Rework pake input getters tests

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2023-02-27 07:53:14 +01:00
parent 6f2d1f419a
commit f5dcb8886a
2 changed files with 54 additions and 67 deletions

View file

@ -194,29 +194,11 @@ PSA PAKE: ecjpake size macros
depends_on:PSA_WANT_KEY_TYPE_ECC_KEY_PAIR:PSA_WANT_ECC_SECP_R1_256
ecjpake_size_macros:
PSA PAKE: input getters password: ok #1
pake_input_getters_password:"aabbccddee":5:PSA_SUCCESS:PSA_SUCCESS
PSA PAKE: input getters: password
pake_input_getters_password
PSA PAKE: input getters password: ok #2
pake_input_getters_password:"11223344556677889900":10:PSA_SUCCESS:PSA_SUCCESS
PSA PAKE: input getters: cipher suite
pake_input_getters_cipher_suite
PSA PAKE: input getters password: buffer to small
pake_input_getters_password:"aabbccddee":4:PSA_ERROR_BUFFER_TOO_SMALL:PSA_SUCCESS
PSA PAKE: input getters password: not set
pake_input_getters_password:"":0:PSA_ERROR_BAD_STATE:PSA_ERROR_BAD_STATE
PSA PAKE: input getters cipher suite: ok
pake_input_getters_cipher_suite:PSA_SUCCESS:1
PSA PAKE: input getters cipher suite: not set
pake_input_getters_cipher_suite:PSA_ERROR_BAD_STATE:0
PSA PAKE: input getters role client: ok
pake_input_getters_role:PSA_PAKE_ROLE_CLIENT:PSA_SUCCESS
PSA PAKE: input getters role server: ok
pake_input_getters_role:PSA_PAKE_ROLE_SERVER:PSA_SUCCESS
PSA PAKE: input getters role: not set
pake_input_getters_role:PSA_PAKE_ROLE_NONE:PSA_ERROR_BAD_STATE
PSA PAKE: input getters: role
pake_input_getters_role

View file

@ -909,14 +909,14 @@ void ecjpake_size_macros()
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
void pake_input_getters_password(data_t *password, int password_buffer_size,
int expected_status_pass, int expected_status_pass_len)
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE:PSA_ALG_SHA_256 */
void pake_input_getters_password()
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t operation = psa_pake_operation_init();
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const char *password = "password";
uint8_t password_ret[20] = { 0 }; // max key length is 20 bytes
size_t password_len_ret = 0;
size_t buffer_len_ret = 0;
@ -937,28 +937,37 @@ void pake_input_getters_password(data_t *password, int password_buffer_size,
PSA_ASSERT(psa_pake_setup(&operation, &cipher_suite));
if (password_buffer_size > 0) {
PSA_ASSERT(psa_import_key(&attributes, password->x, password->len, &key));
PSA_ASSERT(psa_pake_set_password_key(&operation, key));
}
TEST_EQUAL(psa_crypto_driver_pake_get_password_len(&operation.data.inputs, &password_len_ret),
expected_status_pass_len);
if (expected_status_pass_len == PSA_SUCCESS) {
TEST_EQUAL(password_len_ret, password->len);
PSA_ASSERT(psa_import_key(&attributes, (uint8_t *) password, strlen(password), &key));
TEST_EQUAL(psa_crypto_driver_pake_get_password(&operation.data.inputs,
(uint8_t *) &password_ret,
password_buffer_size, &buffer_len_ret),
expected_status_pass);
10, &buffer_len_ret),
PSA_ERROR_BAD_STATE);
if (expected_status_pass == PSA_SUCCESS) {
TEST_EQUAL(buffer_len_ret, password->len);
PSA_ASSERT(memcmp(password_ret, password->x, buffer_len_ret));
}
}
TEST_EQUAL(psa_crypto_driver_pake_get_password_len(&operation.data.inputs, &password_len_ret),
PSA_ERROR_BAD_STATE);
PSA_ASSERT(psa_pake_set_password_key(&operation, key));
TEST_EQUAL(psa_crypto_driver_pake_get_password_len(&operation.data.inputs, &password_len_ret),
PSA_SUCCESS);
TEST_EQUAL(password_len_ret, strlen(password));
TEST_EQUAL(psa_crypto_driver_pake_get_password(&operation.data.inputs,
(uint8_t *) &password_ret,
password_len_ret - 1,
&buffer_len_ret),
PSA_ERROR_BUFFER_TOO_SMALL);
TEST_EQUAL(psa_crypto_driver_pake_get_password(&operation.data.inputs,
(uint8_t *) &password_ret,
password_len_ret,
&buffer_len_ret),
PSA_SUCCESS);
TEST_EQUAL(buffer_len_ret, strlen(password));
PSA_ASSERT(memcmp(password_ret, password, buffer_len_ret));
exit:
PSA_ASSERT(psa_destroy_key(key));
PSA_ASSERT(psa_pake_abort(&operation));
@ -966,8 +975,8 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
void pake_input_getters_cipher_suite(int expected_status, int setup_done)
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE:PSA_ALG_SHA_256 */
void pake_input_getters_cipher_suite()
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t operation = psa_pake_operation_init();
@ -979,20 +988,19 @@ void pake_input_getters_cipher_suite(int expected_status, int setup_done)
PSA_INIT();
if (setup_done == 1) {
psa_pake_cs_set_algorithm(&cipher_suite, PSA_ALG_JPAKE);
psa_pake_cs_set_primitive(&cipher_suite, primitive);
psa_pake_cs_set_hash(&cipher_suite, PSA_ALG_SHA_256);
TEST_EQUAL(psa_crypto_driver_pake_get_cipher_suite(&operation.data.inputs, &cipher_suite_ret),
PSA_ERROR_BAD_STATE);
PSA_ASSERT(psa_pake_setup(&operation, &cipher_suite));
}
TEST_EQUAL(psa_crypto_driver_pake_get_cipher_suite(&operation.data.inputs, &cipher_suite_ret),
expected_status);
PSA_SUCCESS);
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(memcmp(&cipher_suite_ret, &cipher_suite, sizeof(cipher_suite)));
}
exit:
PSA_ASSERT(psa_pake_abort(&operation));
@ -1000,13 +1008,12 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE */
void pake_input_getters_role(int role_arg, int expected_status)
/* BEGIN_CASE depends_on:PSA_WANT_ALG_JPAKE:PSA_ALG_SHA_256 */
void pake_input_getters_role()
{
psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init();
psa_pake_operation_t operation = psa_pake_operation_init();
psa_pake_role_t role_ret = PSA_PAKE_ROLE_NONE;
psa_pake_role_t role = role_arg;
psa_pake_primitive_t primitive = PSA_PAKE_PRIMITIVE(
PSA_PAKE_PRIMITIVE_TYPE_ECC,
@ -1020,17 +1027,15 @@ void pake_input_getters_role(int role_arg, int expected_status)
PSA_ASSERT(psa_pake_setup(&operation, &cipher_suite));
if (role != PSA_PAKE_ROLE_NONE) {
PSA_ASSERT(psa_pake_set_role(&operation, role));
}
TEST_EQUAL(psa_crypto_driver_pake_get_role(&operation.data.inputs, &role_ret),
PSA_ERROR_BAD_STATE);
PSA_ASSERT(psa_pake_set_role(&operation, PSA_PAKE_ROLE_SERVER));
TEST_EQUAL(psa_crypto_driver_pake_get_role(&operation.data.inputs, &role_ret),
expected_status);
if (expected_status == PSA_SUCCESS) {
TEST_EQUAL(role_ret, role);
}
PSA_SUCCESS);
TEST_EQUAL(role_ret, PSA_PAKE_ROLE_SERVER);
exit:
PSA_ASSERT(psa_pake_abort(&operation));
PSA_DONE();