Skip to content

Commit

Permalink
drivers: crypto: generic resources for crypto device driver - CMAC
Browse files Browse the repository at this point in the history
Add a generic cryptographic driver CMAC interface connecting
TEE Crypto generic APIs to HW driver interface

Signed-off-by: Cedric Neveux <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Reviewed-by: Etienne Carriere <[email protected]>
  • Loading branch information
cneveux authored and jforissier committed Jun 15, 2020
1 parent 9bdff33 commit b7604b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/drivers/crypto/crypto_api/include/drvcrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
11 changes: 10 additions & 1 deletion core/drivers/crypto/crypto_api/include/drvcrypt_mac.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright 2020 NXP
* Copyright 2019-2020 NXP
*
* MAC interface calling the HW crypto driver.
*/
Expand All @@ -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__ */
9 changes: 5 additions & 4 deletions core/drivers/crypto/crypto_api/mac/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b7604b9

Please sign in to comment.