VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/CommonLib/EfiConsole.c6
-rw-r--r--Library/CommonLib/EfiFile.c61
-rw-r--r--Library/CommonLib/EfiMem.c27
-rw-r--r--Library/DcsCfgLib/DcsCfgLib.inf8
-rw-r--r--Library/DcsCfgLib/GptEdit.c8
-rw-r--r--Library/DcsTpmLib/Tpm20.c2
-rw-r--r--Library/PasswordLib/ConsolePassword.c39
-rw-r--r--Library/PasswordLib/PicturePassword.c2
-rw-r--r--Library/VeraCryptLib/DcsProp4
-rw-r--r--Library/VeraCryptLib/DcsVeraCrypt.c25
-rw-r--r--Library/VeraCryptLib/DcsVeraCrypt.h2
-rw-r--r--Library/VeraCryptLib/VeraCryptLib.inf18
-rw-r--r--Library/VeraCryptLib/llmath.c435
-rw-r--r--Library/VeraCryptLib/mklinks_src.bat14
14 files changed, 385 insertions, 266 deletions
diff --git a/Library/CommonLib/EfiConsole.c b/Library/CommonLib/EfiConsole.c
index 0d94235..daf087f 100644
--- a/Library/CommonLib/EfiConsole.c
+++ b/Library/CommonLib/EfiConsole.c
@@ -175,7 +175,7 @@ ConsoleShowTip(
// remove tip
for (i = 0; i < StrLen(tip); ++i) {
- OUT_PRINT(L"\b \b", tip);
+ OUT_PRINT(L"\b \b");
}
}
@@ -366,7 +366,7 @@ AsciiHexToByte(
}
BOOLEAN
-AsciiStrToGuid(
+DcsAsciiStrToGuid(
OUT EFI_GUID *guid,
IN CHAR8 *str
)
@@ -428,7 +428,7 @@ AsciiHexToBytes(
}
BOOLEAN
-StrHexToBytes(
+DcsStrHexToBytes(
OUT UINT8 *b,
IN UINTN *bytesLen,
IN CHAR16 *str
diff --git a/Library/CommonLib/EfiFile.c b/Library/CommonLib/EfiFile.c
index fdc999c..4ea164e 100644
--- a/Library/CommonLib/EfiFile.c
+++ b/Library/CommonLib/EfiFile.c
@@ -42,6 +42,38 @@ InitFS() {
}
EFI_STATUS
+DirectoryCreate(
+ IN EFI_FILE* root,
+ IN CHAR16* name
+ )
+{
+ EFI_FILE* file;
+ EFI_STATUS res;
+ if (!name) { return EFI_INVALID_PARAMETER; }
+
+ res = FileOpen(root, name, &file, EFI_FILE_MODE_READ | EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE, EFI_FILE_DIRECTORY);
+ if (EFI_ERROR(res)) return res;
+ FileClose(file);
+ return res;
+}
+
+EFI_STATUS
+DirectoryExists(
+ IN EFI_FILE* root,
+ IN CHAR16* name
+ )
+{
+ EFI_FILE* file;
+ EFI_STATUS res;
+ if (!name) { return EFI_INVALID_PARAMETER; }
+
+ res = FileOpen(root, name, &file, EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY);
+ if (EFI_ERROR(res)) return res;
+ FileClose(file);
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
FileOpenRoot(
IN EFI_HANDLE rootHandle,
OUT EFI_FILE** rootFile)
@@ -131,12 +163,14 @@ EFI_STATUS
FileWrite(
IN EFI_FILE* f,
IN VOID* data,
- IN OUT UINTN* bytes,
+ IN OUT UINTN bytes,
IN OUT UINT64* position)
{
EFI_STATUS res;
+ UINTN remaining;
+ UINT8* pbData = (UINT8*) data;
- if (!f || !data || !bytes) {
+ if (!f || !data) {
return EFI_INVALID_PARAMETER;
}
if (position != NULL) {
@@ -145,7 +179,20 @@ FileWrite(
return res;
}
}
- res = f->Write(f, bytes, data);
+ remaining = bytes;
+ res = f->Write(f, &bytes, pbData);
+ if (!EFI_ERROR(res)) {
+ remaining -= bytes;
+ pbData += bytes;
+ bytes = remaining;
+ while ((remaining > 0) && !EFI_ERROR(res))
+ {
+ res = f->Write(f, &bytes, pbData);
+ remaining -= bytes;
+ pbData += bytes;
+ bytes = remaining;
+ }
+ }
if (position != NULL) {
f->GetPosition(f, position);
}
@@ -265,12 +312,11 @@ FileSave(
{
EFI_FILE* file;
EFI_STATUS res;
- UINTN sz = size;
if (!data || !name) { return EFI_INVALID_PARAMETER; }
FileDelete(root, name);
res = FileOpen(root, name, &file, EFI_FILE_MODE_READ | EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE, 0);
if (EFI_ERROR(res)) return res;
- res = FileWrite(file, data, &sz, NULL);
+ res = FileWrite(file, data, size, NULL);
FileClose(file);
return res;
}
@@ -348,7 +394,8 @@ FileCopy(
res = EFI_BUFFER_TOO_SMALL;
goto copyerr;
}
-
+
+ FileDelete (dstroot, dst);
res = FileOpen(dstroot, dst, &dstfile, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(res)) goto copyerr;
@@ -356,7 +403,7 @@ FileCopy(
datasz = remains > bufSz ? bufSz : remains;
res =FileRead(srcfile, data, &datasz, NULL);
if (EFI_ERROR(res)) goto copyerr;
- res = FileWrite(dstfile, data, &datasz, NULL);
+ res = FileWrite(dstfile, data, datasz, NULL);
if (EFI_ERROR(res)) goto copyerr;
remains -= datasz;
} while (remains > 0);
diff --git a/Library/CommonLib/EfiMem.c b/Library/CommonLib/EfiMem.c
index d9386c0..872d3de 100644
--- a/Library/CommonLib/EfiMem.c
+++ b/Library/CommonLib/EfiMem.c
@@ -72,3 +72,30 @@ PrepareMemory(
*mem = buf;
return status;
}
+
+//////////////////////////////////////////////////////////////////////////
+// Memory misc
+//////////////////////////////////////////////////////////////////////////
+EFI_STATUS MemoryHasPattern (
+ CONST VOID* buffer,
+ UINTN bufferLen,
+ CONST VOID* pattern,
+ UINTN patternLen)
+{
+ EFI_STATUS status = EFI_NOT_FOUND;
+ if (patternLen <= bufferLen)
+ {
+ UINTN i;
+ CONST UINT8* memPtr = (CONST UINT8*) buffer;
+ for (i = 0; i <= (bufferLen - patternLen); ++i)
+ {
+ if (CompareMem (&memPtr[i], pattern, patternLen) == 0)
+ {
+ status = EFI_SUCCESS;
+ break;
+ }
+ }
+ }
+
+ return status;
+}
diff --git a/Library/DcsCfgLib/DcsCfgLib.inf b/Library/DcsCfgLib/DcsCfgLib.inf
index d199bb1..2dd0aab 100644
--- a/Library/DcsCfgLib/DcsCfgLib.inf
+++ b/Library/DcsCfgLib/DcsCfgLib.inf
@@ -74,6 +74,10 @@ DEBUG_VS2015x86_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE
RELEASE_VS2015x86_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /D_UEFI
NOOPT_VS2015x86_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /D_UEFI
+DEBUG_VS2017_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /D_UEFI
+RELEASE_VS2017_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /D_UEFI
+NOOPT_VS2017_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /D_UEFI
+
RELEASE_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
DEBUG_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
NOOPT_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
@@ -81,3 +85,7 @@ NOOPT_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
RELEASE_VS2015x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
DEBUG_VS2015x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
NOOPT_VS2015x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
+
+RELEASE_VS2017_X64_NASM_FLAGS = -Xvc -d_UEFI=1
+DEBUG_VS2017_X64_NASM_FLAGS = -Xvc -d_UEFI=1
+NOOPT_VS2017_X64_NASM_FLAGS = -Xvc -d_UEFI=1
diff --git a/Library/DcsCfgLib/GptEdit.c b/Library/DcsCfgLib/GptEdit.c
index bae8f1e..1cb2b35 100644
--- a/Library/DcsCfgLib/GptEdit.c
+++ b/Library/DcsCfgLib/GptEdit.c
@@ -161,7 +161,7 @@ GptLoadFromDisk(
EFI_PARTITION_ENTRY *part;
part = &GptMainEntrys[i];
if (CompareMem(&gEfiPartTypeSystemPartGuid, &part->PartitionTypeGUID, sizeof(EFI_GUID)) == 0) {
- CHAR16* defExec = L"\\EFI\\Microsoft\\Boot\\Bootmgfw.efi";
+ CHAR16* defExec = L"\\EFI\\Microsoft\\Boot\\bootmgfw_ms.vc";
DeExecParams = MEM_ALLOC(sizeof(*DeExecParams));
ZeroMem(DeExecParams, sizeof(*DeExecParams));
CopyMem(&DeExecParams->ExecPartGuid, &part->UniquePartitionGUID, sizeof(EFI_GUID));
@@ -289,13 +289,13 @@ DeListSaveToFile() {
UINTN pad;
len = (UINTN)DeList->DE[i].Length;
pad = (((len + 511) >> 9) << 9) - len;
- res = FileWrite(file, DeData[i], &len, NULL);
+ res = FileWrite(file, DeData[i], len, NULL);
if (EFI_ERROR(res)) {
ERR_PRINT(L"Write: %r\n", res);
goto error;
}
if (pad > 0) {
- res = FileWrite(file, pad512buf, &pad, NULL);
+ res = FileWrite(file, pad512buf, pad, NULL);
if (EFI_ERROR(res)) {
ERR_PRINT(L"Write: %r\n", res);
goto error;
@@ -636,7 +636,7 @@ GptAskGUID(
ok = TRUE;
}
else {
- ok = AsciiStrToGuid(&result, buf);
+ ok = DcsAsciiStrToGuid(&result, buf);
if (ok) {
CopyMem(guid, &result, sizeof(result));
}
diff --git a/Library/DcsTpmLib/Tpm20.c b/Library/DcsTpmLib/Tpm20.c
index 3ddc4df..182742e 100644
--- a/Library/DcsTpmLib/Tpm20.c
+++ b/Library/DcsTpmLib/Tpm20.c
@@ -539,7 +539,7 @@ DcsTpm2NvRead(
{
EFI_STATUS res;
TPMI_SH_AUTH_SESSION SessionHandle = 0;
- UINT32 PcrMask,
+ UINT32 PcrMask;
CE(DcsTpm2NVReadPcrMask(&PcrMask));
diff --git a/Library/PasswordLib/ConsolePassword.c b/Library/PasswordLib/ConsolePassword.c
index 6894b50..8270290 100644
--- a/Library/PasswordLib/ConsolePassword.c
+++ b/Library/PasswordLib/ConsolePassword.c
@@ -29,6 +29,8 @@ AskConsolePwdInt(
EFI_INPUT_KEY key;
UINT32 count = 0;
UINTN i;
+
+ if ((asciiLine != NULL) && (line_max >= 1)) asciiLine[0] = '\0';
gST->ConOut->EnableCursor(gST->ConOut, TRUE);
if (gPasswordTimeout) {
@@ -36,20 +38,21 @@ AskConsolePwdInt(
UINTN EventIndex = 0;
InputEvents[0] = gST->ConIn->WaitForKey;
gBS->CreateEvent(EVT_TIMER, 0, (EFI_EVENT_NOTIFY)NULL, NULL, &InputEvents[1]);
- gBS->SetTimer(InputEvents[1], TimerPeriodic, 10000000 * gPasswordTimeout);
+ gBS->SetTimer(InputEvents[1], TimerRelative, 10000000 * gPasswordTimeout);
gBS->WaitForEvent(2, InputEvents, &EventIndex);
- gPasswordTimeout = 0;
+ gBS->SetTimer(InputEvents[1], TimerCancel, 0);
gBS->CloseEvent(InputEvents[1]);
if (EventIndex == 1) {
- *retCode = AskPwdRetCancel;
+ *retCode = AskPwdRetTimeout;
return ;
}
}
do {
key = GetKey();
- // Remove dirty chars 0.1s
- FlushInputDelay(100000);
+ // Remove dirty chars
+ if (gKeyboardInputDelay)
+ FlushInputDelay(gKeyboardInputDelay * 1000);
if (key.ScanCode == SCAN_ESC) {
*retCode = AskPwdRetCancel;
@@ -63,19 +66,21 @@ AskConsolePwdInt(
if (key.ScanCode == SCAN_F5) {
show = show ? 0 : 1;
- if (show) {
- for (i = 0; i < count; i++) {
- OUT_PRINT(L"\b");
- }
- OUT_PRINT(L"%a", asciiLine);
- }
- else {
- for (i = 0; i < count; i++) {
- OUT_PRINT(L"\b");
+ if (count > 0) {
+ if (show) {
+ for (i = 0; i < count; i++) {
+ OUT_PRINT(L"\b");
+ }
+ OUT_PRINT(L"%a", asciiLine);
}
- if (gPasswordProgress) {
+ else {
for (i = 0; i < count; i++) {
- OUT_PRINT(L"*");
+ OUT_PRINT(L"\b");
+ }
+ if (gPasswordProgress) {
+ for (i = 0; i < count; i++) {
+ OUT_PRINT(L"*");
+ }
}
}
}
@@ -101,7 +106,7 @@ AskConsolePwdInt(
break;
}
- if ((count >= line_max &&
+ if ((count >= (line_max - 1) &&
key.UnicodeChar != CHAR_BACKSPACE) ||
key.UnicodeChar == CHAR_NULL ||
key.UnicodeChar == CHAR_TAB ||
diff --git a/Library/PasswordLib/PicturePassword.c b/Library/PasswordLib/PicturePassword.c
index b2d8fad..7ce4014 100644
--- a/Library/PasswordLib/PicturePassword.c
+++ b/Library/PasswordLib/PicturePassword.c
@@ -32,6 +32,7 @@ UINT8 gPasswordVisible = 0;
int gPasswordShowMark = 1;
UINT8 gPasswordProgress = 1;
int gPasswordTimeout = 0;
+UINTN gKeyboardInputDelay = 100;
int gPlatformLocked = 0;
int gTPMLocked = 0;
@@ -285,7 +286,6 @@ AskPictPwdInt(
CHAR8 pwdNewChar = 0;
if (gPasswordTimeout) {
- UINTN EventIndex = 0;
InputEvents[0] = gST->ConIn->WaitForKey;
eventsCount = 2;
if (gTouchPointer != NULL) {
diff --git a/Library/VeraCryptLib/DcsProp b/Library/VeraCryptLib/DcsProp
index e0b6691..c9ca1ff 100644
--- a/Library/VeraCryptLib/DcsProp
+++ b/Library/VeraCryptLib/DcsProp
@@ -6,7 +6,7 @@
0 - text message is displayed
PasswordMsg to specify message
1 - touch picture password if touch is supported by EFI. check PlatformInfo
- PasswordPicture to specify bitmap
+ PasswordPicture to specify bitmap (only support BITMAPINFOHEADER format)
-->
<config key="PasswordType">0</config>
<config key="PasswordMsg">Password:</config>
@@ -179,4 +179,4 @@ Hash:</config-->
<config key="BeepControl">1</config>
</configuration>
-</VeraCrypt> \ No newline at end of file
+</VeraCrypt>
diff --git a/Library/VeraCryptLib/DcsVeraCrypt.c b/Library/VeraCryptLib/DcsVeraCrypt.c
index 5d9be88..c165d9f 100644
--- a/Library/VeraCryptLib/DcsVeraCrypt.c
+++ b/Library/VeraCryptLib/DcsVeraCrypt.c
@@ -81,13 +81,15 @@ UINT8 gForcePasswordProgress = 1;
CHAR8* gOnExitFailed = NULL;
CHAR8* gOnExitSuccess = NULL;
CHAR8* gOnExitNotFound = NULL;
+CHAR8* gOnExitTimeout = NULL;
+CHAR8* gOnExitCancelled = NULL;
//////////////////////////////////////////////////////////////////////////
// Authorize
/////////////////////////////////////////////////////////////////////////
#define VCCONFIG_ALLOC(data, size) \
- if(data == NULL) MEM_FREE(data); \
+ if(data != NULL) MEM_FREE(data); \
data = MEM_ALLOC(size);
VOID
@@ -147,7 +149,8 @@ VCAuthLoadConfig()
gPasswordProgress = (UINT8)ConfigReadInt("AuthorizeProgress", 1); // print "*"
gPasswordVisible = (UINT8)ConfigReadInt("AuthorizeVisible", 0); // show chars
gPasswordShowMark = ConfigReadInt("AuthorizeMarkTouch", 1); // show touch points
- gPasswordTimeout = (UINT8)ConfigReadInt("PasswordTimeout", 0); // If no password for <seconds> => <ESC>
+ gPasswordTimeout = (UINTN)ConfigReadInt("PasswordTimeout", 180); // If no password for <seconds> => <ESC>
+ gKeyboardInputDelay = (UINTN)ConfigReadInt("KeyboardInputDelay", 100); // minimum number of ms between two valid key strokes, anything between is discarded
gDcsBootForce = ConfigReadInt("DcsBootForce", 1); // Ask password even if no USB marked found.
@@ -181,12 +184,16 @@ VCAuthLoadConfig()
ConfigReadString("ActionNotFound", "Exit", gOnExitNotFound, MAX_MSG);
VCCONFIG_ALLOC(gOnExitFailed, MAX_MSG);
ConfigReadString("ActionFailed", "Exit", gOnExitFailed, MAX_MSG);
+ VCCONFIG_ALLOC(gOnExitTimeout, MAX_MSG);
+ ConfigReadString("ActionTimeout", "Shutdown", gOnExitTimeout, MAX_MSG);
+ VCCONFIG_ALLOC(gOnExitCancelled, MAX_MSG);
+ ConfigReadString("ActionCancelled", "Exit", gOnExitCancelled, MAX_MSG);
strTemp = MEM_ALLOC(MAX_MSG);
ConfigReadString("PartitionGuidOS", "", strTemp, MAX_MSG);
if (strTemp[0] != 0) {
EFI_GUID g;
- if (AsciiStrToGuid(&g, strTemp)) {
+ if (DcsAsciiStrToGuid(&g, strTemp)) {
VCCONFIG_ALLOC(gPartitionGuidOS, sizeof(EFI_GUID));
if (gPartitionGuidOS != NULL) {
memcpy(gPartitionGuidOS, &g, sizeof(g));
@@ -321,7 +328,7 @@ VCAskPwd(
ERR_PRINT(L"%r\n", res);
}
} while (gCfgMenuContinue);
- if (gAuthPwdCode == AskPwdRetCancel) {
+ if ((gAuthPwdCode == AskPwdRetCancel) || (gAuthPwdCode == AskPwdRetTimeout)) {
return;
}
}
@@ -331,7 +338,7 @@ VCAskPwd(
gAutoLogin = 0;
gAuthPwdCode = AskPwdRetLogin;
vcPwd->Length = (unsigned int)strlen(gAutoPassword);
- strcpy(vcPwd->Text, gAutoPassword);
+ AsciiStrCpyS(vcPwd->Text, sizeof(vcPwd->Text), gAutoPassword);
}
else {
if (gAuthPasswordType == 1 &&
@@ -355,7 +362,7 @@ VCAskPwd(
AskConsolePwdInt(&vcPwd->Length, vcPwd->Text, &gAuthPwdCode, sizeof(vcPwd->Text), gPasswordVisible);
}
- if (gAuthPwdCode == AskPwdRetCancel) {
+ if ((gAuthPwdCode == AskPwdRetCancel) || (gAuthPwdCode == AskPwdRetTimeout)) {
return;
}
}
@@ -394,9 +401,11 @@ VCAskPwd(
VOID
VCAuthAsk()
{
+ MEM_BURN(&gAuthPassword, sizeof(gAuthPassword));
VCAskPwd(AskPwdLogin, &gAuthPassword);
- if (gAuthPwdCode == AskPwdRetCancel) {
+ if ((gAuthPwdCode == AskPwdRetCancel) || (gAuthPwdCode == AskPwdRetTimeout)) {
+ MEM_BURN(&gAuthPassword, sizeof(gAuthPassword));
return;
}
@@ -414,7 +423,7 @@ VCAuthAsk()
if (gAuthHashRqt) {
do {
gAuthHash = AskInt(gAuthHashMsg, gPasswordVisible);
- } while (gAuthHash < 0 || gAuthHash > 4);
+ } while (gAuthHash < 0 || gAuthHash > 5);
}
}
diff --git a/Library/VeraCryptLib/DcsVeraCrypt.h b/Library/VeraCryptLib/DcsVeraCrypt.h
index f7a3c8f..1f25ae9 100644
--- a/Library/VeraCryptLib/DcsVeraCrypt.h
+++ b/Library/VeraCryptLib/DcsVeraCrypt.h
@@ -74,6 +74,8 @@ extern UINT8 gForcePasswordProgress;
extern CHAR8* gOnExitFailed;
extern CHAR8* gOnExitSuccess;
extern CHAR8* gOnExitNotFound;
+extern CHAR8* gOnExitTimeout;
+extern CHAR8* gOnExitCancelled;
void
VCAuthAsk();
diff --git a/Library/VeraCryptLib/VeraCryptLib.inf b/Library/VeraCryptLib/VeraCryptLib.inf
index 359782c..5006cfc 100644
--- a/Library/VeraCryptLib/VeraCryptLib.inf
+++ b/Library/VeraCryptLib/VeraCryptLib.inf
@@ -42,8 +42,11 @@ crypto\Aestab.h
crypto\Aes_hw_cpu.nasm
crypto\Aes_hw_cpu.h
crypto\config.h
-crypto\Rmd160.c
-crypto\Rmd160.h
+crypto\blake2s.c
+crypto\blake2s_SSE2.c
+crypto\blake2s_SSE41.c
+crypto\blake2s_SSSE3.c
+crypto\blake2.h
crypto\Serpent.c
crypto\Serpent.h
crypto\Sha2.c
@@ -52,8 +55,6 @@ crypto\Twofish.c
crypto\Twofish.h
crypto\Whirlpool.c
crypto\Whirlpool.h
-crypto\GostCipher.c
-crypto\GostCipher.h
crypto\Streebog.c
crypto\Streebog.h
crypto\kuznyechik.c
@@ -69,7 +70,6 @@ DcsVeraCrypt.h
[Sources.X64]
crypto\Aes_x64.nasm
-crypto\Gost89_x64.nasm
[Sources.IA32]
llmath.c
@@ -120,6 +120,10 @@ DEBUG_VS2015x86_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE
RELEASE_VS2015x86_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /D_UEFI
NOOPT_VS2015x86_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /D_UEFI
+DEBUG_VS2017_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /D_UEFI
+RELEASE_VS2017_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /D_UEFI
+NOOPT_VS2017_X64_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /D_UEFI
+
RELEASE_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
DEBUG_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
NOOPT_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
@@ -127,3 +131,7 @@ NOOPT_VS2010x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
RELEASE_VS2015x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
DEBUG_VS2015x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
NOOPT_VS2015x86_X64_NASM_FLAGS = -Xvc -d_UEFI=1
+
+RELEASE_VS2017_X64_NASM_FLAGS = -Xvc -d_UEFI=1
+DEBUG_VS2017_X64_NASM_FLAGS = -Xvc -d_UEFI=1
+NOOPT_VS2017_X64_NASM_FLAGS = -Xvc -d_UEFI=1
diff --git a/Library/VeraCryptLib/llmath.c b/Library/VeraCryptLib/llmath.c
index ad13758..2ea1bf9 100644
--- a/Library/VeraCryptLib/llmath.c
+++ b/Library/VeraCryptLib/llmath.c
@@ -1,237 +1,246 @@
-#include <uefi.h>
-void __cdecl atexit() {}
+/** @file
+64-bit Math Worker Function.
+The 32-bit versions of C compiler generate calls to library routines
+to handle 64-bit math. These functions use non-standard calling conventions.
+
+Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available
+under the terms and conditions of the BSD License which accompanies this
+distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-int __cdecl _purecall() { return 0; }
+**/
+
+#include <uefi.h>
+#include <Library/BaseLib.h>
#if defined(_M_IX86)
//////////////////////////////////////////////////////////////////////////
// _allmul
//////////////////////////////////////////////////////////////////////////
-__declspec(naked) void __cdecl _allmul(void)
+/*
+ * Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
+ * and returns a 64-bit result.
+ */
+__declspec(naked) void __cdecl _allmul (void)
{
- _asm {
- mov ebx, [esp + 4] ; ebx <- M1[0..31]
- mov edx, [esp + 12] ; edx <- M2[0..31]
- mov ecx, ebx
- mov eax, edx
- imul ebx, [esp + 16] ; ebx <- M1[0..31] * M2[32..63]
- imul edx, [esp + 8] ; edx <- M1[32..63] * M2[0..31]
- add ebx, edx ; carries are abandoned
- mul ecx ; edx:eax <- M1[0..31] * M2[0..31]
- add edx, ebx ; carries are abandoned
- ret 16
- }
-}
+ //
+ // Wrapper Implementation over EDKII MultS64x64() routine
+ // INT64
+ // EFIAPI
+ // MultS64x64 (
+ // IN INT64 Multiplicand,
+ // IN INT64 Multiplier
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _allmul
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |--Multiplier --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |--Multiplicand-|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
-//////////////////////////////////////////////////////////////////////////
-// _aullmul
-//////////////////////////////////////////////////////////////////////////
-__declspec(naked) void __cdecl _aullmul()
-{
- _asm {
- mov ebx, [esp + 4] ; ebx <- M1[0..31]
- mov edx, [esp + 12] ; edx <- M2[0..31]
- mov ecx, ebx
- mov eax, edx
- imul ebx, [esp + 16] ; ebx <- M1[0..31] * M2[32..63]
- imul edx, [esp + 8] ; edx <- M1[32..63] * M2[0..31]
- add ebx, edx ; carries are abandoned
- mul ecx ; edx:eax <- M1[0..31] * M2[0..31]
- add edx, ebx ; carries are abandoned
- ret 16
- }
-}
+ ;
+ ; Set up the local stack for Multiplicand parameter
+ ;
+ mov eax, [esp + 16]
+ push eax
+ mov eax, [esp + 16]
+ push eax
+
+ ;
+ ; Set up the local stack for Multiplier parameter
+ ;
+ mov eax, [esp + 16]
+ push eax
+ mov eax, [esp + 16]
+ push eax
+
+ ;
+ ; Call native MulS64x64 of BaseLib
+ ;
+ call MultS64x64
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 16
+
+ ret 16
+ }
+}
//////////////////////////////////////////////////////////////////////////
// _alldiv
//////////////////////////////////////////////////////////////////////////
-__declspec(naked) void __cdecl _alldiv()
+/*
+ * Divides a 64-bit signed value with a 64-bit signed value and returns
+ * a 64-bit signed result.
+ */
+__declspec(naked) void __cdecl _alldiv (void)
{
- _asm {
- ; Check sign of res
- mov ebx, [esp + 8] ; dividend msdw
- mov ecx, [esp + 16] ; divisor msdw
- xor ebx, ecx
- shr ebx, 31
- jz _PosRes ; if Result is positive
- push 1 ; if is negative
- jmp _Preparing
- _PosRes:
- push 0
-
- ; Preparing operands
- ; Dividend
- _Preparing:
- mov ecx, [esp + 12]
- shr ecx, 31
- jz _ChkDvsr ; Divident is positive
- mov eax, [esp + 12] ; is negative
- mov ecx, [esp + 8]
- xor eax, 0xFFFFFFFF
- xor ecx, 0xFFFFFFFF
- add ecx, 1
- jnc _DvntOK
- adc eax, 0
- _DvntOK:
- mov [esp + 12], eax
- mov [esp + 8], ecx
-
- ; Divisor
- _ChkDvsr:
- mov ecx, [esp + 20]
- shr ecx, 31
- jz _Divide ; Divisor is positive
- mov eax, [esp + 20] ; is negative
- mov ecx, [esp + 16]
- xor eax, 0xFFFFFFFF
- xor ecx, 0xFFFFFFFF
- add ecx, 1
- jnc _DvsrOK
- adc eax, 0
- _DvsrOK:
- mov [esp + 20], eax
- mov [esp + 16], ecx
-
- _Divide:
- mov ecx, [esp + 20] ; ecx <- divisor[32..63]
- test ecx, ecx
- jnz __DivRemU64x64 ; call __DivRemU64x64 if Divisor > 2^32
- mov ecx, [esp + 16] ; ecx <- divisor
- mov eax, [esp + 12] ; eax <- dividend[32..63]
- xor edx, edx
- div ecx ; eax <- quotient[32..63], edx <- remainder
- push eax
- mov eax, [esp + 12] ; eax <- dividend[0..31]
- div ecx ; eax <- quotient[0..31]
- pop edx ; edx <- quotient[32..63] - edx:eax
- jmp _GetSign
-
- __DivRemU64x64:
- mov edx, dword ptr [esp + 12]
- mov eax, dword ptr [esp + 8] ; edx:eax <- dividend
- mov edi, edx
- mov esi, eax ; edi:esi <- dividend
- mov ebx, dword ptr [esp + 16] ; ecx:ebx <- divisor
- _B:
- shr edx, 1
- rcr eax, 1
- shrd ebx, ecx, 1
- shr ecx, 1
- jnz _B
- div ebx
- mov ebx, eax ; ebx <- quotient
- mov ecx, [esp + 20] ; ecx <- high dword of divisor
- mul dword ptr [esp + 16] ; edx:eax <- quotient * divisor[0..31]
- imul ecx, ebx ; ecx <- quotient * divisor[32..63]
- add edx, ecx ; edx <- (quotient * divisor)[32..63]
- ;mov ecx, dword ptr [esp + 32] ; ecx <- addr for Remainder
- jc _TooLarge ; product > 2^64
- cmp edi, edx ; compare high 32 bits
- ja _Correct
- jb _TooLarge ; product > dividend
- cmp esi, eax
- jae _Correct ; product <= dividend
- _TooLarge:
- dec ebx ; adjust quotient by -1
- jecxz _Return ; return if Remainder == NULL
- sub eax, dword ptr [esp + 16]
- sbb edx, dword ptr [esp + 20] ; edx:eax <- (quotient - 1) * divisor
- _Correct:
- jecxz _Return
- sub esi, eax
- sbb edi, edx ; edi:esi <- remainder
- ;mov [ecx], esi
- ;mov [ecx + 4], edi
- _Return:
- mov eax, ebx ; eax <- quotient
- xor edx, edx ; quotient is 32 bits long
-
- ; Get sign of result
- _GetSign:
- pop ecx ; Sign of res
- jecxz _Rtrn ; Result is positive
- xor eax, 0xFFFFFFFF
- xor edx, 0xFFFFFFFF
- add eax, 1 ; edx:eax
- jnc _Rtrn
- adc edx, 0
-
- _Rtrn:
- ret 16
- }
+ //
+ // Wrapper Implementation over EDKII DivS64x64Remainder() routine
+ // INT64
+ // EFIAPI
+ // DivS64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder OPTIONAL
+ // )
+ //
+ _asm {
+
+ ;Entry:
+ ; Arguments are passed on the stack:
+ ; 1st pushed: divisor (QWORD)
+ ; 2nd pushed: dividend (QWORD)
+ ;
+ ;Exit:
+ ; EDX:EAX contains the quotient (dividend/divisor)
+ ; NOTE: this routine removes the parameters from the stack.
+ ;
+ ; Original local stack when calling _alldiv
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
+
+ ;
+ ; Set up the local stack for NULL Reminder pointer
+ ;
+ xor eax, eax
+ push eax
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Call native DivS64x64Remainder of BaseLib
+ ;
+ call DivS64x64Remainder
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 20
+
+ ret 16
+ }
}
//////////////////////////////////////////////////////////////////////////
// _aulldiv
//////////////////////////////////////////////////////////////////////////
-__declspec(naked) void __cdecl _aulldiv()
+/*
+ * Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
+ * a 64-bit unsigned result.
+ */
+__declspec(naked) void __cdecl _aulldiv (void)
{
- _asm {
- mov ecx, [esp + 16] ; ecx <- divisor[32..63]
- test ecx, ecx
- jnz __DivRemU64x64 ; call __DivRemU64x64 if Divisor > 2^32
- mov ecx, [esp + 12] ; ecx <- divisor
- mov eax, [esp + 8] ; eax <- dividend[32..63]
- xor edx, edx
- div ecx ; eax <- quotient[32..63], edx <- remainder
- push eax
- mov eax, [esp + 8] ; eax <- dividend[0..31]
- div ecx ; eax <- quotient[0..31]
- pop edx ; edx <- quotient[32..63]
- ret 16
-
- __DivRemU64x64:
- mov edx, dword ptr [esp + 8]
- mov eax, dword ptr [esp + 4] ; edx:eax <- dividend
- mov edi, edx
- mov esi, eax ; edi:esi <- dividend
- mov ebx, dword ptr [esp + 12] ; ecx:ebx <- divisor
- _B:
- shr edx, 1
- rcr eax, 1
- shrd ebx, ecx, 1
- shr ecx, 1
- jnz _B
- div ebx
- mov ebx, eax ; ebx <- quotient
- mov ecx, [esp + 16] ; ecx <- high dword of divisor
- mul dword ptr [esp + 12] ; edx:eax <- quotient * divisor[0..31]
- imul ecx, ebx ; ecx <- quotient * divisor[32..63]
- add edx, ecx ; edx <- (quotient * divisor)[32..63]
- ;mov ecx, dword ptr [esp + 32] ; ecx <- addr for Remainder
- jc _TooLarge ; product > 2^64
- cmp edi, edx ; compare high 32 bits
- ja _Correct
- jb _TooLarge ; product > dividend
- cmp esi, eax
- jae _Correct ; product <= dividend
- _TooLarge:
- dec ebx ; adjust quotient by -1
- jecxz _Return ; return if Remainder == NULL
- sub eax, dword ptr [esp + 12]
- sbb edx, dword ptr [esp + 16] ; edx:eax <- (quotient - 1) * divisor
- _Correct:
- jecxz _Return
- sub esi, eax
- sbb edi, edx ; edi:esi <- remainder
- ;mov [ecx], esi
- ;mov [ecx + 4], edi
- _Return:
- mov eax, ebx ; eax <- quotient
- xor edx, edx ; quotient is 32 bits long
-
- ret 16
- }
-}
+ //
+ // Wrapper Implementation over EDKII DivU64x64Reminder() routine
+ // UINT64
+ // EFIAPI
+ // DivU64x64Remainder (
+ // IN UINT64 Dividend,
+ // IN UINT64 Divisor,
+ // OUT UINT64 *Remainder OPTIONAL
+ // )
+ //
+ _asm {
+ ; Original local stack when calling _aulldiv
+ ; -----------------
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Divisor --|
+ ; | |
+ ; |---------------|
+ ; | |
+ ; |-- Dividend --|
+ ; | |
+ ; |---------------|
+ ; | ReturnAddr** |
+ ; ESP---->|---------------|
+ ;
-UINT64
-EFIAPI
-DivU64x64Remainder(
-IN UINT64 Dividend,
-IN UINT64 Divisor,
-OUT UINT64 *Remainder OPTIONAL
-);
+ ;
+ ; Set up the local stack for NULL Reminder pointer
+ ;
+ xor eax, eax
+ push eax
+
+ ;
+ ; Set up the local stack for Divisor parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Set up the local stack for Dividend parameter
+ ;
+ mov eax, [esp + 20]
+ push eax
+ mov eax, [esp + 20]
+ push eax
+
+ ;
+ ; Call native DivU64x64Remainder of BaseLib
+ ;
+ call DivU64x64Remainder
+
+ ;
+ ; Adjust stack
+ ;
+ add esp, 20
+
+ ret 16
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+// _aullrem
+//////////////////////////////////////////////////////////////////////////
/*
* Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
* the 64-bit unsigned remainder.
diff --git a/Library/VeraCryptLib/mklinks_src.bat b/Library/VeraCryptLib/mklinks_src.bat
index f87bc60..ca28f5b 100644
--- a/Library/VeraCryptLib/mklinks_src.bat
+++ b/Library/VeraCryptLib/mklinks_src.bat
@@ -41,9 +41,6 @@ call :create_link common\Xts.c
call :create_link common\Xts.h
if NOT EXIST crypto mkdir crypto
-call :create_link crypto\GostCipher.c
-call :create_link crypto\GostCipher.h
-call :create_link crypto\Gost89_x64.asm Gost89_x64.nasm
call :create_link crypto\Streebog.c
call :create_link crypto\Streebog.h
call :create_link crypto\kuznyechik.c
@@ -61,8 +58,15 @@ call :create_link crypto\cpu.h
call :create_link crypto\cpu.c
call :create_link crypto\config.h
call :create_link crypto\misc.h
-call :create_link crypto\Rmd160.c
-call :create_link crypto\Rmd160.h
+call :create_link crypto\blake2s.c
+call :create_link crypto\blake2.h
+call :create_link crypto\blake2-impl.h
+call :create_link crypto\blake2s_SSE2.c
+call :create_link crypto\blake2s_SSE41.c
+call :create_link crypto\blake2s_SSSE3.c
+call :create_link crypto\blake2s-load-sse2.h
+call :create_link crypto\blake2s-load-sse41.h
+call :create_link crypto\blake2s-round.h
call :create_link crypto\Serpent.c
call :create_link crypto\Serpent.h
call :create_link crypto\Sha2.c