diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2022-03-26 18:46:01 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2022-03-26 21:14:57 +0100 |
commit | 05fd14006d0ee5991f207d2f98a1a9ab0b4060fb (patch) | |
tree | a64bce23d59db0ffc2128e38303f79e2e3f76aa9 /src | |
parent | 533269ca9a13736eb96196b41b38e7c9b04577ae (diff) | |
download | VeraCrypt-05fd14006d0ee5991f207d2f98a1a9ab0b4060fb.tar.gz VeraCrypt-05fd14006d0ee5991f207d2f98a1a9ab0b4060fb.zip |
Remove dead code from chacha_ECRYPT_encrypt_bytes (Coverity)
Diffstat (limited to 'src')
-rw-r--r-- | src/Crypto/chacha-xmm.c | 23 | ||||
-rw-r--r-- | src/Setup/SelfExtract.c | 8 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/Crypto/chacha-xmm.c b/src/Crypto/chacha-xmm.c index 198d0b5b..478de594 100644 --- a/src/Crypto/chacha-xmm.c +++ b/src/Crypto/chacha-xmm.c @@ -107,54 +107,47 @@ void chacha_ECRYPT_keysetup(uint32* input,const uint8 *k,uint32 kbits,uint32 ivb input[8] = U8TO32_LITTLE(k + 0); input[9] = U8TO32_LITTLE(k + 4); input[10] = U8TO32_LITTLE(k + 8); input[11] = U8TO32_LITTLE(k + 12); input[0] = U8TO32_LITTLE(constants + 0); input[1] = U8TO32_LITTLE(constants + 4); input[2] = U8TO32_LITTLE(constants + 8); input[3] = U8TO32_LITTLE(constants + 12); } void chacha_ECRYPT_ivsetup(uint32* input,const uint8 *iv) { input[12] = 0; input[13] = 0; input[14] = U8TO32_LITTLE(iv + 0); input[15] = U8TO32_LITTLE(iv + 4); } void chacha_ECRYPT_encrypt_bytes(size_t bytes, uint32* x, const uint8* m, uint8* out, uint8* output, unsigned int r) { unsigned int i; #include "chacha_u4.h" #include "chacha_u1.h" #ifndef _M_X64 #ifdef _MSC_VER #if _MSC_VER < 1900 _mm_empty(); #endif #endif #endif if (!bytes) return; - for (;;) { - salsa20_wordtobyte(output,x, r); - x[12] = PLUSONE(x[12]); - if (!x[12]) { - x[13] = PLUSONE(x[13]); - /* stopping at 2^70 bytes per nonce is user's responsibility */ - } - if (bytes <= 64) { - for (i = 0;i < bytes;++i) out[i] = m[i] ^ output[i]; - return; - } - for (i = 0;i < 64;++i) out[i] = m[i] ^ output[i]; - bytes -= 64; - out += 64; - m += 64; + // bytes is now guaranteed to be between 1 and 63 + salsa20_wordtobyte(output,x, r); + x[12] = PLUSONE(x[12]); + if (!x[12]) { + x[13] = PLUSONE(x[13]); + /* stopping at 2^70 bytes per nonce is user's responsibility */ } + + for (i = 0;i < bytes;++i) out[i] = m[i] ^ output[i]; } #endif diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c index d5dd3d2c..c672c364 100644 --- a/src/Setup/SelfExtract.c +++ b/src/Setup/SelfExtract.c @@ -563,70 +563,78 @@ BOOL SelfExtractInMemory (wchar_t *path, BOOL bSkipCountCheck) fileDataEndPos--; fileDataStartPos = (int) FindStringInFile (path, MAG_START_MARKER, (int) strlen (MAG_START_MARKER)); if (fileDataStartPos < 0) { Error ("CANNOT_READ_FROM_PACKAGE", NULL); return FALSE; } fileDataStartPos += (int) strlen (MAG_START_MARKER); filePos = fileDataStartPos; // Read the stored total size of the uncompressed data if (!LoadInt32 (path, &uncompressedLen, filePos)) { Error ("CANNOT_READ_FROM_PACKAGE", NULL); return FALSE; } filePos += 4; // Read the stored total size of the compressed data if (!LoadInt32 (path, &compressedLen, filePos)) { Error ("CANNOT_READ_FROM_PACKAGE", NULL); return FALSE; } filePos += 4; if (compressedLen != fileDataEndPos - fileDataStartPos - 8 + 1) { Error ("DIST_PACKAGE_CORRUPTED", NULL); + return FALSE; + } + + // Test to make Coverity happy. It will always be false + if (uncompressedLen >= (INT_MAX - 524288)) + { + Error ("DIST_PACKAGE_CORRUPTED", NULL); + return FALSE; } decompressedDataLen = uncompressedLen; DecompressedData = malloc (decompressedDataLen); if (DecompressedData == NULL) { Error ("ERR_MEM_ALLOC", NULL); return FALSE; } bufPos = DecompressedData; bufEndPos = bufPos + uncompressedLen - 1; compressedData = LoadFileBlock (path, filePos, compressedLen); if (compressedData == NULL) { free (DecompressedData); DecompressedData = NULL; Error ("CANNOT_READ_FROM_PACKAGE", NULL); return FALSE; } // Decompress the data if (DecompressBuffer (DecompressedData, decompressedDataLen, compressedData, compressedLen) != uncompressedLen) { Error ("DIST_PACKAGE_CORRUPTED", NULL); goto sem_end; } while (bufPos <= bufEndPos && fileNo < NBR_COMPRESSED_FILES) { // Filename length Decompressed_Files[fileNo].fileNameLength = mgetWord (bufPos); |