Skip to content

Commit

Permalink
Merge pull request #156 from jaypit02/master
Browse files Browse the repository at this point in the history
Crypto: Test fixes and documentation update
  • Loading branch information
gowthamsiddarthd authored Mar 3, 2020
2 parents e44cceb + 0a4740b commit 10a1a65
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 46 deletions.
4 changes: 2 additions & 2 deletions api-tests/dev_apis/crypto/test_c016/test_c016.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -98,7 +98,7 @@ int32_t psa_generate_key_test(caller_security_t caller)
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));

/* Check the attributes of the exported key */
TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(10));
TEST_ASSERT_RANGE(length, check1[i].expected_range[0], check1[i].expected_range[1], TEST_CHECKPOINT_NUM(10));

/* Reset the attributes */
val->crypto_function(VAL_CRYPTO_RESET_KEY_ATTRIBUTES, &attributes);
Expand Down
26 changes: 13 additions & 13 deletions api-tests/dev_apis/crypto/test_c016/test_data.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,7 +25,7 @@ typedef struct {
psa_algorithm_t key_alg;
size_t attr_bits;
uint32_t expected_bit_length;
uint32_t expected_key_length;
uint32_t expected_range[2];
psa_status_t expected_status;
} test_data;

Expand All @@ -34,58 +34,58 @@ static test_data check1[] = {
#ifdef ARCH_TEST_AES_128
{"Test psa_generate_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
BYTES_TO_BITS(AES_16B_KEY_SIZE), {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE}, PSA_SUCCESS
},
#endif

#ifdef ARCH_TEST_AES_192
{"Test psa_generate_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_24B_KEY_SIZE),
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
BYTES_TO_BITS(AES_24B_KEY_SIZE), {AES_24B_KEY_SIZE, AES_24B_KEY_SIZE}, PSA_SUCCESS
},
#endif

#ifdef ARCH_TEST_AES_256
{"Test psa_generate_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_32B_KEY_SIZE),
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
BYTES_TO_BITS(AES_32B_KEY_SIZE), {AES_32B_KEY_SIZE, AES_32B_KEY_SIZE}, PSA_SUCCESS
},
#endif

#ifdef ARCH_TEST_DES_1KEY
{"Test psa_generate_key with DES 64 bit key\n", 4, PSA_KEY_TYPE_DES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(DES_8B_KEY_SIZE),
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
BYTES_TO_BITS(DES_8B_KEY_SIZE), {DES_8B_KEY_SIZE, DES_8B_KEY_SIZE}, PSA_SUCCESS
},
#endif

#ifdef ARCH_TEST_DES_2KEY
{"Test psa_generate_key with Triple DES 2-Key\n", 5, PSA_KEY_TYPE_DES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(DES3_2KEY_SIZE),
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
BYTES_TO_BITS(DES3_2KEY_SIZE), {DES3_2KEY_SIZE, DES3_2KEY_SIZE}, PSA_SUCCESS
},
#endif

#ifdef ARCH_TEST_DES_3KEY
{"Test psa_generate_key with Triple DES 3-Key\n", 6, PSA_KEY_TYPE_DES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(DES3_3KEY_SIZE),
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
BYTES_TO_BITS(DES3_3KEY_SIZE), {DES3_3KEY_SIZE, DES3_3KEY_SIZE}, PSA_SUCCESS
},
#endif

#endif

{"Test psa_generate_key with RSA 2048 Keypair\n", 7, PSA_KEY_TYPE_RSA_KEY_PAIR,
PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 2048, 1192, PSA_SUCCESS
2048, 2048, {1190, 1194}, PSA_SUCCESS
},

#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
{"Test psa_generate_key with ECC KeyPair\n", 8,
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP224R1),
PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, 224,
224, 28, PSA_SUCCESS
224, {28, 28}, PSA_SUCCESS
},
#endif
#endif
Expand All @@ -94,18 +94,18 @@ static test_data check1[] = {
#ifdef ARCH_TEST_RSA_2048
{"Test psa_generate_key with RSA 2048 Public key\n", 9, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 2048, 1192, PSA_ERROR_NOT_SUPPORTED
2048, 2048, {1190, 1194}, PSA_ERROR_NOT_SUPPORTED
},
#endif
#endif

{"Test psa_generate_key with invalid key type\n", 10, 0,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_NOT_SUPPORTED
BYTES_TO_BITS(AES_16B_KEY_SIZE), {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE}, PSA_ERROR_NOT_SUPPORTED
},

{"Test psa_generate_key with invalid usage flags\n", 11, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_INVALID, PSA_ALG_CTR, BYTES_TO_BITS(AES_16B_KEY_SIZE),
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
BYTES_TO_BITS(AES_16B_KEY_SIZE), {AES_16B_KEY_SIZE, AES_16B_KEY_SIZE}, PSA_ERROR_INVALID_ARGUMENT
},
};
2 changes: 2 additions & 0 deletions api-tests/dev_apis/crypto/test_c039/test_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static test_data check1[] = {

#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
#ifdef ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
{"Test psa_asymmetric_encrypt - ECC public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0}, 65, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
Expand All @@ -237,6 +238,7 @@ static test_data check1[] = {
}
#endif
#endif
#endif
};

static test_data check2[] = {
Expand Down
6 changes: 3 additions & 3 deletions api-tests/dev_apis/crypto/test_c043/test_data.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -167,7 +167,7 @@ static test_data check1[] = {
0x3c, 0x6e, 0x70, 0xc4, 0x16, 0xdd, 0x5f, 0x0c, 0x68, 0x75, 0x9d, 0xd1, 0xff,
0xf8, 0x3f, 0xa4, 0x01, 0x42, 0x20, 0x9d, 0xff, 0x5e, 0xaa, 0xd9, 0x6d, 0xb9,
0xe6, 0x38, 0x6c}, 97,
{0}, 0, 0, PSA_ERROR_INVALID_ARGUMENT
{0}, 0, SIZE_50B, PSA_ERROR_INVALID_ARGUMENT
},

{"Test psa_raw_key_agreement - Public key instead of private key\n", 7,
Expand All @@ -183,7 +183,7 @@ static test_data check1[] = {
0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3, 0xca, 0x36, 0x6c,
0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d, 0x6a, 0xac, 0x23, 0xf0,
0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f, 0x33, 0x03, 0x98, 0x72, 0xab},
65, {0}, 0, 0, PSA_ERROR_INVALID_ARGUMENT
65, {0}, 0, SIZE_50B, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
Expand Down
50 changes: 24 additions & 26 deletions api-tests/docs/test_failure_analysis.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@

# Test failure analysis document

This file contains list of failures identified when running the PSA API tests
This file contains list of failures identified when testing the release
on tgt_dev_apis_tfm_an521, tgt_dev_apis_tfm_musca_a and tgt_dev_apis_tfm_musca_b1
targets with TFM commit Hash - 6e7be077eabef00b4825e245604148d82b11f832.
The reason for each failing test is listed here in this file.

## Known Failures

| Test | Fail description |
|------|---------------------------------------------------------------------------------|
|test_c006 | psa_hash_compute is unimplemented in TFM |
|test_c007 | psa_hash_compare is unimplemented in TFM |
|test_c009 | psa_key_derivation_input_bytes returns incorrect error code |
|test_c016 | psa_generate_key generates incorrect key length for RSA |
|test_c020 | psa_key_derivation_output_bytes returns incorrect error code |
|test_c021 | psa_key_derivation_output_key returns incorrect error code |
|test_c039 | psa_asymmetric_encrypt does not have support for ECC keys |
|test_c046 | psa_mac_compute is unimplemented in TFM |
|test_c047 | psa_mac_verify is unimplemented in TFM |
|test_c048 | psa_cipher_encrypt is unimplemented in TFM |
|test_c049 | psa_cipher_decrypt is unimplemented in TFM |
|test_c050 | psa_open_key API not enabled in TFM |
|test_c051 | psa_close_key API not enabled in TFM |
|test_c052 | psa_aead_encrypt_setup is unimplemented in TFM |
|test_c053 | psa_aead_decrypt_setup is unimplemented in TFM |
|test_c054 | psa_aead_generate_nonce is unimplemented in TFM |
|test_c055 | psa_aead_set_nonce is unimplemented in TFM |
|test_c056 | psa_aead_set_lengths is unimplemented in TFM |
|test_c057 | psa_aead_update_ad is unimplemented in TFM |
|test_c058 | psa_aead_update is unimplemented in TFM |
|test_c059 | psa_aead_finish is unimplemented in TFM |
|test_c060 | psa_aead_abort is unimplemented in TFM |
|test_c061 | psa_aead_verify is unimplemented in TFM |
| Test | Fail description | Github issue |
|------|---------------------------------------------------------------------------------| ------------ |
|test_c006 | psa_hash_compute is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c007 | psa_hash_compare is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c009 | psa_key_derivation_input_bytes returns incorrect error code | https://github.com/ARMmbed/mbed-crypto/issues/175 |
|test_c020 | psa_key_derivation_output_bytes returns incorrect error code | https://github.com/ARMmbed/mbed-crypto/issues/175 |
|test_c021 | psa_key_derivation_output_key returns incorrect error code | https://github.com/ARMmbed/mbed-crypto/issues/175 |
|test_c046 | psa_mac_compute is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c047 | psa_mac_verify is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c048 | psa_cipher_encrypt is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c049 | psa_cipher_decrypt is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c050 | Persistent key storage is unavailable in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/382 |
|test_c051 | Persistent key storage is unavailable in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/382 |
|test_c052 | psa_aead_encrypt_setup is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c053 | psa_aead_decrypt_setup is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c054 | psa_aead_generate_nonce is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c055 | psa_aead_set_nonce is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c056 | psa_aead_set_lengths is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c057 | psa_aead_update_ad is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c058 | psa_aead_update is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c059 | psa_aead_finish is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c060 | psa_aead_abort is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |
|test_c061 | psa_aead_verify is unimplemented in TFM/mbed-crypto. So the test has not been verified. | https://github.com/ARMmbed/mbed-crypto/issues/381 |

## License

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -317,6 +317,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
*/
#define ARCH_TEST_DETERMINISTIC_ECDSA

/**
* \def ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
*
* Enable ECC support for asymmetric API.
*/
//#define ARCH_TEST_ECC_ASYMMETRIC_API_SUPPORT
#include "pal_crypto_config_check.h"

#endif /* _PAL_CRYPTO_CONFIG_H_ */
14 changes: 13 additions & 1 deletion api-tests/val/common/val.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2018-2020, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -165,6 +165,18 @@
} \
} while (0)

#define TEST_ASSERT_RANGE(arg1, range1, range2, checkpoint) \
do { \
if ((arg1) < range1 || (arg1) > range2) \
{ \
val->print(PRINT_ERROR, "\tFailed at Checkpoint: %d\n", checkpoint); \
val->print(PRINT_ERROR, "\tActual: %d\n", arg1); \
val->print(PRINT_ERROR, "\tExpected range: %d to ", range1); \
val->print(PRINT_ERROR, "%d", range2); \
return 1; \
} \
} while (0)

/* enums */
typedef enum {
CALLER_NONSECURE = 0x0,
Expand Down

0 comments on commit 10a1a65

Please sign in to comment.