summaryrefslogtreecommitdiff
path: root/core/tee/tee_rpmb_fs.c
diff options
context:
space:
mode:
authorJens Wiklander <jens.wiklander@linaro.org>2017-11-09 23:20:25 +0100
committerJérôme Forissier <jerome.forissier@linaro.org>2017-11-14 13:48:32 +0100
commite9eaba5c0a3d27075b1e995294fd42de65c0b912 (patch)
tree74999649def54c18ee7b4fa22f4486178086dc4f /core/tee/tee_rpmb_fs.c
parent82d91db11f0188df939ce52f6106a39f026de74c (diff)
Replace struct mac_ops with function interface
Adds mac_cipher_get_ctx_size(), mac_cipher_init(), mac_cipher_update() and mac_cipher_final() replacing struct mac_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'core/tee/tee_rpmb_fs.c')
-rw-r--r--core/tee/tee_rpmb_fs.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/core/tee/tee_rpmb_fs.c b/core/tee/tee_rpmb_fs.c
index bde489e4..a63f022c 100644
--- a/core/tee/tee_rpmb_fs.c
+++ b/core/tee/tee_rpmb_fs.c
@@ -353,18 +353,18 @@ static TEE_Result tee_rpmb_key_gen(uint16_t dev_id __unused,
memcpy(message, rpmb_ctx->cid, RPMB_EMMC_CID_SIZE);
memset(message + RPMB_CID_PRV_OFFSET, 0, 1);
memset(message + RPMB_CID_CRC_OFFSET, 0, 1);
- res = crypto_ops.mac.init(ctx, TEE_ALG_HMAC_SHA256, hwkey.data,
- HW_UNIQUE_KEY_LENGTH);
+ res = crypto_mac_init(ctx, TEE_ALG_HMAC_SHA256, hwkey.data,
+ HW_UNIQUE_KEY_LENGTH);
if (res != TEE_SUCCESS)
goto out;
- res = crypto_ops.mac.update(ctx, TEE_ALG_HMAC_SHA256,
+ res = crypto_mac_update(ctx, TEE_ALG_HMAC_SHA256,
message,
RPMB_EMMC_CID_SIZE);
if (res != TEE_SUCCESS)
goto out;
- res = crypto_ops.mac.final(ctx, TEE_ALG_HMAC_SHA256, key, len);
+ res = crypto_mac_final(ctx, TEE_ALG_HMAC_SHA256, key, len);
out:
free(ctx);
@@ -415,19 +415,19 @@ static TEE_Result tee_rpmb_mac_calc(uint8_t *mac, uint32_t macsize,
if (!ctx)
return TEE_ERROR_OUT_OF_MEMORY;
- res = crypto_ops.mac.init(ctx, TEE_ALG_HMAC_SHA256, key, keysize);
+ res = crypto_mac_init(ctx, TEE_ALG_HMAC_SHA256, key, keysize);
if (res != TEE_SUCCESS)
goto func_exit;
for (i = 0; i < blkcnt; i++) {
- res = crypto_ops.mac.update(ctx, TEE_ALG_HMAC_SHA256,
- datafrms[i].data,
- RPMB_MAC_PROTECT_DATA_SIZE);
+ res = crypto_mac_update(ctx, TEE_ALG_HMAC_SHA256,
+ datafrms[i].data,
+ RPMB_MAC_PROTECT_DATA_SIZE);
if (res != TEE_SUCCESS)
goto func_exit;
}
- res = crypto_ops.mac.final(ctx, TEE_ALG_HMAC_SHA256, mac, macsize);
+ res = crypto_mac_final(ctx, TEE_ALG_HMAC_SHA256, mac, macsize);
if (res != TEE_SUCCESS)
goto func_exit;
@@ -741,8 +741,8 @@ static TEE_Result tee_rpmb_data_cpy_mac_calc(struct rpmb_data_frame *datafrm,
goto func_exit;
}
- res = crypto_ops.mac.init(ctx, TEE_ALG_HMAC_SHA256, rpmb_ctx->key,
- RPMB_KEY_MAC_SIZE);
+ res = crypto_mac_init(ctx, TEE_ALG_HMAC_SHA256, rpmb_ctx->key,
+ RPMB_KEY_MAC_SIZE);
if (res != TEE_SUCCESS)
goto func_exit;
@@ -762,9 +762,8 @@ static TEE_Result tee_rpmb_data_cpy_mac_calc(struct rpmb_data_frame *datafrm,
*/
memcpy(&localfrm, &datafrm[i], RPMB_DATA_FRAME_SIZE);
- res = crypto_ops.mac.update(ctx, TEE_ALG_HMAC_SHA256,
- localfrm.data,
- RPMB_MAC_PROTECT_DATA_SIZE);
+ res = crypto_mac_update(ctx, TEE_ALG_HMAC_SHA256, localfrm.data,
+ RPMB_MAC_PROTECT_DATA_SIZE);
if (res != TEE_SUCCESS)
goto func_exit;
@@ -796,13 +795,13 @@ static TEE_Result tee_rpmb_data_cpy_mac_calc(struct rpmb_data_frame *datafrm,
goto func_exit;
/* Update MAC against the last block */
- res = crypto_ops.mac.update(ctx, TEE_ALG_HMAC_SHA256, lastfrm->data,
- RPMB_MAC_PROTECT_DATA_SIZE);
+ res = crypto_mac_update(ctx, TEE_ALG_HMAC_SHA256, lastfrm->data,
+ RPMB_MAC_PROTECT_DATA_SIZE);
if (res != TEE_SUCCESS)
goto func_exit;
- res = crypto_ops.mac.final(ctx, TEE_ALG_HMAC_SHA256, rawdata->key_mac,
- RPMB_KEY_MAC_SIZE);
+ res = crypto_mac_final(ctx, TEE_ALG_HMAC_SHA256, rawdata->key_mac,
+ RPMB_KEY_MAC_SIZE);
if (res != TEE_SUCCESS)
goto func_exit;
@@ -1128,22 +1127,12 @@ static TEE_Result tee_rpmb_write_and_verify_key(uint16_t dev_id __unused)
}
#endif
-/* True when all the required crypto functions are available */
-static bool have_crypto_ops(void)
-{
- return (crypto_ops.mac.init && crypto_ops.mac.update &&
- crypto_ops.mac.final);
-}
-
/* This function must never return TEE_SUCCESS if rpmb_ctx == NULL */
static TEE_Result tee_rpmb_init(uint16_t dev_id)
{
TEE_Result res = TEE_SUCCESS;
struct rpmb_dev_info dev_info;
- if (!have_crypto_ops())
- return TEE_ERROR_NOT_SUPPORTED;
-
if (!rpmb_ctx) {
rpmb_ctx = calloc(1, sizeof(struct tee_rpmb_ctx));
if (!rpmb_ctx)
@@ -1178,9 +1167,8 @@ static TEE_Result tee_rpmb_init(uint16_t dev_id)
memcpy(rpmb_ctx->cid, dev_info.cid, RPMB_EMMC_CID_SIZE);
if ((rpmb_ctx->hash_ctx_size == 0) &&
- (crypto_ops.mac.get_ctx_size(
- TEE_ALG_HMAC_SHA256,
- &rpmb_ctx->hash_ctx_size))) {
+ crypto_mac_get_ctx_size(TEE_ALG_HMAC_SHA256,
+ &rpmb_ctx->hash_ctx_size)) {
rpmb_ctx->hash_ctx_size = 0;
res = TEE_ERROR_GENERIC;
goto func_exit;