fixing crypto issue "passphrase longer than plaintext"
This commit is contained in:
Rainer Kottenhoff 2016-11-06 16:15:36 +01:00
parent 40cff43135
commit 0c4c5a5da5
4 changed files with 36 additions and 33 deletions

View File

@ -361,17 +361,19 @@ BOOL ReadAndDecryptFile(HWND hwnd, HANDLE hFile, DWORD size, void** result, DWOR
AES_bin_setup(&fileDecode, AES_DIR_DECRYPT, KEY_BYTES * 8, binFileKey);
AES_bin_cipherInit(&fileCypher, AES_MODE_CBC, &rawdata[PREAMBLE_SIZE]); // IV is next
{ // finally, decrypt the actual data
int nbb = 0;
int nbp = 0;
if ((readsize - code_offset) > PAD_SLOP) {
int nbb = BAD_CIPHER_STATE;
int nbp = BAD_CIPHER_STATE;
if ((readsize - code_offset) >= PAD_SLOP) {
nbb = AES_blockDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset], readsize - code_offset - PAD_SLOP, rawdata);
}
if (nbb >= 0) {
nbp = AES_padDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset + nbb], readsize - code_offset - nbb, rawdata + nbb);
if (nbp > 0) {
nbb += nbp;
rawdata[nbb] = (char)0;
rawdata[nbb + 1] = (char)0; // two zeros in case it's multi-byte
*resultlen = (DWORD)nbb;
}
if (nbp >= 0) {
int nb = nbb + nbp;
rawdata[nb] = (char)0;
rawdata[nb + 1] = (char)0; // two zeros in case it's multi-byte
*resultlen = (DWORD)nb;
bReadSuccess = TRUE;
}
else {

View File

@ -853,7 +853,7 @@ int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBit
return Nr;
}
void rijndaelEncrypt(u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) {
void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) {
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
@ -1034,7 +1034,7 @@ void rijndaelEncrypt(u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16])
PUTU32(ct + 12, s3);
}
void rijndaelDecrypt(u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]) {
void rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]) {
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
@ -1217,7 +1217,7 @@ void rijndaelDecrypt(u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16])
#ifdef INTERMEDIATE_VALUE_KAT
void rijndaelEncryptRound(u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds) {
void rijndaelEncryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds) {
int r;
u32 s0, s1, s2, s3, t0, t1, t2, t3;
@ -1310,7 +1310,7 @@ void rijndaelEncryptRound(u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int roun
PUTU32(block + 12, s3);
}
void rijndaelDecryptRound(u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds) {
void rijndaelDecryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds) {
int r;
u32 s0, s1, s2, s3, t0, t1, t2, t3;

View File

@ -37,12 +37,12 @@ typedef unsigned int u32;
int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits);
int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits);
void rijndaelEncrypt(u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]);
void rijndaelDecrypt(u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]);
void rijndaelEncrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]);
void rijndaelDecrypt(const u32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]);
#ifdef INTERMEDIATE_VALUE_KAT
void rijndaelEncryptRound(u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds);
void rijndaelDecryptRound(u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds);
void rijndaelEncryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds);
void rijndaelDecryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], int rounds);
#endif /* INTERMEDIATE_VALUE_KAT */
#endif /* __RIJNDAEL_ALG_FST_H */

View File

@ -542,7 +542,8 @@ BOOL EditCopyAppend(HWND hwnd)
(int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0) -
(int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);
pszText = LocalAlloc(LPTR,iSelCount + 1);
// fixing 64bit issue #37
pszText = LocalAlloc(LPTR,iSelCount + 4);
(int)SendMessage(hwnd,SCI_GETSELTEXT,0,(LPARAM)pszText);
}
}
@ -1651,8 +1652,8 @@ void EditInvertCase(HWND hwnd)
int iSelCount = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0) -
(int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);
char* pszText = GlobalAlloc(GPTR,(iSelCount)+2);
LPWSTR pszTextW = GlobalAlloc(GPTR,(iSelCount*2)+2);
char* pszText = GlobalAlloc(GPTR,(iSelCount)+4);
LPWSTR pszTextW = GlobalAlloc(GPTR,(iSelCount*2)+8);
if (pszText == NULL || pszTextW == NULL) {
GlobalFree(pszText);
@ -1727,8 +1728,8 @@ void EditTitleCase(HWND hwnd)
int iSelCount = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0) -
(int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);
char* pszText = GlobalAlloc(GPTR,(iSelCount)+2);
LPWSTR pszTextW = GlobalAlloc(GPTR,(iSelCount*2)+2);
char* pszText = GlobalAlloc(GPTR,(iSelCount)+4);
LPWSTR pszTextW = GlobalAlloc(GPTR,(iSelCount*2)+8);
if (pszText == NULL || pszTextW == NULL) {
GlobalFree(pszText);
@ -1839,8 +1840,8 @@ void EditSentenceCase(HWND hwnd)
int iSelCount = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0) -
(int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);
char* pszText = GlobalAlloc(GPTR,(iSelCount)+2);
LPWSTR pszTextW = GlobalAlloc(GPTR,(iSelCount*2)+2);
char* pszText = GlobalAlloc(GPTR,(iSelCount)+4);
LPWSTR pszTextW = GlobalAlloc(GPTR,(iSelCount*2)+8);
if (pszText == NULL || pszTextW == NULL) {
GlobalFree(pszText);
@ -1926,12 +1927,12 @@ void EditURLEncode(HWND hwnd)
DWORD cchEscapedW;
LPWSTR pszEscapedW;
pszText = LocalAlloc(LPTR,(iSelCount)+2);
pszText = LocalAlloc(LPTR,(iSelCount)+4);
if (pszText == NULL) {
return;
}
pszTextW = LocalAlloc(LPTR,(iSelCount*2)+2);
pszTextW = LocalAlloc(LPTR,(iSelCount*2)+8);
if (pszTextW == NULL) {
LocalFree(pszText);
return;
@ -2012,12 +2013,12 @@ void EditURLDecode(HWND hwnd)
DWORD cchUnescapedW;
LPWSTR pszUnescapedW;
pszText = LocalAlloc(LPTR,(iSelCount)+2);
pszText = LocalAlloc(LPTR,(iSelCount)+4);
if (pszText == NULL) {
return;
}
pszTextW = LocalAlloc(LPTR,(iSelCount*2)+2);
pszTextW = LocalAlloc(LPTR,(iSelCount*2)+8);
if (pszTextW == NULL) {
LocalFree(pszText);
return;
@ -5810,23 +5811,23 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase
(int)SendMessage(hwnd, SCI_LINEFROMPOSITION, iSelEnd, 0))
return;
pszText = LocalAlloc(LPTR,iSelCount + 1);
// fixing 64bit issue #37
pszText = LocalAlloc(LPTR,iSelCount + 4);
(int)SendMessage(hwnd,SCI_GETSELTEXT,0,(LPARAM)pszText);
// exit if selection is not a word and Match whole words only is enabled
if (bMarkOccurrencesMatchWords)
{
iSelStart = 0;
while (pszText[iSelStart])
int i = 0;
while ((i <= iSelCount) && pszText[i])
{
if (StrChrIA(" \t\r\n@#$%^&*~-=+()[]{}\\/:;'\"", pszText[iSelStart]))
if (StrChrIA(" \t\r\n@#$%^&*~-=+()[]{}\\/:;'\"", pszText[i]))
{
LocalFree(pszText);
return;
}
iSelStart++;
i++;
}
}