blob: ac67a8210da511658221a4a7205b2598ce1abafb [file] [log] [blame]
Juan Castillo7d37aa12015-04-02 15:44:20 +01001/*
Yann Gautiere8ae4fa2024-05-20 17:11:47 +02002 * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
Juan Castillo7d37aa12015-04-02 15:44:20 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo7d37aa12015-04-02 15:44:20 +01005 */
6
Sumit Garg7cda17b2019-11-15 10:43:00 +05307#include <assert.h>
Juan Castillo7d37aa12015-04-02 15:44:20 +01008#include <stddef.h>
9#include <string.h>
10
Juan Castillo649dbf62015-11-05 09:24:53 +000011/* mbed TLS headers */
Sumit Garg7cda17b2019-11-15 10:43:00 +053012#include <mbedtls/gcm.h>
Juan Castillo649dbf62015-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 Rajad7f61812023-01-11 18:34:58 +000017#include <mbedtls/version.h>
Madhukar Pappireddy93ee2792020-03-05 18:18:40 -060018#include <mbedtls/x509.h>
Juan Castillo7d37aa12015-04-02 15:44:20 +010019
Antonio Nino Diaz09d40e02018-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 Rajad7f61812023-01-11 18:34:58 +000023
Sumit Garg7cda17b2019-11-15 10:43:00 +053024#include <plat/common/platform.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000025
Juan Castillo649dbf62015-11-05 09:24:53 +000026#define LIB_NAME "mbed TLS"
Juan Castillo7d37aa12015-04-02 15:44:20 +010027
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +010028#if CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
29CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Manish V Badarkhe14db9632021-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 Badarkhe2bf4f272022-06-20 15:32:38 +010037#endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
38 CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
Manish V Badarkhe14db9632021-10-06 23:41:50 +010039
Juan Castillo7d37aa12015-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 Castillo649dbf62015-11-05 09:24:53 +000062 /* Initialize mbed TLS */
Juan Castillo7d37aa12015-04-02 15:44:20 +010063 mbedtls_init();
64}
65
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +010066#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
67CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Yann Gautiere8ae4fa2024-05-20 17:11:47 +020068
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 Castillo7d37aa12015-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 Castillo649dbf62015-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 Mathew10012022017-05-31 10:35:27 +010095 mbedtls_pk_context pk = {0};
Juan Castillo7d37aa12015-04-02 15:44:20 +010096 int rc;
97 void *sig_opts = NULL;
Juan Castillo649dbf62015-11-05 09:24:53 +000098 const mbedtls_md_info_t *md_info;
Juan Castillo7d37aa12015-04-02 15:44:20 +010099 unsigned char *p, *end;
Juan Castillo649dbf62015-11-05 09:24:53 +0000100 unsigned char hash[MBEDTLS_MD_MAX_SIZE];
Juan Castillo7d37aa12015-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 Castillo649dbf62015-11-05 09:24:53 +0000105 rc = mbedtls_asn1_get_alg(&p, end, &sig_oid, &sig_params);
Juan Castillo7d37aa12015-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 Mathew10012022017-05-31 10:35:27 +0100111 rc = mbedtls_x509_get_sig_alg(&sig_oid, &sig_params, &md_alg, &pk_alg, &sig_opts);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100112 if (rc != 0) {
113 return CRYPTO_ERR_SIGNATURE;
114 }
115
116 /* Parse the public key */
Juan Castillo649dbf62015-11-05 09:24:53 +0000117 mbedtls_pk_init(&pk);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100118 p = (unsigned char *)pk_ptr;
119 end = (unsigned char *)(p + pk_len);
Juan Castillo649dbf62015-11-05 09:24:53 +0000120 rc = mbedtls_pk_parse_subpubkey(&p, end, &pk);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100121 if (rc != 0) {
Soby Mathew10012022017-05-31 10:35:27 +0100122 rc = CRYPTO_ERR_SIGNATURE;
123 goto end2;
Juan Castillo7d37aa12015-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 Castillo649dbf62015-11-05 09:24:53 +0000130 rc = mbedtls_asn1_get_bitstring_null(&p, end, &signature.len);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100131 if (rc != 0) {
132 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew10012022017-05-31 10:35:27 +0100133 goto end1;
Juan Castillo7d37aa12015-04-02 15:44:20 +0100134 }
135 signature.p = p;
136
137 /* Calculate the hash of the data */
Juan Castillo649dbf62015-11-05 09:24:53 +0000138 md_info = mbedtls_md_info_from_type(md_alg);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100139 if (md_info == NULL) {
140 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew10012022017-05-31 10:35:27 +0100141 goto end1;
Juan Castillo7d37aa12015-04-02 15:44:20 +0100142 }
143 p = (unsigned char *)data_ptr;
Juan Castillo649dbf62015-11-05 09:24:53 +0000144 rc = mbedtls_md(md_info, p, data_len, hash);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100145 if (rc != 0) {
146 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew10012022017-05-31 10:35:27 +0100147 goto end1;
Juan Castillo7d37aa12015-04-02 15:44:20 +0100148 }
149
150 /* Verify the signature */
Juan Castillo649dbf62015-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 Castillo7d37aa12015-04-02 15:44:20 +0100154 if (rc != 0) {
155 rc = CRYPTO_ERR_SIGNATURE;
Soby Mathew10012022017-05-31 10:35:27 +0100156 goto end1;
Juan Castillo7d37aa12015-04-02 15:44:20 +0100157 }
158
159 /* Signature verification success */
160 rc = CRYPTO_SUCCESS;
161
Soby Mathew10012022017-05-31 10:35:27 +0100162end1:
Juan Castillo649dbf62015-11-05 09:24:53 +0000163 mbedtls_pk_free(&pk);
Soby Mathew10012022017-05-31 10:35:27 +0100164end2:
165 mbedtls_free(sig_opts);
Juan Castillo7d37aa12015-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 Castillo649dbf62015-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 Castillo7d37aa12015-04-02 15:44:20 +0100181 unsigned char *p, *end, *hash;
Juan Castillo649dbf62015-11-05 09:24:53 +0000182 unsigned char data_hash[MBEDTLS_MD_MAX_SIZE];
Juan Castillo7d37aa12015-04-02 15:44:20 +0100183 size_t len;
184 int rc;
185
Juan Castillo649dbf62015-11-05 09:24:53 +0000186 /* Digest info should be an MBEDTLS_ASN1_SEQUENCE */
Juan Castillo7d37aa12015-04-02 15:44:20 +0100187 p = (unsigned char *)digest_info_ptr;
Sandrine Bailleuxaa856912016-01-04 15:49:23 +0000188 end = p + digest_info_len;
Juan Castillo649dbf62015-11-05 09:24:53 +0000189 rc = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED |
190 MBEDTLS_ASN1_SEQUENCE);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100191 if (rc != 0) {
192 return CRYPTO_ERR_HASH;
193 }
194
195 /* Get the hash algorithm */
Juan Castillo649dbf62015-11-05 09:24:53 +0000196 rc = mbedtls_asn1_get_alg(&p, end, &hash_oid, &params);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100197 if (rc != 0) {
198 return CRYPTO_ERR_HASH;
199 }
200
Juan Castillo649dbf62015-11-05 09:24:53 +0000201 rc = mbedtls_oid_get_md_alg(&hash_oid, &md_alg);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100202 if (rc != 0) {
203 return CRYPTO_ERR_HASH;
204 }
205
Juan Castillo649dbf62015-11-05 09:24:53 +0000206 md_info = mbedtls_md_info_from_type(md_alg);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100207 if (md_info == NULL) {
208 return CRYPTO_ERR_HASH;
209 }
210
211 /* Hash should be octet string type */
Juan Castillo649dbf62015-11-05 09:24:53 +0000212 rc = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100213 if (rc != 0) {
214 return CRYPTO_ERR_HASH;
215 }
216
217 /* Length of hash must match the algorithm's size */
Juan Castillo649dbf62015-11-05 09:24:53 +0000218 if (len != mbedtls_md_get_size(md_info)) {
Juan Castillo7d37aa12015-04-02 15:44:20 +0100219 return CRYPTO_ERR_HASH;
220 }
221 hash = p;
222
223 /* Calculate the hash of the data */
224 p = (unsigned char *)data_ptr;
Juan Castillo649dbf62015-11-05 09:24:53 +0000225 rc = mbedtls_md(md_info, p, data_len, data_hash);
Juan Castillo7d37aa12015-04-02 15:44:20 +0100226 if (rc != 0) {
227 return CRYPTO_ERR_HASH;
228 }
229
230 /* Compare values */
Antonio Nino Diazfabd21a2017-02-09 10:26:54 +0000231 rc = memcmp(data_hash, hash, mbedtls_md_get_size(md_info));
Juan Castillo7d37aa12015-04-02 15:44:20 +0100232 if (rc != 0) {
233 return CRYPTO_ERR_HASH;
234 }
235
236 return CRYPTO_SUCCESS;
237}
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100238#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
239 CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
Juan Castillo7d37aa12015-04-02 15:44:20 +0100240
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100241#if CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
242CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Alexei Fedorov8c105292020-01-23 14:27:38 +0000243/*
Manish V Badarkhe14db9632021-10-06 23:41:50 +0100244 * Map a generic crypto message digest algorithm to the corresponding macro used
245 * by Mbed TLS.
246 */
247static inline mbedtls_md_type_t md_type(enum crypto_md_algo algo)
248{
249 switch (algo) {
250 case CRYPTO_MD_SHA512:
251 return MBEDTLS_MD_SHA512;
252 case CRYPTO_MD_SHA384:
253 return MBEDTLS_MD_SHA384;
254 case CRYPTO_MD_SHA256:
255 return MBEDTLS_MD_SHA256;
256 default:
257 /* Invalid hash algorithm. */
258 return MBEDTLS_MD_NONE;
259 }
260}
261
262/*
Alexei Fedorov8c105292020-01-23 14:27:38 +0000263 * Calculate a hash
264 *
265 * output points to the computed hash
266 */
Manish V Badarkhe14db9632021-10-06 23:41:50 +0100267static int calc_hash(enum crypto_md_algo md_algo, void *data_ptr,
268 unsigned int data_len,
269 unsigned char output[CRYPTO_MD_MAX_SIZE])
Alexei Fedorov8c105292020-01-23 14:27:38 +0000270{
271 const mbedtls_md_info_t *md_info;
272
Manish V Badarkhe14db9632021-10-06 23:41:50 +0100273 md_info = mbedtls_md_info_from_type(md_type(md_algo));
Alexei Fedorov8c105292020-01-23 14:27:38 +0000274 if (md_info == NULL) {
275 return CRYPTO_ERR_HASH;
276 }
277
Manish V Badarkhe14db9632021-10-06 23:41:50 +0100278 /*
279 * Calculate the hash of the data, it is safe to pass the
280 * 'output' hash buffer pointer considering its size is always
281 * bigger than or equal to MBEDTLS_MD_MAX_SIZE.
282 */
Alexei Fedorov8c105292020-01-23 14:27:38 +0000283 return mbedtls_md(md_info, data_ptr, data_len, output);
284}
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100285#endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
286 CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
Alexei Fedorov8c105292020-01-23 14:27:38 +0000287
Sumit Garg7cda17b2019-11-15 10:43:00 +0530288#if TF_MBEDTLS_USE_AES_GCM
289/*
290 * Stack based buffer allocation for decryption operation. It could
291 * be configured to balance stack usage vs execution speed.
292 */
293#define DEC_OP_BUF_SIZE 128
294
295static int aes_gcm_decrypt(void *data_ptr, size_t len, const void *key,
296 unsigned int key_len, const void *iv,
297 unsigned int iv_len, const void *tag,
298 unsigned int tag_len)
299{
300 mbedtls_gcm_context ctx;
301 mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
302 unsigned char buf[DEC_OP_BUF_SIZE];
303 unsigned char tag_buf[CRYPTO_MAX_TAG_SIZE];
304 unsigned char *pt = data_ptr;
305 size_t dec_len;
306 int diff, i, rc;
Yann Gautierfd566c32024-01-19 17:44:41 +0100307 size_t output_length __unused;
Sumit Garg7cda17b2019-11-15 10:43:00 +0530308
309 mbedtls_gcm_init(&ctx);
310
311 rc = mbedtls_gcm_setkey(&ctx, cipher, key, key_len * 8);
312 if (rc != 0) {
313 rc = CRYPTO_ERR_DECRYPTION;
314 goto exit_gcm;
315 }
316
Yann Gautierfd566c32024-01-19 17:44:41 +0100317#if (MBEDTLS_VERSION_MAJOR < 3)
Sumit Garg7cda17b2019-11-15 10:43:00 +0530318 rc = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT, iv, iv_len, NULL, 0);
Yann Gautierfd566c32024-01-19 17:44:41 +0100319#else
320 rc = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT, iv, iv_len);
321#endif
Sumit Garg7cda17b2019-11-15 10:43:00 +0530322 if (rc != 0) {
323 rc = CRYPTO_ERR_DECRYPTION;
324 goto exit_gcm;
325 }
326
327 while (len > 0) {
328 dec_len = MIN(sizeof(buf), len);
329
Yann Gautierfd566c32024-01-19 17:44:41 +0100330#if (MBEDTLS_VERSION_MAJOR < 3)
Sumit Garg7cda17b2019-11-15 10:43:00 +0530331 rc = mbedtls_gcm_update(&ctx, dec_len, pt, buf);
Yann Gautierfd566c32024-01-19 17:44:41 +0100332#else
333 rc = mbedtls_gcm_update(&ctx, pt, dec_len, buf, sizeof(buf), &output_length);
334#endif
335
Sumit Garg7cda17b2019-11-15 10:43:00 +0530336 if (rc != 0) {
337 rc = CRYPTO_ERR_DECRYPTION;
338 goto exit_gcm;
339 }
340
341 memcpy(pt, buf, dec_len);
342 pt += dec_len;
343 len -= dec_len;
344 }
345
Yann Gautierfd566c32024-01-19 17:44:41 +0100346#if (MBEDTLS_VERSION_MAJOR < 3)
Sumit Garg7cda17b2019-11-15 10:43:00 +0530347 rc = mbedtls_gcm_finish(&ctx, tag_buf, sizeof(tag_buf));
Yann Gautierfd566c32024-01-19 17:44:41 +0100348#else
349 rc = mbedtls_gcm_finish(&ctx, NULL, 0, &output_length, tag_buf, sizeof(tag_buf));
350#endif
351
Sumit Garg7cda17b2019-11-15 10:43:00 +0530352 if (rc != 0) {
353 rc = CRYPTO_ERR_DECRYPTION;
354 goto exit_gcm;
355 }
356
357 /* Check tag in "constant-time" */
358 for (diff = 0, i = 0; i < tag_len; i++)
359 diff |= ((const unsigned char *)tag)[i] ^ tag_buf[i];
360
361 if (diff != 0) {
362 rc = CRYPTO_ERR_DECRYPTION;
363 goto exit_gcm;
364 }
365
366 /* GCM decryption success */
367 rc = CRYPTO_SUCCESS;
368
369exit_gcm:
370 mbedtls_gcm_free(&ctx);
371 return rc;
372}
373
374/*
375 * Authenticated decryption of an image
376 */
377static int auth_decrypt(enum crypto_dec_algo dec_algo, void *data_ptr,
378 size_t len, const void *key, unsigned int key_len,
379 unsigned int key_flags, const void *iv,
380 unsigned int iv_len, const void *tag,
381 unsigned int tag_len)
382{
383 int rc;
384
385 assert((key_flags & ENC_KEY_IS_IDENTIFIER) == 0);
386
387 switch (dec_algo) {
388 case CRYPTO_GCM_DECRYPT:
389 rc = aes_gcm_decrypt(data_ptr, len, key, key_len, iv, iv_len,
390 tag, tag_len);
391 if (rc != 0)
392 return rc;
393 break;
394 default:
395 return CRYPTO_ERR_DECRYPTION;
396 }
397
398 return CRYPTO_SUCCESS;
399}
400#endif /* TF_MBEDTLS_USE_AES_GCM */
401
Juan Castillo7d37aa12015-04-02 15:44:20 +0100402/*
403 * Register crypto library descriptor
404 */
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100405#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
Sumit Garg7cda17b2019-11-15 10:43:00 +0530406#if TF_MBEDTLS_USE_AES_GCM
407REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, calc_hash,
408 auth_decrypt);
Alexei Fedorov8c105292020-01-23 14:27:38 +0000409#else
Sumit Garg7cda17b2019-11-15 10:43:00 +0530410REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, calc_hash,
411 NULL);
412#endif
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100413#elif CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY
Sumit Garg7cda17b2019-11-15 10:43:00 +0530414#if TF_MBEDTLS_USE_AES_GCM
415REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash,
416 auth_decrypt);
417#else
418REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL);
419#endif
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100420#elif CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY
Manish V Badarkhe0aa0b3a2021-12-16 10:41:47 +0000421REGISTER_CRYPTO_LIB(LIB_NAME, init, calc_hash);
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100422#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */