Antonio de Angelis | d3142fd | 2019-03-28 16:25:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __CRYPTO_TESTS_COMMON_H__ |
| 9 | #define __CRYPTO_TESTS_COMMON_H__ |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame^] | 15 | #include "psa/crypto.h" |
Antonio de Angelis | d3142fd | 2019-03-28 16:25:14 +0000 | [diff] [blame] | 16 | #include "test/framework/test_framework_helpers.h" |
| 17 | |
| 18 | /** |
| 19 | * \brief Size of the key to use in tests in bits |
| 20 | * |
| 21 | */ |
| 22 | #define BIT_SIZE_TEST_KEY (128) |
| 23 | |
| 24 | /** |
| 25 | * \brief Size of the long key to use in tests in bits |
| 26 | * |
| 27 | */ |
| 28 | #define BIT_SIZE_TEST_LONG_KEY (256) |
| 29 | |
| 30 | /** |
| 31 | * \brief Macro to extract the size of the key in bytes |
| 32 | * |
| 33 | */ |
| 34 | #define BYTE_SIZE_TEST_KEY (BIT_SIZE_TEST_KEY/8) |
| 35 | |
| 36 | /** |
| 37 | * \brief Size in bytes of a chunk of data to process |
| 38 | * |
| 39 | */ |
| 40 | #define BYTE_SIZE_CHUNK (16) |
| 41 | |
| 42 | /** |
| 43 | * \brief Size in bytes of the encryption/decryption buffers |
| 44 | * |
| 45 | */ |
| 46 | #define ENC_DEC_BUFFER_SIZE (32) |
| 47 | |
| 48 | /** |
| 49 | * \brief Size in bytes of the associated data to authenticate |
| 50 | * in AEAD tests |
| 51 | * |
| 52 | */ |
| 53 | #define ASSOCIATED_DATA_SIZE (24) |
| 54 | |
| 55 | /** |
Antonio de Angelis | d3142fd | 2019-03-28 16:25:14 +0000 | [diff] [blame] | 56 | * \brief The maximum allowed key length in bytes used in the |
| 57 | * tests |
| 58 | */ |
| 59 | #define TEST_MAX_KEY_LENGTH (64) |
| 60 | |
| 61 | /** |
| 62 | * \brief Tests the key interfaces with different key types |
| 63 | * |
| 64 | * \param[in] key_type PSA key type |
| 65 | * \param[out] ret Test result |
| 66 | * |
| 67 | */ |
| 68 | void psa_key_interface_test(const psa_key_type_t key_type, |
| 69 | struct test_result_t *ret); |
| 70 | /** |
| 71 | * \brief Run block ciphering tests with different algorithms and key types |
| 72 | * |
| 73 | * \param[in] key_type PSA key type |
| 74 | * \param[in] alg PSA algorithm |
| 75 | * \param[out] ret Test result |
| 76 | * |
| 77 | */ |
| 78 | void psa_cipher_test(const psa_key_type_t key_type, |
| 79 | const psa_algorithm_t alg, |
| 80 | struct test_result_t *ret); |
| 81 | /** |
| 82 | * \brief Tests invalid key type and algorithm combinations for block ciphers |
| 83 | * |
| 84 | * \param[in] key_type PSA key type |
| 85 | * \param[in] alg PSA algorithm |
| 86 | * \param[in] key_size Key size |
| 87 | * \param[out] ret Test result |
| 88 | * |
| 89 | */ |
| 90 | void psa_invalid_cipher_test(const psa_key_type_t key_type, |
| 91 | const psa_algorithm_t alg, |
| 92 | const size_t key_size, |
| 93 | struct test_result_t *ret); |
| 94 | /** |
| 95 | * \brief Tests different hashing algorithms |
| 96 | * |
| 97 | * \param[in] alg PSA algorithm |
| 98 | * \param[out] ret Test result |
| 99 | * |
| 100 | */ |
| 101 | void psa_hash_test(const psa_algorithm_t alg, |
| 102 | struct test_result_t *ret); |
| 103 | /** |
| 104 | * \brief Tests different MAC algorithms |
| 105 | * |
| 106 | * \param[in] alg PSA algorithm |
| 107 | * \param[in] use_long_key Flag used to indicate to use the long test key |
| 108 | * \param[out] ret Test result |
| 109 | * |
| 110 | */ |
| 111 | void psa_mac_test(const psa_algorithm_t alg, |
| 112 | uint8_t use_long_key, |
| 113 | struct test_result_t *ret); |
| 114 | /** |
| 115 | * \brief Run AEAD tests with different algorithms and key types |
| 116 | * |
| 117 | * \param[in] key_type PSA key type |
| 118 | * \param[in] alg PSA algorithm |
| 119 | * \param[out] ret Test result |
| 120 | * |
| 121 | */ |
| 122 | void psa_aead_test(const psa_key_type_t key_type, |
| 123 | const psa_algorithm_t alg, |
| 124 | struct test_result_t *ret); |
| 125 | /** |
| 126 | * \brief Tests invalid key length |
| 127 | * |
| 128 | * \param[out] ret Test result |
| 129 | * |
| 130 | */ |
| 131 | void psa_invalid_key_length_test(struct test_result_t *ret); |
| 132 | |
| 133 | /** |
| 134 | * \brief Tests the policy key interface |
| 135 | * |
| 136 | * \param[out] ret Test result |
| 137 | * |
| 138 | */ |
| 139 | void psa_policy_key_interface_test(struct test_result_t *ret); |
| 140 | |
| 141 | /** |
| 142 | * \brief Tests invalid policy usage |
| 143 | * |
| 144 | * \param[out] ret Test result |
| 145 | * |
| 146 | */ |
| 147 | void psa_policy_invalid_policy_usage_test(struct test_result_t *ret); |
| 148 | |
| 149 | #ifdef __cplusplus |
| 150 | } |
| 151 | #endif |
| 152 | |
| 153 | #endif /* __CRYPTO_TESTS_COMMON__ */ |