Deserialize tags only if password was given 15/296715/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 3 Aug 2023 08:55:48 +0000 (10:55 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 3 Aug 2023 09:24:24 +0000 (11:24 +0200)
Change-Id: I1c598e17740785e4bd49edc120b6844ebe65e88a

src/manager/crypto/tz-backend/tz-context.cpp

index 7a6e921..ffa41a0 100644 (file)
@@ -249,28 +249,27 @@ void TrustZoneContext::GenerateAKey(tz_command commandId,
                                     const RawBuffer &hashPriv,
                                                                        const RawBuffer &hashPub)
 {
-       uint32_t pubTagSize = 0;
-       uint32_t privTagSize = 0;
        uint32_t pubPwdExists = pubPwd.empty() ? 0 : 1;
-       if (pubPwdExists) {
-               pubTagSize = Params::DEFAULT_AES_GCM_TAG_LEN_BYTES;
-       }
+       TZSerializer sOut;
+       if (pubPwdExists)
+               sOut.Push(new TZSerializableBinary(Params::DEFAULT_AES_GCM_TAG_LEN_BYTES));
+
        uint32_t privPwdExists = privPwd.empty() ? 0 : 1;
-       if (privPwdExists) {
-               privTagSize = Params::DEFAULT_AES_GCM_TAG_LEN_BYTES;
-       }
+       if (privPwdExists)
+               sOut.Push(new TZSerializableBinary(Params::DEFAULT_AES_GCM_TAG_LEN_BYTES));
 
        push(sIn, EncPwd{pubPwd, pubPwdIv}, EncPwd{privPwd, privPwdIv}, hashPriv, hashPub);
        TrustZoneMemory inMemory(m_Context, sIn.GetSize(), TEEC_MEM_INPUT);
        sIn.Serialize(inMemory);
 
-       TZSerializer sOut;
-       sOut.Push(new TZSerializableBinary(pubTagSize));
-       sOut.Push(new TZSerializableBinary(privTagSize));
-
        TrustZoneMemory outMemory(m_Context, sOut.GetSize(), TEEC_MEM_OUTPUT);
 
-       TEEC_Operation op = makeOp(TEEC_VALUE_INOUT, inMemory, outMemory);
+       TEEC_Operation op;
+       if (sOut.GetSize() == 0) {
+               op = makeOp(TEEC_VALUE_INOUT, inMemory);
+       } else {
+               op = makeOp(TEEC_VALUE_INOUT, inMemory, outMemory);
+       }
        op.params[0].value.b = genParam;
 
        Execute(commandId, &op);