blob: 8fe426bb8f2d32f52dcd39ea0833d472ad43ce51 [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001/*
Jimmy Brisson640d9912024-04-10 10:20:13 -05002 * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
Juan Castilloa57a4d52015-04-02 15:44:20 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castilloa57a4d52015-04-02 15:44:20 +01005 */
6
Sumit Garg392e4df2019-11-15 10:43:00 +05307#include <assert.h>
Juan Castilloa57a4d52015-04-02 15:44:20 +01008#include <stddef.h>
9#include <string.h>
10
Juan Castillobae6b2a2015-11-05 09:24:53 +000011/* mbed TLS headers */
Sumit Garg392e4df2019-11-15 10:43:00 +053012#include <mbedtls/gcm.h>
Juan Castillobae6b2a2015-11-05 09:24:53 +000013#include <mbedtls/md.h>
14#include <mbedtls/memory_buffer_alloc.h>
15#include <mbedtls/oid.h>
16#include <mbedtls/platform.h>
Govindraj Raja9c7dfb02023-01-11 18:34:58 +000017#include <mbedtls/version.h>
Madhukar Pappireddy57eaae82020-03-05 18:18:40 -060018#include <mbedtls/x509.h>
Juan Castilloa57a4d52015-04-02 15:44:20 +010019
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000020#include <common/debug.h>
21#include <drivers/auth/crypto_mod.h>
22#include <drivers/auth/mbedtls/mbedtls_common.h>
Govindraj Raja9c7dfb02023-01-11 18:34:58 +000023
Sumit Garg392e4df2019-11-15 10:43:00 +053024#include <plat/common/platform.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025
Juan Castillobae6b2a2015-11-05 09:24:53 +000026#define LIB_NAME "mbed TLS"
Juan Castilloa57a4d52015-04-02 15:44:20 +010027
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +010028#if CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
29CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010030/*
31 * CRYPTO_MD_MAX_SIZE value is as per current stronger algorithm available
32 * so make sure that mbed TLS MD maximum size must be lesser than this.
33 */
34CASSERT(CRYPTO_MD_MAX_SIZE >= MBEDTLS_MD_MAX_SIZE,
35 assert_mbedtls_md_size_overflow);
36
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +010037#endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
38 CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
Manish V Badarkhee112a5a2021-10-06 23:41:50 +010039
Juan Castilloa57a4d52015-04-02 15:44:20 +010040/*
41 * AlgorithmIdentifier ::= SEQUENCE {
42 * algorithm OBJECT IDENTIFIER,
43 * parameters ANY DEFINED BY algorithm OPTIONAL
44 * }
45 *
46 * SubjectPublicKeyInfo ::= SEQUENCE {
47 * algorithm AlgorithmIdentifier,
48 * subjectPublicKey BIT STRING
49 * }
50 *
51 * DigestInfo ::= SEQUENCE {
52 * digestAlgorithm AlgorithmIdentifier,
53 * digest OCTET STRING
54 * }
55 */
56
57/*
58 * Initialize the library and export the descriptor
59 */
60static void init(void)
61{
Juan Castillobae6b2a2015-11-05 09:24:53 +000062 /* Initialize mbed TLS */
Juan Castilloa57a4d52015-04-02 15:44:20 +010063 mbedtls_init();
64}
65
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +010066#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
67CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Jimmy Brisson640d9912024-04-10 10:20:13 -050068
69
70/*
71 * NOTE: This has been made internal in mbedtls 3.6.0 and the mbedtls team has
72 * advised that it's better to copy out the declaration than it would be to
73 * update to 3.5.2, where this function is exposed.
74 */
75int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid,
76 const mbedtls_x509_buf *sig_params,
77 mbedtls_md_type_t *md_alg,
78 mbedtls_pk_type_t *pk_alg,
79 void **sig_opts);
Juan Castilloa57a4d52015-04-02 15:44:20 +010080/*
81 * Verify a signature.
82 *
83 * Parameters are passed using the DER encoding format following the ASN.1
84 * structures detailed above.
85 */
86static int verify_signature(void *data_ptr, unsigned int data_len,
87 void *sig_ptr, unsigned int sig_len,
88 void *sig_alg, unsigned int sig_alg_len,
89 void *pk_ptr, unsigned int pk_len)
90{
Juan Castillobae6b2a2015-11-05 09:24:53 +000091 mbedtls_asn1_buf sig_oid, sig_params;
92 mbedtls_asn1_buf signature;
93 mbedtls_md_type_t md_alg;
94 mbedtls_pk_type_t pk_alg;
Soby Mathew0a68d132017-05-31 10:35:27 +010095 mbedtls_pk_context pk = {0};
Juan Castilloa57a4d52015-04-02 15:44:20 +010096 int rc;
97 void *sig_opts = NULL;
Juan Castillobae6b2a2015-11-05 09:24:53 +000098 const mbedtls_md_info_t *md_info;
Juan Castilloa57a4d52015-04-02 15:44:20 +010099 unsigned char *p, *end;
Juan Castillobae6b2a2015-11-05 09:24:53 +0000100 unsigned char hash[MBEDTLS_MD_MAX_SIZE];
Juan Castilloa57a4d52015-04-02 15:44:20 +0100101
102 /* Get pointers to signature OID and parameters */
103 p = (unsigned char *)sig_alg;
104 end = (unsigned char *)(p + sig_alg_len);
Juan Castillobae6b2a2015-11-05 09:24:53 +0000105 rc = mbedtls_asn1_get_alg(&p, end, &sig_oid, &sig_params);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100106 if (rc != 0) {
107 return CRYPTO_ERR_SIGNATURE;
108 }
109
110 /* Get the actual signature algorithm (MD + PK) */
Soby Mathew0a68d132017-05-31 10:35:27 +0100111 rc = mbedtls_x509_get_sig_alg(&sig_oid, &sig_params, &md_alg, &pk_alg, &sig_opts);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100112 if (rc != 0) {
113 return CRYPTO_ERR_SIGNATURE;
114 }
115
116 /* Parse the public key */
Juan Castillobae6b2a2015-11-05 09:24:53 +0000117 mbedtls_pk_init(&pk);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100118 p = (unsigned char *)pk_ptr;
119 end = (unsigned char *)(p + pk_len);
Juan Castillobae6b2a2015-11-05 09:24:53 +0000120 rc = mbedtls_pk_parse_subpubkey(&p, end, &pk);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100121 if (rc != 0) {
Soby Mathew0a68d132017-05-31 10:35:27 +0100122 rc = CRYPTO_ERR_SIGNATURE;
123 goto end2;
Juan Castilloa57a4d52015-04-02 15:44:20 +0100124 }
125
126 /* Get the signature (bitstring) */
127 p = (unsigned char *)sig_ptr;
128 end = (unsigned char *)(p + sig_len);
129 signature.tag = *p;
Juan Castillobae6b2a2015-11-05 09:24:53 +0000130 rc = mbedtls_asn1_get_bitstring_null(&p, end, &signature.len);
Demi Marie Obenour447adc02022-12-08 15:24:10 -0500131 if ((rc != 0) || ((size_t)(end - p) != signature.len)) {
Juan Castilloa57a4d52015-04-02 15:44:20 +0100132 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew0a68d132017-05-31 10:35:27 +0100133 goto end1;
Juan Castilloa57a4d52015-04-02 15:44:20 +0100134 }
135 signature.p = p;
136
137 /* Calculate the hash of the data */
Juan Castillobae6b2a2015-11-05 09:24:53 +0000138 md_info = mbedtls_md_info_from_type(md_alg);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100139 if (md_info == NULL) {
140 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew0a68d132017-05-31 10:35:27 +0100141 goto end1;
Juan Castilloa57a4d52015-04-02 15:44:20 +0100142 }
143 p = (unsigned char *)data_ptr;
Juan Castillobae6b2a2015-11-05 09:24:53 +0000144 rc = mbedtls_md(md_info, p, data_len, hash);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100145 if (rc != 0) {
146 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew0a68d132017-05-31 10:35:27 +0100147 goto end1;
Juan Castilloa57a4d52015-04-02 15:44:20 +0100148 }
149
150 /* Verify the signature */
Juan Castillobae6b2a2015-11-05 09:24:53 +0000151 rc = mbedtls_pk_verify_ext(pk_alg, sig_opts, &pk, md_alg, hash,
152 mbedtls_md_get_size(md_info),
153 signature.p, signature.len);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100154 if (rc != 0) {
155 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew0a68d132017-05-31 10:35:27 +0100156 goto end1;
Juan Castilloa57a4d52015-04-02 15:44:20 +0100157 }
158
159 /* Signature verification success */
160 rc = CRYPTO_SUCCESS;
161
Soby Mathew0a68d132017-05-31 10:35:27 +0100162end1:
Juan Castillobae6b2a2015-11-05 09:24:53 +0000163 mbedtls_pk_free(&pk);
Soby Mathew0a68d132017-05-31 10:35:27 +0100164end2:
165 mbedtls_free(sig_opts);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100166 return rc;
167}
168
169/*
170 * Match a hash
171 *
172 * Digest info is passed in DER format following the ASN.1 structure detailed
173 * above.
174 */
175static int verify_hash(void *data_ptr, unsigned int data_len,
176 void *digest_info_ptr, unsigned int digest_info_len)
177{
Juan Castillobae6b2a2015-11-05 09:24:53 +0000178 mbedtls_asn1_buf hash_oid, params;
179 mbedtls_md_type_t md_alg;
180 const mbedtls_md_info_t *md_info;
Juan Castilloa57a4d52015-04-02 15:44:20 +0100181 unsigned char *p, *end, *hash;
Juan Castillobae6b2a2015-11-05 09:24:53 +0000182 unsigned char data_hash[MBEDTLS_MD_MAX_SIZE];
Juan Castilloa57a4d52015-04-02 15:44:20 +0100183 size_t len;
184 int rc;
185
Demi Marie Obenourae266642022-12-08 15:24:01 -0500186 /*
Demi Marie Obenourc2800782023-05-30 13:49:29 -0400187 * Digest info should be an MBEDTLS_ASN1_SEQUENCE, but padding after
188 * it is allowed. This is necessary to support multiple hash
189 * algorithms.
Demi Marie Obenourae266642022-12-08 15:24:01 -0500190 */
Juan Castilloa57a4d52015-04-02 15:44:20 +0100191 p = (unsigned char *)digest_info_ptr;
Sandrine Bailleuxdf8de2d2016-01-04 15:49:23 +0000192 end = p + digest_info_len;
Juan Castillobae6b2a2015-11-05 09:24:53 +0000193 rc = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED |
194 MBEDTLS_ASN1_SEQUENCE);
Demi Marie Obenourc2800782023-05-30 13:49:29 -0400195 if (rc != 0) {
Juan Castilloa57a4d52015-04-02 15:44:20 +0100196 return CRYPTO_ERR_HASH;
197 }
198
Demi Marie Obenourc2800782023-05-30 13:49:29 -0400199 end = p + len;
200
Juan Castilloa57a4d52015-04-02 15:44:20 +0100201 /* Get the hash algorithm */
Juan Castillobae6b2a2015-11-05 09:24:53 +0000202 rc = mbedtls_asn1_get_alg(&p, end, &hash_oid, &params);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100203 if (rc != 0) {
204 return CRYPTO_ERR_HASH;
205 }
206
Juan Castillobae6b2a2015-11-05 09:24:53 +0000207 rc = mbedtls_oid_get_md_alg(&hash_oid, &md_alg);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100208 if (rc != 0) {
209 return CRYPTO_ERR_HASH;
210 }
211
Juan Castillobae6b2a2015-11-05 09:24:53 +0000212 md_info = mbedtls_md_info_from_type(md_alg);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100213 if (md_info == NULL) {
214 return CRYPTO_ERR_HASH;
215 }
216
Demi Marie Obenourae266642022-12-08 15:24:01 -0500217 /* Hash should be octet string type and consume all bytes */
Juan Castillobae6b2a2015-11-05 09:24:53 +0000218 rc = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING);
Demi Marie Obenourae266642022-12-08 15:24:01 -0500219 if ((rc != 0) || ((size_t)(end - p) != len)) {
Juan Castilloa57a4d52015-04-02 15:44:20 +0100220 return CRYPTO_ERR_HASH;
221 }
222
223 /* Length of hash must match the algorithm's size */
Juan Castillobae6b2a2015-11-05 09:24:53 +0000224 if (len != mbedtls_md_get_size(md_info)) {
Juan Castilloa57a4d52015-04-02 15:44:20 +0100225 return CRYPTO_ERR_HASH;
226 }
227 hash = p;
228
229 /* Calculate the hash of the data */
230 p = (unsigned char *)data_ptr;
Juan Castillobae6b2a2015-11-05 09:24:53 +0000231 rc = mbedtls_md(md_info, p, data_len, data_hash);
Juan Castilloa57a4d52015-04-02 15:44:20 +0100232 if (rc != 0) {
233 return CRYPTO_ERR_HASH;
234 }
235
236 /* Compare values */
Antonio Nino Diaz0ca1afa2017-02-09 10:26:54 +0000237 rc = memcmp(data_hash, hash, mbedtls_md_get_size(md_info));
Juan Castilloa57a4d52015-04-02 15:44:20 +0100238 if (rc != 0) {
239 return CRYPTO_ERR_HASH;
240 }
241
242 return CRYPTO_SUCCESS;
243}
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100244#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
245 CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
Juan Castilloa57a4d52015-04-02 15:44:20 +0100246
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100247#if CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
248CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000249/*
Manish V Badarkhee112a5a2021-10-06 23:41:50 +0100250 * Map a generic crypto message digest algorithm to the corresponding macro used
251 * by Mbed TLS.
252 */
253static inline mbedtls_md_type_t md_type(enum crypto_md_algo algo)
254{
255 switch (algo) {
256 case CRYPTO_MD_SHA512:
257 return MBEDTLS_MD_SHA512;
258 case CRYPTO_MD_SHA384:
259 return MBEDTLS_MD_SHA384;
260 case CRYPTO_MD_SHA256:
261 return MBEDTLS_MD_SHA256;
262 default:
263 /* Invalid hash algorithm. */
264 return MBEDTLS_MD_NONE;
265 }
266}
267
268/*
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000269 * Calculate a hash
270 *
271 * output points to the computed hash
272 */
Manish V Badarkhee112a5a2021-10-06 23:41:50 +0100273static int calc_hash(enum crypto_md_algo md_algo, void *data_ptr,
274 unsigned int data_len,
275 unsigned char output[CRYPTO_MD_MAX_SIZE])
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000276{
277 const mbedtls_md_info_t *md_info;
Ryan Everettf33a5ef2024-11-08 15:03:15 +0000278 int rc;
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000279
Manish V Badarkhee112a5a2021-10-06 23:41:50 +0100280 md_info = mbedtls_md_info_from_type(md_type(md_algo));
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000281 if (md_info == NULL) {
282 return CRYPTO_ERR_HASH;
283 }
284
Manish V Badarkhee112a5a2021-10-06 23:41:50 +0100285 /*
286 * Calculate the hash of the data, it is safe to pass the
287 * 'output' hash buffer pointer considering its size is always
288 * bigger than or equal to MBEDTLS_MD_MAX_SIZE.
289 */
Ryan Everettf33a5ef2024-11-08 15:03:15 +0000290 rc = mbedtls_md(md_info, data_ptr, data_len, output);
291 if (rc != 0) {
292 return CRYPTO_ERR_HASH;
293 }
294
295 return CRYPTO_SUCCESS;
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000296}
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100297#endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
298 CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000299
Sumit Garg392e4df2019-11-15 10:43:00 +0530300#if TF_MBEDTLS_USE_AES_GCM
301/*
302 * Stack based buffer allocation for decryption operation. It could
303 * be configured to balance stack usage vs execution speed.
304 */
305#define DEC_OP_BUF_SIZE 128
306
307static int aes_gcm_decrypt(void *data_ptr, size_t len, const void *key,
308 unsigned int key_len, const void *iv,
309 unsigned int iv_len, const void *tag,
310 unsigned int tag_len)
311{
312 mbedtls_gcm_context ctx;
313 mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
314 unsigned char buf[DEC_OP_BUF_SIZE];
315 unsigned char tag_buf[CRYPTO_MAX_TAG_SIZE];
316 unsigned char *pt = data_ptr;
317 size_t dec_len;
318 int diff, i, rc;
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000319 size_t output_length __unused;
Sumit Garg392e4df2019-11-15 10:43:00 +0530320
321 mbedtls_gcm_init(&ctx);
322
323 rc = mbedtls_gcm_setkey(&ctx, cipher, key, key_len * 8);
324 if (rc != 0) {
325 rc = CRYPTO_ERR_DECRYPTION;
326 goto exit_gcm;
327 }
328
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000329#if (MBEDTLS_VERSION_MAJOR < 3)
Sumit Garg392e4df2019-11-15 10:43:00 +0530330 rc = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT, iv, iv_len, NULL, 0);
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000331#else
332 rc = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT, iv, iv_len);
333#endif
Sumit Garg392e4df2019-11-15 10:43:00 +0530334 if (rc != 0) {
335 rc = CRYPTO_ERR_DECRYPTION;
336 goto exit_gcm;
337 }
338
339 while (len > 0) {
340 dec_len = MIN(sizeof(buf), len);
341
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000342#if (MBEDTLS_VERSION_MAJOR < 3)
Sumit Garg392e4df2019-11-15 10:43:00 +0530343 rc = mbedtls_gcm_update(&ctx, dec_len, pt, buf);
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000344#else
345 rc = mbedtls_gcm_update(&ctx, pt, dec_len, buf, sizeof(buf), &output_length);
346#endif
347
Sumit Garg392e4df2019-11-15 10:43:00 +0530348 if (rc != 0) {
349 rc = CRYPTO_ERR_DECRYPTION;
350 goto exit_gcm;
351 }
352
353 memcpy(pt, buf, dec_len);
354 pt += dec_len;
355 len -= dec_len;
356 }
357
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000358#if (MBEDTLS_VERSION_MAJOR < 3)
Sumit Garg392e4df2019-11-15 10:43:00 +0530359 rc = mbedtls_gcm_finish(&ctx, tag_buf, sizeof(tag_buf));
Govindraj Rajadee8b6f2023-01-12 15:34:12 +0000360#else
361 rc = mbedtls_gcm_finish(&ctx, NULL, 0, &output_length, tag_buf, sizeof(tag_buf));
362#endif
363
Sumit Garg392e4df2019-11-15 10:43:00 +0530364 if (rc != 0) {
365 rc = CRYPTO_ERR_DECRYPTION;
366 goto exit_gcm;
367 }
368
369 /* Check tag in "constant-time" */
370 for (diff = 0, i = 0; i < tag_len; i++)
371 diff |= ((const unsigned char *)tag)[i] ^ tag_buf[i];
372
373 if (diff != 0) {
374 rc = CRYPTO_ERR_DECRYPTION;
375 goto exit_gcm;
376 }
377
378 /* GCM decryption success */
379 rc = CRYPTO_SUCCESS;
380
381exit_gcm:
382 mbedtls_gcm_free(&ctx);
383 return rc;
384}
385
386/*
387 * Authenticated decryption of an image
388 */
389static int auth_decrypt(enum crypto_dec_algo dec_algo, void *data_ptr,
390 size_t len, const void *key, unsigned int key_len,
391 unsigned int key_flags, const void *iv,
392 unsigned int iv_len, const void *tag,
393 unsigned int tag_len)
394{
395 int rc;
396
397 assert((key_flags & ENC_KEY_IS_IDENTIFIER) == 0);
398
399 switch (dec_algo) {
400 case CRYPTO_GCM_DECRYPT:
401 rc = aes_gcm_decrypt(data_ptr, len, key, key_len, iv, iv_len,
402 tag, tag_len);
403 if (rc != 0)
404 return rc;
405 break;
406 default:
407 return CRYPTO_ERR_DECRYPTION;
408 }
409
410 return CRYPTO_SUCCESS;
411}
412#endif /* TF_MBEDTLS_USE_AES_GCM */
413
Juan Castilloa57a4d52015-04-02 15:44:20 +0100414/*
415 * Register crypto library descriptor
416 */
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100417#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Sumit Garg392e4df2019-11-15 10:43:00 +0530418#if TF_MBEDTLS_USE_AES_GCM
419REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, calc_hash,
Yann Gautierc68b8af2023-01-24 09:39:47 +0100420 auth_decrypt, NULL);
Sumit Garg392e4df2019-11-15 10:43:00 +0530421#else
422REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, calc_hash,
Yann Gautierc68b8af2023-01-24 09:39:47 +0100423 NULL, NULL);
Sumit Garg392e4df2019-11-15 10:43:00 +0530424#endif
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100425#elif CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY
Sumit Garg392e4df2019-11-15 10:43:00 +0530426#if TF_MBEDTLS_USE_AES_GCM
Yann Gautier2b6673d2023-03-15 11:31:25 +0100427REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL,
Yann Gautierc68b8af2023-01-24 09:39:47 +0100428 auth_decrypt, NULL);
Alexei Fedorov913cb7e2020-01-23 14:27:38 +0000429#else
Yann Gautier2b6673d2023-03-15 11:31:25 +0100430REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL,
431 NULL, NULL);
Sumit Garg392e4df2019-11-15 10:43:00 +0530432#endif
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100433#elif CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY
Yann Gautier2b6673d2023-03-15 11:31:25 +0100434REGISTER_CRYPTO_LIB(LIB_NAME, init, NULL, NULL, calc_hash, NULL, NULL);
Manish V Badarkhec9fdaf62022-06-20 15:32:38 +0100435#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */