Merge commit '05fedaf5cbdfe00b0b1c60121ba9466fecbd197f' into mui_dev

This commit is contained in:
Pairi Daiza 2019-06-06 00:34:18 +02:00
commit 9e7aa5a01f
7 changed files with 95 additions and 82 deletions

View File

@ -1 +1 @@
2228
2243

View File

@ -36,7 +36,6 @@ see ecryption-doc.txt for details
#define WKEY_LEN 256
#define KEY_LEN 512
#define PAD_SLOP 16
bool useFileKey = false; // file should be encrypted
char fileKey[KEY_LEN] = { 0 }; // ascii passphrase for the file key
@ -476,7 +475,7 @@ bool EncryptAndWriteFile(HWND hwnd, HANDLE hFile, BYTE *data, DWORD size, DWORD
static int sequence = 1; // sequence counter so each time is unique
srand(sequence++ ^ (unsigned int)time(NULL));
{
int i; for (i = 0; i < AES_MAX_IV_SIZE; i++) {
for (int i = 0; i < AES_MAX_IV_SIZE; i++) {
precodedata[PREAMBLE_SIZE + i] = 0;//rand();
}
}
@ -513,7 +512,7 @@ bool EncryptAndWriteFile(HWND hwnd, HANDLE hFile, BYTE *data, DWORD size, DWORD
AES_bin_setup(&masterencode, AES_DIR_ENCRYPT, KEY_BYTES * 8, binMasterKey);
{// generate another IV for the master key
int i; for (i = 0; i < sizeof(masterFileIV); i++) { masterFileIV[i] = (BYTE)(rand() & BYTE_MAX); }
for (int i = 0; i < sizeof(masterFileIV); i++) { masterFileIV[i] = (BYTE)(rand() & BYTE_MAX); }
}
AES_bin_cipherInit(&mastercypher, AES_MODE_CBC, masterFileIV);
@ -542,10 +541,11 @@ bool EncryptAndWriteFile(HWND hwnd, HANDLE hFile, BYTE *data, DWORD size, DWORD
DWORD enclen = 0;
bool bWriteRes = false;
BYTE* encdata = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, size + PAD_SLOP); // add slop to the end for padding
if (!encdata)
return bWriteRes;
BYTE* encdata = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + PAD_SLOP); // add slop to the end for padding
if (!encdata) {
return bWriteRes;
}
if (size > PAD_SLOP) { enclen += AES_blockEncrypt(&fileCypher, &fileEncode, data, size - PAD_SLOP, encdata); }
enclen += AES_padEncrypt(&fileCypher, &fileEncode, data + enclen, size - enclen, encdata + enclen);

View File

@ -3,13 +3,19 @@
#define __CRYPTO_H__
#include <stdbool.h>
#ifdef _DEBUG
#define BUG1(a,b) { perror("a"); }
#define BUG(a) { perror("a"); }
#else
#define BUG1(a,b) ((void)0);
#define BUG(a) ((void)0);
#endif
#define PREAMBLE_SIZE 8 // 4 byte signature + 4 byte subfile type
#define KEY_BYTES 32 // 32 bytes = 256 bits of key
#define PREAMBLE_SIZE 8 // 4 byte signature + 4 byte subfile type
#define PAD_SLOP 16 // padding for block chain
#define KEY_BYTES 32 // 32 bytes = 256 bits of key
#define PREAMBLE 0x01020304 // first 4 bytes of the file
#define FILEKEY_FORMAT 1 // next 4 bytes determine version/format
#define FILEKEY_FORMAT 1 // next 4 bytes determine version/format
#define MASTERKEY_FORMAT 2 // format with master key
#define MASTER_KEY_OFFSET (PREAMBLE_SIZE+AES_MAX_IV_SIZE)
#define UNUSED(expr) (void)(expr)

View File

@ -96,7 +96,6 @@ int AES_setup
char *keyMat;
u8 cipherKey[MAXKB];
if (TheKey != NULL) {
//strncpy(key->TheKey, TheKey, keyLen/4);
memcpy_s(key->TheKey, AES_MAX_KEY_SIZE, TheKey, keyLen / 4);
@ -245,8 +244,8 @@ int AES_blockEncrypt
int inputLen, // @parm the size of the input data
BYTE *outBuffer) //@parm a buffer to receive the encrypted data
{
int i, k, t, numBlocks;
u8 block[16], *iv;
u8 block[16];
u8* iv;
if (cipher == NULL ||
key == NULL ||
@ -257,11 +256,11 @@ int AES_blockEncrypt
return 0; /* nothing to do */
}
numBlocks = inputLen / 16;
unsigned int const numBlocks = inputLen / 16;
switch (cipher->mode) {
case AES_MODE_ECB:
for (i = numBlocks; i > 0; i--) {
for (unsigned int i = numBlocks; i > 0; i--) {
rijndaelEncrypt(key->rk, key->Nr, input, outBuffer);
input += 16;
outBuffer += 16;
@ -270,7 +269,7 @@ int AES_blockEncrypt
case AES_MODE_CBC:
iv = cipher->IV;
for (i = numBlocks; i > 0; i--) {
for (unsigned int i = numBlocks; i > 0; i--) {
((u32*)block)[0] = ((u32*)input)[0] ^ ((u32*)iv)[0];
((u32*)block)[1] = ((u32*)input)[1] ^ ((u32*)iv)[1];
((u32*)block)[2] = ((u32*)input)[2] ^ ((u32*)iv)[2];
@ -287,12 +286,12 @@ int AES_blockEncrypt
case AES_MODE_CFB1:
iv = cipher->IV;
for (i = numBlocks; i > 0; i--) {
for (unsigned int i = numBlocks; i > 0; i--) {
memcpy(outBuffer, input, 16);
for (k = 0; k < 128; k++) {
for (unsigned int k = 0; k < 128; k++) {
rijndaelEncrypt(key->ek, key->Nr, iv, block);
outBuffer[k >> 3] ^= (block[0] & 0x80U) >> (k & 7);
for (t = 0; t < 15; t++) {
for (unsigned int t = 0; t < 15; t++) {
iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7);
}
iv[15] = (iv[15] << 1) | ((outBuffer[k >> 3] >> (7 - (k & 7))) & 1);
@ -330,8 +329,8 @@ int AES_padEncrypt
int inputOctets, // @parm the size of the input data
BYTE *outBuffer) //@parm a buffer to receive the encrypted data
{
int i, numBlocks, padLen;
u8 block[16], *iv;
u8 block[16];
u8* iv;
if (cipher == NULL ||
key == NULL ||
@ -342,50 +341,57 @@ int AES_padEncrypt
return 0; /* nothing to do */
}
numBlocks = inputOctets / 16;
unsigned int const numBlocks = inputOctets / 16;
switch (cipher->mode) {
case AES_MODE_ECB:
for (i = numBlocks; i > 0; i--) {
rijndaelEncrypt(key->rk, key->Nr, input, outBuffer);
input += 16;
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16 * numBlocks);
if ((padLen <= 0) || (padLen > 16)) {
BUG1("Padding must be 1-16, is %d", padLen);
}
memcpy(block, input, 16 - padLen);
memset(block + 16 - padLen, padLen, padLen);
rijndaelEncrypt(key->rk, key->Nr, block, outBuffer);
break;
{
for (unsigned int i = numBlocks; i > 0; i--) {
rijndaelEncrypt(key->rk, key->Nr, input, outBuffer);
input += 16;
outBuffer += 16;
}
unsigned int const padLen = 16 - (inputOctets - 16 * numBlocks);
if ((padLen <= 0) || (padLen > 16)) {
BUG1("Padding must be 1-16, is %d", padLen);
return 16 * numBlocks;
}
memcpy(block, input, 16 - padLen);
memset(block + 16 - padLen, padLen, padLen);
rijndaelEncrypt(key->rk, key->Nr, block, outBuffer);
}
break;
case AES_MODE_CBC:
iv = cipher->IV;
for (i = numBlocks; i > 0; i--) {
((u32*)block)[0] = ((u32*)input)[0] ^ ((u32*)iv)[0];
((u32*)block)[1] = ((u32*)input)[1] ^ ((u32*)iv)[1];
((u32*)block)[2] = ((u32*)input)[2] ^ ((u32*)iv)[2];
((u32*)block)[3] = ((u32*)input)[3] ^ ((u32*)iv)[3];
rijndaelEncrypt(key->rk, key->Nr, block, outBuffer);
iv = outBuffer;
input += 16;
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16 * numBlocks);
if ((padLen <= 0) || (padLen > 16)) {
BUG1("Padding must be 1-16, is %d", padLen);
}
for (i = 0; i < 16 - padLen; i++) {
block[i] = input[i] ^ iv[i];
}
for (i = 16 - padLen; (0 <= i) && (i < 16); i++) {
block[i] = (BYTE)padLen ^ iv[i];
}
{
iv = cipher->IV;
for (unsigned int i = numBlocks; i > 0; i--) {
((u32*)block)[0] = ((u32*)input)[0] ^ ((u32*)iv)[0];
((u32*)block)[1] = ((u32*)input)[1] ^ ((u32*)iv)[1];
((u32*)block)[2] = ((u32*)input)[2] ^ ((u32*)iv)[2];
((u32*)block)[3] = ((u32*)input)[3] ^ ((u32*)iv)[3];
rijndaelEncrypt(key->rk, key->Nr, block, outBuffer);
// set for chaining to the next block, even though there will normally not be one
memcpy(cipher->IV, outBuffer, AES_MAX_IV_SIZE);
break;
iv = outBuffer;
input += 16;
outBuffer += 16;
}
unsigned int const padLen = 16 - (inputOctets - 16 * numBlocks);
if ((padLen <= 0) || (padLen > 16)) {
BUG1("Padding must be 1-16, is %d", padLen);
return 16 * numBlocks;
}
for (unsigned int i = 0; i < 16 - padLen; i++) {
block[i] = input[i] ^ iv[i];
}
BYTE const plen = (BYTE)(padLen & 0xFF);
for (unsigned int i = 16 - padLen; (i < 16); i++) {
block[i] = plen ^ iv[i];
}
rijndaelEncrypt(key->rk, key->Nr, block, outBuffer);
// set for chaining to the next block, even though there will normally not be one
memcpy(cipher->IV, outBuffer, AES_MAX_IV_SIZE);
}
break;
default:
return BAD_CIPHER_STATE;
@ -409,8 +415,8 @@ int AES_blockDecrypt
BYTE *outBuffer) //@parm a buffer to receive the decrypted buffer
{
//int lim = 32;
int i, k, t, numBlocks;
u8 block[16], *iv;
u8 block[16];
u8* iv;
if (cipher == NULL ||
key == NULL ||
@ -421,11 +427,11 @@ int AES_blockDecrypt
return 0; /* nothing to do */
}
numBlocks = inputLen / 16;
unsigned int const numBlocks = inputLen / 16;
switch (cipher->mode) {
case AES_MODE_ECB:
for (i = numBlocks; i > 0; i--) {
for (unsigned int i = numBlocks; i > 0; i--) {
rijndaelDecrypt(key->rk, key->Nr, input, outBuffer);
input += 16;
outBuffer += 16;
@ -434,7 +440,7 @@ int AES_blockDecrypt
case AES_MODE_CBC:
iv = cipher->IV;
for (i = numBlocks; i > 0; i--) {
for (unsigned int i = numBlocks; i > 0; i--) {
rijndaelDecrypt(key->rk, key->Nr, input, block);
((u32*)block)[0] ^= ((u32*)iv)[0];
((u32*)block)[1] ^= ((u32*)iv)[1];
@ -449,11 +455,11 @@ int AES_blockDecrypt
case AES_MODE_CFB1:
iv = cipher->IV;
for (i = numBlocks; i > 0; i--) {
for (unsigned int i = numBlocks; i > 0; i--) {
memcpy(outBuffer, input, 16);
for (k = 0; k < 128; k++) {
for (unsigned int k = 0; k < 128; k++) {
rijndaelEncrypt(key->ek, key->Nr, iv, block);
for (t = 0; t < 15; t++) {
for (unsigned int t = 0; t < 15; t++) {
iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7);
}
iv[15] = (iv[15] << 1) | ((input[k >> 3] >> (7 - (k & 7))) & 1);
@ -487,8 +493,8 @@ int AES_padDecrypt
int inputOctets, //@parm the size of the input
BYTE *outBuffer) //@parm a buffer to receive the decrypted buffer
{
int i, numBlocks, padLen;
u8 block[16];
unsigned int padLen;
if (cipher == NULL ||
key == NULL ||
@ -502,12 +508,12 @@ int AES_padDecrypt
return BAD_DATA;
}
numBlocks = inputOctets / 16;
unsigned int const numBlocks = inputOctets / 16;
switch (cipher->mode) {
case AES_MODE_ECB:
/* all blocks but last */
for (i = numBlocks - 1; i > 0; i--) {
for (unsigned int i = numBlocks - 1; i > 0; i--) {
rijndaelDecrypt(key->rk, key->Nr, input, outBuffer);
input += 16;
outBuffer += 16;
@ -518,7 +524,7 @@ int AES_padDecrypt
if (padLen >= 16) {
return BAD_DATA;
}
for (i = 16 - padLen; i < 16; i++) {
for (unsigned int i = 16 - padLen; i < 16; i++) {
if (block[i] != padLen) {
return BAD_DATA;
}
@ -528,7 +534,7 @@ int AES_padDecrypt
case AES_MODE_CBC:
/* all blocks but last */
for (i = numBlocks - 1; i > 0; i--) {
for (unsigned int i = numBlocks - 1; i > 0; i--) {
rijndaelDecrypt(key->rk, key->Nr, input, block);
((u32*)block)[0] ^= ((u32*)cipher->IV)[0];
((u32*)block)[1] ^= ((u32*)cipher->IV)[1];
@ -550,7 +556,7 @@ int AES_padDecrypt
if (padLen <= 0 || padLen > 16) {
return BAD_DATA;
}
for (i = 16 - padLen; i < 16; i++) {
for (unsigned int i = 16 - padLen; i < 16; i++) {
if (block[i] != padLen) {
return BAD_DATA;
}

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.19.529.2228"
version="5.19.605.2243"
type="win32"
/>
<description>Notepad3 RC2</description>

View File

@ -1316,8 +1316,6 @@ bool EditSaveFile(
// get text
cbData = (DWORD)SciCall_GetTextLength();
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
SciCall_GetText((DocPos)SizeOfMem(lpData), lpData);
if (cbData == 0) {
bWriteSuccess = SetEndOfFile(hFile);
@ -1325,7 +1323,10 @@ bool EditSaveFile(
}
else {
// FIXME: move checks in front of disk file access
lpData = AllocMem(cbData + 4 + PAD_SLOP, HEAP_ZERO_MEMORY); //fix: +bom
SciCall_GetText((DocPos)cbData+1, lpData);
// FIXME: move checks in front of disk file access
// Msg if file tag encoding does not correspond to BOM
/*if ((g_Encodings[iEncoding].uFlags & NCP_UNICODE) == 0 && (g_Encodings[iEncoding].uFlags & NCP_UTF8_SIGN) == 0) {
bool bEncodingMismatch = true;
@ -1352,7 +1353,7 @@ bool EditSaveFile(
{
SetEndOfFile(hFile);
LPWSTR lpDataWide = AllocMem(cbData * 2 + 16, HEAP_ZERO_MEMORY);
LPWSTR lpDataWide = AllocMem(cbData * 2 + PAD_SLOP, HEAP_ZERO_MEMORY);
int bomoffset = 0;
if (Encoding_IsUNICODE_BOM(status->iEncoding)) {
const char* bom = "\xFF\xFE";
@ -1378,7 +1379,7 @@ bool EditSaveFile(
if (Encoding_IsUTF8_SIGN(status->iEncoding)) {
const char* bom = "\xEF\xBB\xBF";
DWORD bomoffset = 3;
DWORD const bomoffset = 3;
MoveMemory(&lpData[bomoffset], lpData, cbData);
CopyMemory(lpData, bom, bomoffset);
cbData += bomoffset;
@ -1395,7 +1396,7 @@ bool EditSaveFile(
BOOL bCancelDataLoss = FALSE;
UINT uCodePage = Encoding_GetCodePage(status->iEncoding);
LPWSTR lpDataWide = AllocMem(cbData * 2 + 16, HEAP_ZERO_MEMORY);
LPWSTR lpDataWide = AllocMem(cbData * 2 + PAD_SLOP, HEAP_ZERO_MEMORY);
int cbDataWide = MultiByteToWideChar(Encoding_SciCP,0,lpData,cbData,
lpDataWide,(MBWC_DocPos_Cast)(SizeOfMem(lpDataWide)/sizeof(WCHAR)));

View File

@ -7,8 +7,8 @@
#define SAPPNAME "Notepad3"
#define VERSION_MAJOR 5
#define VERSION_MINOR 19
#define VERSION_REV 529
#define VERSION_BUILD 2228
#define VERSION_REV 605
#define VERSION_BUILD 2243
#define SCINTILLA_VER 415+
#define ONIGMO_REGEX_VER 6.2.0
#define VERSION_PATCH RC2