diff --git a/core/drivers/crypto/crypto_api/include/drvcrypt.h b/core/drivers/crypto/crypto_api/include/drvcrypt.h index 45a8fb8a4d2..de54063a4c8 100644 --- a/core/drivers/crypto/crypto_api/include/drvcrypt.h +++ b/core/drivers/crypto/crypto_api/include/drvcrypt.h @@ -50,6 +50,7 @@ struct drvcrypt_buf { enum drvcrypt_algo_id { CRYPTO_HASH = 0, /* Hash driver */ CRYPTO_HMAC, /* HMAC driver */ + CRYPTO_CMAC, /* CMAC driver */ CRYPTO_RSA, /* Asymmetric RSA driver */ CRYPTO_MATH, /* Mathematical driver */ CRYPTO_CIPHER, /* Cipher driver */ diff --git a/core/drivers/crypto/crypto_api/include/drvcrypt_mac.h b/core/drivers/crypto/crypto_api/include/drvcrypt_mac.h index 4a46896d72d..c000366c56a 100644 --- a/core/drivers/crypto/crypto_api/include/drvcrypt_mac.h +++ b/core/drivers/crypto/crypto_api/include/drvcrypt_mac.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright 2020 NXP + * Copyright 2019-2020 NXP * * MAC interface calling the HW crypto driver. */ @@ -27,4 +27,13 @@ static inline TEE_Result drvcrypt_register_hmac(drvcrypt_mac_allocate allocate) return drvcrypt_register(CRYPTO_HMAC, (void *)allocate); } +/* + * Register a CMAC processing driver in the crypto API + * + * @allocate - Callback for driver context allocation in the crypto layer + */ +static inline TEE_Result drvcrypt_register_cmac(drvcrypt_mac_allocate allocate) +{ + return drvcrypt_register(CRYPTO_CMAC, (void *)allocate); +} #endif /* __DRVCRYPT_MAC_H__ */ diff --git a/core/drivers/crypto/crypto_api/mac/mac.c b/core/drivers/crypto/crypto_api/mac/mac.c index fabe0ea482f..a233ab088ce 100644 --- a/core/drivers/crypto/crypto_api/mac/mac.c +++ b/core/drivers/crypto/crypto_api/mac/mac.c @@ -20,12 +20,13 @@ TEE_Result drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx, uint32_t algo) assert(ctx); - if (algo_id >= TEE_MAIN_ALGO_MD5 && algo_id <= TEE_MAIN_ALGO_SHA512) { + if (algo_id >= TEE_MAIN_ALGO_MD5 && algo_id <= TEE_MAIN_ALGO_SHA512) mac_alloc = drvcrypt_get_ops(CRYPTO_HMAC); + else + mac_alloc = drvcrypt_get_ops(CRYPTO_CMAC); - if (mac_alloc) - ret = mac_alloc(ctx, algo); - } + if (mac_alloc) + ret = mac_alloc(ctx, algo); CRYPTO_TRACE("mac alloc_ctx ret 0x%" PRIX32, ret);