Fix bugs during exporting a wrapped key 98/296798/1
authorDongsun Lee <ds73.lee@samsung.com>
Sat, 29 Jul 2023 07:26:10 +0000 (16:26 +0900)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 4 Aug 2023 08:11:17 +0000 (10:11 +0200)
- generous output size check
- enlarged encryption overhead for RSA
- use type of wrap to key

Change-Id: I64367edf00d58e67df62a682a05c58dae5e2327b

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

index a811557..a1fbbb7 100644 (file)
@@ -120,7 +120,7 @@ RawBuffer Key::wrap(const CryptoAlgorithm &alg,
                                                                           alg,
                                                                           keyToWrapId,
                                                                           Pwd(keyToWrapPass, keyToWrapIV, keyToWrapTag),
-                                                                          m_type);
+                                                                          keyToWrap.dataType);
 }
 
 RawBuffer SKey::encrypt(const CryptoAlgorithm &alg, const RawBuffer &data)
index 8710982..fb05e3c 100644 (file)
@@ -770,9 +770,13 @@ RawBuffer TrustZoneContext::exportWrappedKey(const RawBuffer &wrappingKeyId,
 
        LogDebug("GetData data_size = [" << dataSize << "]");
 
+       uint32_t enc_overhead = KM_ENCRYPTION_OVERHEAD;
+       if (algo == ALGO_RSA)
+               enc_overhead = KM_RSA_BLOCK_SIZE;
+
        // encrypted data may be longer
        TZSerializer sOut;
-       sOut.Push(new TZSerializableBinary(dataSize + KM_ENCRYPTION_OVERHEAD));
+       sOut.Push(new TZSerializableBinary(dataSize + enc_overhead, false));
        TrustZoneMemory outMemory(m_Context, sOut.GetSize(), TEEC_MEM_OUTPUT);
        sOut.Serialize(outMemory);