blob: a523120083a3821c4bbd724cbe25ec8adf45db2d [file] [log] [blame]
Gabor Tothc64890c2024-12-03 14:10:32 +01001/*
2 * Copyright (c) 2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "mock_crypto.h"
9
10#include <CppUTestExt/MockSupport.h>
11
12void expect_psa_crypto_init(psa_status_t result)
13{
14 mock().expectOneCall("psa_crypto_init").andReturnValue(result);
15}
16
17psa_status_t psa_crypto_init(void)
18{
19 return mock().actualCall("psa_crypto_init").returnIntValue();
20}
21
22void expect_psa_reset_key_attributes(psa_key_attributes_t *attributes)
23{
24 mock().expectOneCall("psa_reset_key_attributes")
25 .withMemoryBufferParameter("attributes", (const uint8_t *)attributes, sizeof(*attributes));
26}
27
28void psa_reset_key_attributes(psa_key_attributes_t *attributes)
29{
30 mock().actualCall("psa_reset_key_attributes").withOutputParameter("attributes", attributes);
31}
32
33void expect_psa_destroy_key(psa_key_id_t key, psa_status_t result)
34{
35 mock().expectOneCall("psa_destroy_key")
36 .withUnsignedIntParameter("key", key)
37 .andReturnValue(result);
38}
39
40psa_status_t psa_destroy_key(psa_key_id_t key)
41{
42 return mock()
43 .actualCall("psa_destroy_key")
44 .withUnsignedIntParameter("key", key)
45 .returnIntValue();
46}
47
48void expect_psa_import_key(const psa_key_attributes_t *attributes, const uint8_t *data,
49 size_t data_length, psa_key_id_t *key, psa_status_t result)
50{
51 mock().expectOneCall("psa_import_key")
52 .withMemoryBufferParameter("attributes", (const uint8_t *)attributes, sizeof(*attributes))
53 .withMemoryBufferParameter("data", data, sizeof(*data))
54 .withUnsignedIntParameter("data_length", data_length)
55 .withOutputParameterReturning("key", key, sizeof(*key))
56 .andReturnValue(result);
57}
58
59psa_status_t psa_import_key(const psa_key_attributes_t *attributes, const uint8_t *data,
60 size_t data_length, psa_key_id_t *key)
61{
62 return mock()
63 .actualCall("psa_import_key")
64 .withMemoryBufferParameter("attributes", (const uint8_t *)attributes, sizeof(*attributes))
65 .withMemoryBufferParameter("data", data, data_length)
66 .withUnsignedIntParameter("data_length", data_length)
67 .withOutputParameter("key", key)
68 .returnIntValue();
69}
70
71void expect_psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, psa_key_id_t key,
72 psa_algorithm_t alg, psa_status_t result)
73{
74 mock().expectOneCall("psa_cipher_encrypt_setup")
75 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
76 .withUnsignedIntParameter("key", key)
77 .withUnsignedIntParameter("alg", alg)
78 .andReturnValue(result);
79}
80
81psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, psa_key_id_t key,
82 psa_algorithm_t alg)
83{
84 return mock()
85 .actualCall("psa_cipher_encrypt_setup")
86 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
87 .withUnsignedIntParameter("key", key)
88 .withUnsignedIntParameter("alg", alg)
89 .returnIntValue();
90}
91
92void expect_psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, psa_key_id_t key,
93 psa_algorithm_t alg, psa_status_t result)
94{
95 mock().expectOneCall("psa_cipher_decrypt_setup")
96 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
97 .withUnsignedIntParameter("key", key)
98 .withUnsignedIntParameter("alg", alg)
99 .andReturnValue(result);
100}
101
102psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, psa_key_id_t key,
103 psa_algorithm_t alg)
104{
105 return mock()
106 .actualCall("psa_cipher_decrypt_setup")
107 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
108 .withUnsignedIntParameter("key", key)
109 .withUnsignedIntParameter("alg", alg)
110 .returnIntValue();
111}
112
113void expect_psa_cipher_set_iv(psa_cipher_operation_t *operation, const uint8_t *iv,
114 size_t iv_length, psa_status_t result)
115{
116 mock().expectOneCall("psa_cipher_set_iv")
117 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
118 .withMemoryBufferParameter("iv", iv, iv_length)
119 .withUnsignedIntParameter("iv_length", iv_length)
120 .andReturnValue(result);
121}
122
123psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation, const uint8_t *iv,
124 size_t iv_length)
125{
126 return mock()
127 .actualCall("psa_cipher_set_iv")
128 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
129 .withMemoryBufferParameter("iv", iv, iv_length)
130 .withUnsignedIntParameter("iv_length", iv_length)
131 .returnIntValue();
132}
133
134void expect_psa_cipher_update(psa_cipher_operation_t *operation, const uint8_t *input,
135 size_t input_length, uint8_t *output, size_t output_size,
136 size_t *output_length, psa_status_t result)
137{
138 mock().expectOneCall("psa_cipher_update")
139 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
140 .withMemoryBufferParameter("input", input, input_length)
141 .withUnsignedIntParameter("input_length", input_length)
142 .withMemoryBufferParameter("output", output, *output_length)
143 .withUnsignedIntParameter("output_size", output_size)
144 .withOutputParameterReturning("output_length", output_length,
145 sizeof(*output_length))
146 .andReturnValue(result);
147}
148
149psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, const uint8_t *input,
150 size_t input_length, uint8_t *output, size_t output_size,
151 size_t *output_length)
152{
153 return mock()
154 .actualCall("psa_cipher_update")
155 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
156 .withMemoryBufferParameter("input", input, input_length)
157 .withUnsignedIntParameter("input_length", input_length)
158 .withMemoryBufferParameter("output", output, output_size)
159 .withUnsignedIntParameter("output_size", output_size)
160 .withOutputParameter("output_length", output_length)
161 .returnIntValue();
162}
163
164void expect_psa_cipher_finish(psa_cipher_operation_t *operation, uint8_t *output,
165 size_t output_size, size_t *output_length, psa_status_t result)
166{
167 mock().expectOneCall("psa_cipher_finish")
168 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
169 .withOutputParameterReturning("output", output, sizeof(*output))
170 .withUnsignedIntParameter("output_size", output_size)
171 .withOutputParameterReturning("output_length", output_length,
172 sizeof(*output_length))
173 .andReturnValue(result);
174}
175
176psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, uint8_t *output,
177 size_t output_size, size_t *output_length)
178{
179 return mock()
180 .actualCall("psa_cipher_finish")
181 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
182 .withOutputParameter("output", output)
183 .withUnsignedIntParameter("output_size", output_size)
184 .withOutputParameter("output_length", output_length)
185 .returnIntValue();
186}
187
188void expect_psa_cipher_abort(psa_cipher_operation_t *operation, psa_status_t result)
189{
190 mock().expectOneCall("psa_cipher_abort")
191 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
192 .andReturnValue(result);
193}
194
195psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
196{
197 return mock()
198 .actualCall("psa_cipher_abort")
199 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
200 .returnIntValue();
201}
202
203void expect_psa_key_derivation_setup(psa_key_derivation_operation_t *operation, psa_algorithm_t alg,
204 psa_status_t result)
205{
206 mock().expectOneCall("psa_key_derivation_setup")
207 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
208 .withUnsignedIntParameter("alg", alg)
209 .andReturnValue(result);
210}
211
212psa_status_t psa_key_derivation_setup(psa_key_derivation_operation_t *operation,
213 psa_algorithm_t alg)
214{
215 return mock()
216 .actualCall("psa_key_derivation_setup")
217 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
218 .withUnsignedIntParameter("alg", alg)
219 .returnIntValue();
220}
221
222void expect_psa_key_derivation_input_bytes(psa_key_derivation_operation_t *operation,
223 psa_key_derivation_step_t step, const uint8_t *data,
224 size_t data_length, psa_status_t result)
225{
226 mock().expectOneCall("psa_key_derivation_input_bytes")
227 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
228 .withUnsignedIntParameter("step", step)
229 .withMemoryBufferParameter("data", data, data_length)
230 .withUnsignedIntParameter("data_length", data_length)
231 .andReturnValue(result);
232}
233
234psa_status_t psa_key_derivation_input_bytes(psa_key_derivation_operation_t *operation,
235 psa_key_derivation_step_t step, const uint8_t *data,
236 size_t data_length)
237{
238 return mock()
239 .actualCall("psa_key_derivation_input_bytes")
240 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
241 .withUnsignedIntParameter("step", step)
242 .withMemoryBufferParameter("data", data, data_length)
243 .withUnsignedIntParameter("data_length", data_length)
244 .returnIntValue();
245}
246
247void expect_psa_key_derivation_input_key(psa_key_derivation_operation_t *operation,
248 psa_key_derivation_step_t step, psa_key_id_t key,
249 psa_status_t result)
250{
251 mock().expectOneCall("psa_key_derivation_input_key")
252 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
253 .withUnsignedIntParameter("step", step)
254 .withUnsignedIntParameter("key", key)
255 .andReturnValue(result);
256}
257
258psa_status_t psa_key_derivation_input_key(psa_key_derivation_operation_t *operation,
259 psa_key_derivation_step_t step, psa_key_id_t key)
260{
261 return mock()
262 .actualCall("psa_key_derivation_input_key")
263 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
264 .withUnsignedIntParameter("step", step)
265 .withUnsignedIntParameter("key", key)
266 .returnIntValue();
267}
268
269void expect_psa_key_derivation_output_key(const psa_key_attributes_t *attributes,
270 psa_key_derivation_operation_t *operation,
271 psa_key_id_t *key, psa_status_t result)
272{
273 mock().expectOneCall("psa_key_derivation_output_key")
274 .withMemoryBufferParameter("attributes", (const uint8_t *)attributes, sizeof(*attributes))
275 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
276 .withOutputParameterReturning("key", key, sizeof(*key))
277 .andReturnValue(result);
278}
279
280psa_status_t psa_key_derivation_output_key(const psa_key_attributes_t *attributes,
281 psa_key_derivation_operation_t *operation,
282 psa_key_id_t *key)
283{
284 return mock()
285 .actualCall("psa_key_derivation_output_key")
286 .withMemoryBufferParameter("attributes", (const uint8_t *)attributes, sizeof(*attributes))
287 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
288 .withOutputParameter("key", key)
289 .returnIntValue();
290}
291
292void expect_psa_key_derivation_abort(psa_key_derivation_operation_t *operation, psa_status_t result)
293{
294 mock().expectOneCall("psa_key_derivation_abort")
295 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
296 .andReturnValue(result);
297}
298
299psa_status_t psa_key_derivation_abort(psa_key_derivation_operation_t *operation)
300{
301 return mock()
302 .actualCall("psa_key_derivation_abort")
303 .withMemoryBufferParameter("operation", (uint8_t *)operation, sizeof(*operation))
304 .returnIntValue();
305}