Skip to content

Commit

Permalink
regression_4000: check if the generated DH private key is a CAAM blac…
Browse files Browse the repository at this point in the history
…k key

Check if the generated private DH key is a CAAM black key. If it is the
case, skip the buffer size check as the key size and CAAM black key
buffer size do not match.

Signed-off-by: Clement Faure <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
  • Loading branch information
clementfaure committed Feb 21, 2024
1 parent 4b4caf7 commit e2cb53c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion host/xtest/regression_4000.c
Original file line number Diff line number Diff line change
Expand Up @@ -4368,6 +4368,21 @@ struct key_attrs {
uint32_t keysize_check;
};

static bool is_caam_black_key(uint8_t *buf, size_t size)
{
/*
* This value is a magic number for the a CAAM Black key. This value
* must match the value defined in optee-os
* core/drivers/crypto/caam/caam_key.c
*/
const uint8_t magic_number[4] = {0xFB, 0xBF, 0xAF, 0xCA};

if (size < sizeof(magic_number))
return false;

return !memcmp(buf, magic_number, sizeof(magic_number));
}

static bool test_keygen_attributes(ADBG_Case_t *c, TEEC_Session *s,
TEE_ObjectHandle key, uint32_t key_size,
struct key_attrs *attrs, size_t num_attrs)
Expand All @@ -4386,7 +4401,13 @@ static bool test_keygen_attributes(ADBG_Case_t *c, TEEC_Session *s,
key, attrs[m].attr, out, &out_size)))
return false;

if (attrs[m].keysize_check)
/*
* Check for CAAM black key header. If the buffer holds
* a CAAM black key, do not check the key size as the
* buffer size and the key size do not match.
*/
if (attrs[m].keysize_check &&
!is_caam_black_key(out, out_size))
ADBG_EXPECT_COMPARE_UNSIGNED(c, out_size, <=,
key_size / 8);

Expand Down

0 comments on commit e2cb53c

Please sign in to comment.