mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-07-01 07:15:39 +00:00
Don't depend on outputDataLength to be initialized with mbedTLS
OpenSSL has no such requirement, so MbedTLS breakages snuck in.
This commit is contained in:
parent
48d7f1ace1
commit
eb21561541
@ -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
|
||||
@ -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;
|
||||
@ -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
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user