Fix bugs during exporting a wrapped key
[platform/core/security/key-manager.git] / src / manager / crypto / tz-backend / tz-context.cpp
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);