From 94615a4f980f4cb755724497820db7fe1ca37ffe Mon Sep 17 00:00:00 2001 From: Wentong Wu Date: Wed, 3 Apr 2019 04:49:06 +0800 Subject: [PATCH] ext: lib: crypto: unify the API of CCM alogrith unify the API of CCM alogrithm's implemation for TinyCrypt, mbedTLS and cc2520 crypto device to make users easy to use. Fixes #8339. Signed-off-by: Wentong Wu --- drivers/crypto/crypto_tc_shim.c | 4 +++- drivers/ieee802154/ieee802154_cc2520.c | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/crypto_tc_shim.c b/drivers/crypto/crypto_tc_shim.c index a0784e0526f..37b8657440a 100644 --- a/drivers/crypto/crypto_tc_shim.c +++ b/drivers/crypto/crypto_tc_shim.c @@ -125,7 +125,9 @@ static int do_ccm_encrypt_mac(struct cipher_ctx *ctx, * of this and provide sufficient buffer space in output buffer to hold * both encrypted output and hash */ - aead_op->tag = op->out_buf + op->in_len; + if (aead_op->tag) { + memcpy(aead_op->tag, op->out_buf + op->in_len, ccm.mlen); + } /* Before returning TC_CRYPTO_SUCCESS, tc_ccm_generation_encryption() * will advance the output buffer pointer by op->in_len bytes, diff --git a/drivers/ieee802154/ieee802154_cc2520.c b/drivers/ieee802154/ieee802154_cc2520.c index caa00ff4f7a..49fa36a8a75 100644 --- a/drivers/ieee802154/ieee802154_cc2520.c +++ b/drivers/ieee802154/ieee802154_cc2520.c @@ -1283,11 +1283,6 @@ static int _cc2520_crypto_ccm(struct cipher_ctx *ctx, return -EINVAL; } - if (apkt->tag) { - LOG_ERR("CCM encryption does not take a tag"); - return -EINVAL; - } - m = insert_crypto_parameters(ctx, apkt, ccm_nonce, &auth_crypt); if (m < 0) { LOG_ERR("Inserting crypto parameters failed"); @@ -1312,7 +1307,10 @@ static int _cc2520_crypto_ccm(struct cipher_ctx *ctx, return -EIO; } - apkt->tag = apkt->pkt->out_buf + apkt->pkt->in_len; + if (apkt->tag) { + memcpy(apkt->tag, apkt->pkt->out_buf + apkt->pkt->in_len, + ctx->mode_params.ccm_info.tag_len); + } return 0; }