From 97ca6f65f6477e7d2fe771d7728e365f88a9c143 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Tue, 8 Aug 2023 17:00:00 +0200 Subject: [PATCH] Use default CTR length in TZ encryption According to API documentation the counter length parameter is optional. TZ implementation should not assume its existence. Change-Id: I89ef3b78e95f2a3a8c79688ee21c9d04a43a5116 --- src/manager/crypto/tz-backend/internals.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/manager/crypto/tz-backend/internals.cpp b/src/manager/crypto/tz-backend/internals.cpp index 9817480..8470c12 100644 --- a/src/manager/crypto/tz-backend/internals.cpp +++ b/src/manager/crypto/tz-backend/internals.cpp @@ -203,7 +203,8 @@ void decompose(const CryptoAlgorithm &alg, switch (algo) { case AlgoType::AES_CTR: iv = unpack(alg, ParamName::ED_IV); - ctrLenOrTagSizeBits = unpack(alg, ParamName::ED_CTR_LEN); + ctrLenOrTagSizeBits = Params::DEFAULT_AES_IV_LEN * 8; + alg.getParam(ParamName::ED_CTR_LEN, ctrLenOrTagSizeBits); // counter length is in bits if (ctrLenOrTagSizeBits != Params::DEFAULT_AES_IV_LEN * 8) { LogError("CTR length invalid: " << std::to_string(ctrLenOrTagSizeBits)); @@ -514,11 +515,11 @@ RawBuffer symmetricEncrypt(const RawBuffer &keyId, const RawBuffer &data) { AlgoType algo = unpack(alg, ParamName::ALGO_TYPE); - uint64_t ctrLen = 0; + uint64_t ctrLen = Params::DEFAULT_AES_IV_LEN * 8; switch (algo) { case AlgoType::AES_CTR: { - ctrLen = unpack(alg, ParamName::ED_CTR_LEN); + alg.getParam(ParamName::ED_CTR_LEN, ctrLen); // counter length is in bits if (ctrLen != Params::DEFAULT_AES_IV_LEN * 8) { LogError("CTR length invalid: " << std::to_string(ctrLen)); @@ -565,11 +566,11 @@ RawBuffer symmetricDecrypt(const RawBuffer &keyId, const RawBuffer &data) { AlgoType algo = unpack(alg, ParamName::ALGO_TYPE); - uint64_t ctrLen = 0; + uint64_t ctrLen = Params::DEFAULT_AES_IV_LEN * 8; switch (algo) { case AlgoType::AES_CTR: { - ctrLen = unpack(alg, ParamName::ED_CTR_LEN); + alg.getParam(ParamName::ED_CTR_LEN, ctrLen); // counter length is in bits if (ctrLen != Params::DEFAULT_AES_IV_LEN * 8) { LogError("CTR length invalid: " << std::to_string(ctrLen)); -- 2.7.4