blob: 897ae1d25643639eb40e90f5666c8447af4df2c0 [file] [log] [blame]
Antonio de Angelisd3142fd2019-03-28 16:25:14 +00001/*
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
12extern "C" {
13#endif
14
15#include "psa_crypto.h"
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/**
56 * \brief The key slot number to be used by the tests
57 *
58 */
59#define TEST_KEY_SLOT (1)
60
61/**
62 * \brief The maximum allowed key length in bytes used in the
63 * tests
64 */
65#define TEST_MAX_KEY_LENGTH (64)
66
67/**
68 * \brief Tests the key interfaces with different key types
69 *
70 * \param[in] key_type PSA key type
71 * \param[out] ret Test result
72 *
73 */
74void psa_key_interface_test(const psa_key_type_t key_type,
75 struct test_result_t *ret);
76/**
77 * \brief Run block ciphering tests with different algorithms and key types
78 *
79 * \param[in] key_type PSA key type
80 * \param[in] alg PSA algorithm
81 * \param[out] ret Test result
82 *
83 */
84void psa_cipher_test(const psa_key_type_t key_type,
85 const psa_algorithm_t alg,
86 struct test_result_t *ret);
87/**
88 * \brief Tests invalid key type and algorithm combinations for block ciphers
89 *
90 * \param[in] key_type PSA key type
91 * \param[in] alg PSA algorithm
92 * \param[in] key_size Key size
93 * \param[out] ret Test result
94 *
95 */
96void psa_invalid_cipher_test(const psa_key_type_t key_type,
97 const psa_algorithm_t alg,
98 const size_t key_size,
99 struct test_result_t *ret);
100/**
101 * \brief Tests different hashing algorithms
102 *
103 * \param[in] alg PSA algorithm
104 * \param[out] ret Test result
105 *
106 */
107void psa_hash_test(const psa_algorithm_t alg,
108 struct test_result_t *ret);
109/**
110 * \brief Tests different MAC algorithms
111 *
112 * \param[in] alg PSA algorithm
113 * \param[in] use_long_key Flag used to indicate to use the long test key
114 * \param[out] ret Test result
115 *
116 */
117void psa_mac_test(const psa_algorithm_t alg,
118 uint8_t use_long_key,
119 struct test_result_t *ret);
120/**
121 * \brief Run AEAD tests with different algorithms and key types
122 *
123 * \param[in] key_type PSA key type
124 * \param[in] alg PSA algorithm
125 * \param[out] ret Test result
126 *
127 */
128void psa_aead_test(const psa_key_type_t key_type,
129 const psa_algorithm_t alg,
130 struct test_result_t *ret);
131/**
132 * \brief Tests invalid key length
133 *
134 * \param[out] ret Test result
135 *
136 */
137void psa_invalid_key_length_test(struct test_result_t *ret);
138
139/**
140 * \brief Tests the policy key interface
141 *
142 * \param[out] ret Test result
143 *
144 */
145void psa_policy_key_interface_test(struct test_result_t *ret);
146
147/**
148 * \brief Tests invalid policy usage
149 *
150 * \param[out] ret Test result
151 *
152 */
153void psa_policy_invalid_policy_usage_test(struct test_result_t *ret);
154
155#ifdef __cplusplus
156}
157#endif
158
159#endif /* __CRYPTO_TESTS_COMMON__ */