diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/auth/crypto_mod.c | 23 | ||||
-rw-r--r-- | drivers/auth/mbedtls/mbedtls_crypto.c | 27 |
2 files changed, 48 insertions, 2 deletions
diff --git a/drivers/auth/crypto_mod.c b/drivers/auth/crypto_mod.c index 5e5ac2b03..110c5045f 100644 --- a/drivers/auth/crypto_mod.c +++ b/drivers/auth/crypto_mod.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -103,3 +103,24 @@ int crypto_mod_verify_hash(void *data_ptr, unsigned int data_len, return crypto_lib_desc.verify_hash(data_ptr, data_len, digest_info_ptr, digest_info_len); } + +#if MEASURED_BOOT +/* + * Calculate a hash + * + * Parameters: + * + * alg: message digest algorithm + * data_ptr, data_len: data to be hashed + * output: resulting hash + */ +int crypto_mod_calc_hash(unsigned int alg, void *data_ptr, + unsigned int data_len, unsigned char *output) +{ + assert(data_ptr != NULL); + assert(data_len != 0); + assert(output != NULL); + + return crypto_lib_desc.calc_hash(alg, data_ptr, data_len, output); +} +#endif /* MEASURED_BOOT */ diff --git a/drivers/auth/mbedtls/mbedtls_crypto.c b/drivers/auth/mbedtls/mbedtls_crypto.c index 33420fbbd..04fbc648b 100644 --- a/drivers/auth/mbedtls/mbedtls_crypto.c +++ b/drivers/auth/mbedtls/mbedtls_crypto.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -205,7 +205,32 @@ static int verify_hash(void *data_ptr, unsigned int data_len, return CRYPTO_SUCCESS; } +#if MEASURED_BOOT +/* + * Calculate a hash + * + * output points to the computed hash + */ +int calc_hash(unsigned int alg, void *data_ptr, + unsigned int data_len, unsigned char *output) +{ + const mbedtls_md_info_t *md_info; + + md_info = mbedtls_md_info_from_type((mbedtls_md_type_t)alg); + if (md_info == NULL) { + return CRYPTO_ERR_HASH; + } + + /* Calculate the hash of the data */ + return mbedtls_md(md_info, data_ptr, data_len, output); +} +#endif /* MEASURED_BOOT */ + /* * Register crypto library descriptor */ +#if MEASURED_BOOT +REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, calc_hash); +#else REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash); +#endif /* MEASURED_BOOT */ |