Merge pull request #7412 from silabs-Kusumit/PBKDF2_implementation
PBKDF2: Implement input_integer
This commit is contained in:
commit
c70d9eab8a
3 changed files with 88 additions and 8 deletions
|
@ -6481,6 +6481,27 @@ exit:
|
|||
return status;
|
||||
}
|
||||
|
||||
static psa_status_t psa_key_derivation_input_integer_internal(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
psa_key_derivation_step_t step,
|
||||
uint64_t value)
|
||||
{
|
||||
psa_status_t status;
|
||||
psa_algorithm_t kdf_alg = psa_key_derivation_get_kdf_alg(operation);
|
||||
|
||||
{
|
||||
(void) step;
|
||||
(void) value;
|
||||
(void) kdf_alg;
|
||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (status != PSA_SUCCESS) {
|
||||
psa_key_derivation_abort(operation);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
psa_status_t psa_key_derivation_input_bytes(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
psa_key_derivation_step_t step,
|
||||
|
@ -6492,6 +6513,14 @@ psa_status_t psa_key_derivation_input_bytes(
|
|||
data, data_length);
|
||||
}
|
||||
|
||||
psa_status_t psa_key_derivation_input_integer(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
psa_key_derivation_step_t step,
|
||||
uint64_t value)
|
||||
{
|
||||
return psa_key_derivation_input_integer_internal(operation, step, value);
|
||||
}
|
||||
|
||||
psa_status_t psa_key_derivation_input_key(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
psa_key_derivation_step_t step,
|
||||
|
|
|
@ -5031,6 +5031,9 @@ PSA key derivation setup: bad algorithm
|
|||
depends_on:PSA_WANT_ALG_SHA_256
|
||||
derive_setup:PSA_ALG_CATEGORY_KEY_DERIVATION:PSA_ERROR_NOT_SUPPORTED
|
||||
|
||||
Parse binary string
|
||||
parse_binary_string_test:"123456":0x123456
|
||||
|
||||
PSA key derivation: HKDF-SHA-256, good case, direct output
|
||||
depends_on:PSA_WANT_ALG_HKDF:PSA_WANT_ALG_SHA_256
|
||||
derive_input:PSA_ALG_HKDF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_SALT:PSA_KEY_TYPE_NONE:"":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_SECRET:PSA_KEY_TYPE_DERIVE:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_INFO:PSA_KEY_TYPE_NONE:"":PSA_SUCCESS:PSA_KEY_TYPE_NONE:PSA_SUCCESS
|
||||
|
@ -5159,6 +5162,23 @@ PSA key derivation: HKDF-SHA-256, reject seed step
|
|||
depends_on:PSA_WANT_ALG_HKDF:PSA_WANT_ALG_SHA_256
|
||||
derive_input:PSA_ALG_HKDF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_SEED:PSA_KEY_TYPE_NONE:"":PSA_ERROR_INVALID_ARGUMENT:PSA_KEY_DERIVATION_INPUT_SECRET:PSA_KEY_TYPE_DERIVE:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ERROR_BAD_STATE:PSA_KEY_DERIVATION_INPUT_INFO:PSA_KEY_TYPE_NONE:"":PSA_ERROR_BAD_STATE:PSA_KEY_TYPE_NONE:PSA_ERROR_BAD_STATE
|
||||
|
||||
PSA key derivation: HKDF-SHA-256, reject using input integer with direct secret
|
||||
depends_on:PSA_WANT_ALG_HKDF:PSA_WANT_ALG_SHA_256
|
||||
derive_input:PSA_ALG_HKDF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_SALT:PSA_KEY_TYPE_NONE:"":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_SECRET:INPUT_INTEGER:"0b0b0b0b0b0b0b0b":PSA_ERROR_INVALID_ARGUMENT:PSA_KEY_DERIVATION_INPUT_INFO:PSA_KEY_TYPE_NONE:"":PSA_ERROR_BAD_STATE:PSA_KEY_TYPE_NONE:PSA_ERROR_BAD_STATE
|
||||
|
||||
PSA key derivation: HKDF-SHA-256, reject input cost step using input_bytes
|
||||
depends_on:PSA_WANT_ALG_HKDF:PSA_WANT_ALG_SHA_256
|
||||
derive_input:PSA_ALG_HKDF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_COST:PSA_KEY_TYPE_NONE:"100000":PSA_ERROR_INVALID_ARGUMENT:PSA_KEY_DERIVATION_INPUT_SECRET:PSA_KEY_TYPE_NONE:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ERROR_BAD_STATE:PSA_KEY_DERIVATION_INPUT_INFO:PSA_KEY_TYPE_NONE:"":PSA_ERROR_BAD_STATE:PSA_KEY_TYPE_NONE:PSA_ERROR_BAD_STATE
|
||||
|
||||
PSA key derivation: HKDF-SHA-256, input cost using input_integer after secret
|
||||
depends_on:PSA_WANT_ALG_HKDF:PSA_WANT_ALG_SHA_256
|
||||
derive_input:PSA_ALG_HKDF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_SECRET:PSA_KEY_TYPE_NONE:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_COST:INPUT_INTEGER:"100000":PSA_ERROR_INVALID_ARGUMENT:PSA_KEY_DERIVATION_INPUT_INFO:PSA_KEY_TYPE_NONE:"":PSA_ERROR_BAD_STATE:PSA_KEY_TYPE_NONE:PSA_ERROR_BAD_STATE
|
||||
|
||||
PSA key derivation: HKDF-SHA-256, reject input cost using input_integer after secret and info
|
||||
depends_on:PSA_WANT_ALG_HKDF:PSA_WANT_ALG_SHA_256
|
||||
derive_input:PSA_ALG_HKDF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_SECRET:PSA_KEY_TYPE_NONE:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_INFO:PSA_KEY_TYPE_NONE:"":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_COST:INPUT_INTEGER:"100000":PSA_ERROR_INVALID_ARGUMENT:PSA_KEY_TYPE_NONE:PSA_ERROR_BAD_STATE
|
||||
|
||||
|
||||
PSA key derivation: TLS 1.2 PRF SHA-256, good case
|
||||
depends_on:PSA_WANT_ALG_SHA_256:PSA_WANT_ALG_TLS12_PRF
|
||||
derive_input:PSA_ALG_TLS12_PRF(PSA_ALG_SHA_256):PSA_KEY_DERIVATION_INPUT_SEED:PSA_KEY_TYPE_NONE:"":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_SECRET:PSA_KEY_TYPE_DERIVE:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_SUCCESS:PSA_KEY_DERIVATION_INPUT_LABEL:PSA_KEY_TYPE_NONE:"":PSA_SUCCESS:PSA_KEY_TYPE_DERIVE:PSA_SUCCESS
|
||||
|
|
|
@ -294,6 +294,19 @@ exit:
|
|||
((void) 0)
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
|
||||
#define INPUT_INTEGER 0x10000 /* Out of range of psa_key_type_t */
|
||||
|
||||
uint64_t parse_binary_string(data_t *bin_string)
|
||||
{
|
||||
uint64_t result = 0;
|
||||
TEST_LE_U(bin_string->len, 8);
|
||||
for (size_t i = 0; i < bin_string->len; i++) {
|
||||
result = result << 8 | bin_string->x[i];
|
||||
}
|
||||
exit:
|
||||
return result; /* returns 0 if len > 8 */
|
||||
}
|
||||
|
||||
/* An overapproximation of the amount of storage needed for a key of the
|
||||
* given type and with the given content. The API doesn't make it easy
|
||||
* to find a good value for the size. The current implementation doesn't
|
||||
|
@ -318,6 +331,7 @@ typedef enum {
|
|||
USE_GIVEN_TAG = 1,
|
||||
} tag_usage_method_t;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Internal Function for AEAD multipart tests.
|
||||
* \param key_type_arg Type of key passed in
|
||||
|
@ -8445,6 +8459,15 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void parse_binary_string_test(data_t *input, int output)
|
||||
{
|
||||
uint64_t value;
|
||||
value = parse_binary_string(input);
|
||||
TEST_EQUAL(value, output);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void derive_input(int alg_arg,
|
||||
int step_arg1, int key_type_arg1, data_t *input1,
|
||||
|
@ -8457,7 +8480,7 @@ void derive_input(int alg_arg,
|
|||
{
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
psa_key_derivation_step_t steps[] = { step_arg1, step_arg2, step_arg3 };
|
||||
psa_key_type_t key_types[] = { key_type_arg1, key_type_arg2, key_type_arg3 };
|
||||
uint32_t key_types[] = { key_type_arg1, key_type_arg2, key_type_arg3 };
|
||||
psa_status_t expected_statuses[] = { expected_status_arg1,
|
||||
expected_status_arg2,
|
||||
expected_status_arg3 };
|
||||
|
@ -8484,12 +8507,13 @@ void derive_input(int alg_arg,
|
|||
mbedtls_test_set_step(i);
|
||||
if (steps[i] == 0) {
|
||||
/* Skip this step */
|
||||
} else if (key_types[i] != PSA_KEY_TYPE_NONE) {
|
||||
psa_set_key_type(&attributes, key_types[i]);
|
||||
} else if (((psa_key_type_t) key_types[i]) != PSA_KEY_TYPE_NONE &&
|
||||
key_types[i] != INPUT_INTEGER) {
|
||||
psa_set_key_type(&attributes, ((psa_key_type_t) key_types[i]));
|
||||
PSA_ASSERT(psa_import_key(&attributes,
|
||||
inputs[i]->x, inputs[i]->len,
|
||||
&keys[i]));
|
||||
if (PSA_KEY_TYPE_IS_KEY_PAIR(key_types[i]) &&
|
||||
if (PSA_KEY_TYPE_IS_KEY_PAIR((psa_key_type_t) key_types[i]) &&
|
||||
steps[i] == PSA_KEY_DERIVATION_INPUT_SECRET) {
|
||||
// When taking a private key as secret input, use key agreement
|
||||
// to add the shared secret to the derivation
|
||||
|
@ -8502,10 +8526,17 @@ void derive_input(int alg_arg,
|
|||
expected_statuses[i]);
|
||||
}
|
||||
} else {
|
||||
TEST_EQUAL(psa_key_derivation_input_bytes(
|
||||
&operation, steps[i],
|
||||
inputs[i]->x, inputs[i]->len),
|
||||
expected_statuses[i]);
|
||||
if (key_types[i] == INPUT_INTEGER) {
|
||||
TEST_EQUAL(psa_key_derivation_input_integer(
|
||||
&operation, steps[i],
|
||||
parse_binary_string(inputs[i])),
|
||||
expected_statuses[i]);
|
||||
} else {
|
||||
TEST_EQUAL(psa_key_derivation_input_bytes(
|
||||
&operation, steps[i],
|
||||
inputs[i]->x, inputs[i]->len),
|
||||
expected_statuses[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue