Skip to content

Commit

Permalink
Don't depend on outputDataLength to be initialized with mbedTLS
Browse files Browse the repository at this point in the history
OpenSSL has no such requirement, so MbedTLS breakages snuck in.
  • Loading branch information
cgutman committed Mar 6, 2024
1 parent 48d7f1a commit eb21561
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/PlatformCrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ bool PltEncryptMessage(PPLT_CRYPTO_CONTEXT ctx, int algorithm, int flags,
ctx->initialized = true;
}

outLength = *outputDataLength;

if (tag != NULL) {
#ifdef USE_MBEDTLS_CRYPTO_EXT
// In mbedTLS, tag is always after ciphertext, while we need to put tag BEFORE ciphertext here
Expand All @@ -88,7 +86,7 @@ bool PltEncryptMessage(PPLT_CRYPTO_CONTEXT ctx, int algorithm, int flags,
#endif
size_t encryptedLength = 0;
unsigned char * encryptedData = tag;
size_t encryptedCapacity = outLength + tagLength;
size_t encryptedCapacity = inputDataLength + tagLength;
if (mbedtls_cipher_auth_encrypt_ext(&ctx->ctx, iv, ivLength, NULL, 0, inputData, inputDataLength, encryptedData,
encryptedCapacity, &encryptedLength, tagLength) != 0) {
return false;
Expand Down Expand Up @@ -273,8 +271,6 @@ bool PltDecryptMessage(PPLT_CRYPTO_CONTEXT ctx, int algorithm, int flags,
ctx->initialized = true;
}

outLength = *outputDataLength;

if (tag != NULL) {
#ifdef USE_MBEDTLS_CRYPTO_EXT
// We only support 16 bytes sized tag
Expand All @@ -296,7 +292,7 @@ bool PltDecryptMessage(PPLT_CRYPTO_CONTEXT ctx, int algorithm, int flags,
// Copy back tag to the end
memcpy(encryptedData + inputDataLength, tagTemp, tagLength);
if (mbedtls_cipher_auth_decrypt_ext(&ctx->ctx, iv, ivLength, NULL, 0, encryptedData, encryptedDataLen,
outputData, outLength, &outLength, tagLength) != 0) {
outputData, inputDataLength, &outLength, tagLength) != 0) {
return false;
}
#else
Expand Down

0 comments on commit eb21561

Please sign in to comment.