VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Build/Include/Makefile.inc12
-rw-r--r--src/Common/Crypto.c28
-rw-r--r--src/Common/Dlgcode.c4
-rw-r--r--src/Common/Dlgcode.h2
-rw-r--r--src/Common/Random.c4
-rw-r--r--src/Common/Tests.c2
-rw-r--r--src/Crypto/Aes_hw_armv8.c316
-rw-r--r--src/Crypto/Aes_hw_cpu.h2
-rw-r--r--src/Crypto/Crypto.vcxproj4
-rw-r--r--src/Crypto/Crypto.vcxproj.filters15
-rw-r--r--src/Crypto/config.h39
-rw-r--r--src/Crypto/cpu.c38
-rw-r--r--src/Crypto/cpu.h18
-rw-r--r--src/Driver/Driver.vcxproj4
-rw-r--r--src/Driver/Driver.vcxproj.filters3
-rw-r--r--src/Driver/Ntdriver.c11
-rw-r--r--src/ExpandVolume/WinMain.cpp4
-rw-r--r--src/Format/Tcformat.c4
-rw-r--r--src/Main/UserInterface.cpp3
-rw-r--r--src/Makefile6
-rw-r--r--src/Mount/Mount.c4
-rw-r--r--src/Volume/Volume.make10
22 files changed, 488 insertions, 45 deletions
diff --git a/src/Build/Include/Makefile.inc b/src/Build/Include/Makefile.inc
index 0f68df36..281d206a 100644
--- a/src/Build/Include/Makefile.inc
+++ b/src/Build/Include/Makefile.inc
@@ -1,58 +1,62 @@
#
# Derived from source code of TrueCrypt 7.1a, which is
# Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
# by the TrueCrypt License 3.0.
#
# Modifications and additions to the original source code (contained in this file)
# and all other portions of this file are Copyright (c) 2013-2017 IDRIX
# and are governed by the Apache License 2.0 the full text of which is
# contained in the file License.txt included in VeraCrypt binary and source
# code distribution packages.
#
$(NAME): $(NAME).a
clean:
@echo Cleaning $(NAME)
- rm -f $(APPNAME) $(NAME).a $(OBJS) $(OBJSEX) $(OBJSNOOPT) $(OBJSHANI) $(OBJSSSE41) $(OBJSSSSE3) $(OBJS:.o=.d) $(OBJSEX:.oo=.d) $(OBJSNOOPT:.o0=.d) $(OBJSHANI:.oshani=.d) $(OBJSSSE41:.osse41=.d) $(OBJSSSSE3:.ossse3=.d) *.gch
+ rm -f $(APPNAME) $(NAME).a $(OBJS) $(OBJSEX) $(OBJSNOOPT) $(OBJSHANI) $(OBJSSSE41) $(OBJSSSSE3) $(OBJARMV8CRYPTO) $(OBJS:.o=.d) $(OBJSEX:.oo=.d) $(OBJSNOOPT:.o0=.d) $(OBJSHANI:.oshani=.d) $(OBJSSSE41:.osse41=.d) $(OBJSSSSE3:.ossse3=.d) $(OBJARMV8CRYPTO:.oarmv8crypto=.d) *.gch
%.o: %.c
@echo Compiling $(<F)
$(CC) $(CFLAGS) -c $< -o $@
%.o0: %.c
@echo Compiling $(<F)
$(CC) $(CFLAGS) -O0 -c $< -o $@
%.osse41: %.c
@echo Compiling $(<F)
$(CC) $(CFLAGS) -mssse3 -msse4.1 -c $< -o $@
%.oshani: %.c
@echo Compiling $(<F)
$(CC) $(CFLAGS) -mssse3 -msse4.1 -msha -c $< -o $@
%.ossse3: %.c
@echo Compiling $(<F)
$(CC) $(CFLAGS) -mssse3 -c $< -o $@
+%.oarmv8crypto: %.c
+ @echo Compiling $(<F)
+ $(CC) $(CFLAGS) -march=armv8-a+crypto -c $< -o $@
+
%.o: %.cpp
@echo Compiling $(<F)
$(CXX) $(CXXFLAGS) -c $< -o $@
%.osse41: %.cpp
@echo Compiling $(<F)
$(CXX) $(CXXFLAGS) -mssse3 -msse4.1 -c $< -o $@
%.oshani: %.cpp
@echo Compiling $(<F)
$(CXX) $(CXXFLAGS) -mssse3 -msse4.1 -msha -c $< -o $@
%.ossse3: %.cpp
@echo Compiling $(<F)
$(CXX) $(CXXFLAGS) -mssse3 -c $< -o $@
%.o: %.S
@echo Compiling $(<F)
$(CC) $(CFLAGS) -c $< -o $@
@@ -79,27 +83,27 @@ ifeq "$(PLATFORM)" "OpenBSD"
OD_BIN := ggod -v -t u1 -A n
else
OD_BIN := od -v -t u1 -A n
endif
TR_SED_BIN := tr '\n' ' ' | tr -s ' ' ',' | sed -e 's/^,//g' -e 's/,$$/n/' | tr 'n' '\n'
%.xml.h: %.xml
@echo Converting $(<F)
$(OD_BIN) $< | $(TR_SED_BIN) >$@
%.txt.h: %.txt
@echo Converting $(<F)
$(OD_BIN) $< | $(TR_SED_BIN) >$@
%.bmp.h: %.bmp
@echo Converting $(<F)
$(OD_BIN) $< | $(TR_SED_BIN) >$@
# Dependencies
--include $(OBJS:.o=.d) $(OBJSEX:.oo=.d) $(OBJSNOOPT:.o0=.d) $(OBJSHANI:.oshani=.d) $(OBJSSSE41:.osse41=.d) $(OBJSSSSE3:.ossse3=.d)
+-include $(OBJS:.o=.d) $(OBJSEX:.oo=.d) $(OBJSNOOPT:.o0=.d) $(OBJSHANI:.oshani=.d) $(OBJSSSE41:.osse41=.d) $(OBJSSSSE3:.ossse3=.d) $(OBJARMV8CRYPTO:.oarmv8crypto=.d)
-$(NAME).a: $(OBJS) $(OBJSEX) $(OBJSNOOPT) $(OBJSHANI) $(OBJSSSE41) $(OBJSSSSE3)
+$(NAME).a: $(OBJS) $(OBJSEX) $(OBJSNOOPT) $(OBJSHANI) $(OBJSSSE41) $(OBJSSSSE3) $(OBJARMV8CRYPTO)
@echo Updating library $@
- $(AR) $(AFLAGS) -rc $@ $(OBJS) $(OBJSEX) $(OBJSNOOPT) $(OBJSHANI) $(OBJSSSE41) $(OBJSSSSE3)
+ $(AR) $(AFLAGS) -rc $@ $(OBJS) $(OBJSEX) $(OBJSNOOPT) $(OBJSHANI) $(OBJSSSE41) $(OBJSSSSE3) $(OBJARMV8CRYPTO)
$(RANLIB) $@
diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c
index 32ef4b56..2f4e447f 100644
--- a/src/Common/Crypto.c
+++ b/src/Common/Crypto.c
@@ -1147,42 +1147,40 @@ void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo,
#endif // TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
#if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES)
static BOOL HwEncryptionDisabled = FALSE;
BOOL IsAesHwCpuSupported ()
{
#ifdef TC_WINDOWS_BOOT_AES
static BOOL state = FALSE;
static BOOL stateValid = FALSE;
if (!stateValid)
{
state = is_aes_hw_cpu_supported() ? TRUE : FALSE;
stateValid = TRUE;
}
return state && !HwEncryptionDisabled;
-#elif defined (_M_ARM64) || defined(__arm__) || defined (__arm64__) || defined (__aarch64__)
- return 0;
#else
return (HasAESNI() && !HwEncryptionDisabled)? TRUE : FALSE;
#endif
}
void EnableHwEncryption (BOOL enable)
{
#if defined (TC_WINDOWS_BOOT)
if (enable)
aes_hw_cpu_enable_sse();
#endif
HwEncryptionDisabled = !enable;
}
BOOL IsHwEncryptionEnabled ()
{
return !HwEncryptionDisabled;
}
@@ -1466,46 +1464,20 @@ static void VcInternalProtectKeys (PCRYPTO_INFO pCryptoInfo, uint64 encID)
}
void VcProtectKeys (PCRYPTO_INFO pCryptoInfo, uint64 encID)
{
Dump ("VcProtectKeys BEGIN\n");
VcInternalProtectKeys (pCryptoInfo, encID);
Dump ("VcProtectKeys END\n");
}
void VcUnprotectKeys (PCRYPTO_INFO pCryptoInfo, uint64 encID)
{
Dump ("VcUnprotectKeys BEGIN\n");
VcInternalProtectKeys (pCryptoInfo, encID);
Dump ("VcUnprotectKeys END\n");
}
#endif
#endif
-#if defined(_M_ARM64) || defined(__arm__) || defined (__arm64__) || defined (__aarch64__)
-/* dummy implementation that should never be called */
-void aes_hw_cpu_decrypt(const uint8* ks, uint8* data)
-{
- ks = ks;
- data = data;
-}
-
-void aes_hw_cpu_decrypt_32_blocks(const uint8* ks, uint8* data)
-{
- ks = ks;
- data = data;
-}
-
-void aes_hw_cpu_encrypt(const uint8* ks, uint8* data)
-{
- ks = ks;
- data = data;
-}
-
-void aes_hw_cpu_encrypt_32_blocks(const uint8* ks, uint8* data)
-{
- ks = ks;
- data = data;
-}
-#endif
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 045def76..e471fc46 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -1029,41 +1029,41 @@ BOOL IsOSVersionAtLeast (OSVersionEnum reqMinOS, int reqMinServicePack)
switch (reqMinOS)
{
case WIN_2000: major = 5; minor = 0; break;
case WIN_XP: major = 5; minor = 1; break;
case WIN_SERVER_2003: major = 5; minor = 2; break;
case WIN_VISTA: major = 6; minor = 0; break;
case WIN_7: major = 6; minor = 1; break;
case WIN_8: major = 6; minor = 2; break;
case WIN_8_1: major = 6; minor = 3; break;
case WIN_10: major = 10; minor = 0; break;
default:
TC_THROW_FATAL_EXCEPTION;
break;
}
return ((CurrentOSMajor << 16 | CurrentOSMinor << 8 | CurrentOSServicePack)
>= (major << 16 | minor << 8 | reqMinServicePack));
}
-BOOL IsWin10BuildAtLeast(DWORD minBuild)
+BOOL IsWin10BuildAtLeast(int minBuild)
{
// Must first be recognized as Windows 10 or higher
if (nCurrentOS < WIN_10)
return FALSE;
// If we’re on Windows 10, check build number
if (nCurrentOS == WIN_10 && CurrentOSBuildNumber < minBuild)
return FALSE;
// If we are on a higher version of Windows, we are good to go
return TRUE;
}
#ifdef SETUP_DLL
static BOOL GetWindowVersionFromFile(DWORD* pdwMajor, DWORD* pdwMinor, DWORD* pdwBuildNumber)
{
wchar_t dllPath[MAX_PATH];
BOOL bRet = FALSE;
LPBYTE versionInfo = NULL;
UINT size;
@@ -14866,48 +14866,50 @@ void GetAppRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed)
if (QueryPerformanceFrequency (&iSeed))
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
/* use Windows random generator as entropy source */
if (RtlGenRandom (digest, sizeof (digest)))
WHIRLPOOL_add (digest, sizeof(digest), &tctx);
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
if (0 == jent_entropy_init ())
{
struct rand_data *ec = jent_entropy_collector_alloc (1, 0);
if (ec)
{
ssize_t rndLen = jent_read_entropy (ec, (char*) digest, sizeof (digest));
if (rndLen > 0)
WHIRLPOOL_add (digest, (unsigned int) rndLen, &tctx);
jent_entropy_collector_free (ec);
}
}
+#ifndef _M_ARM64
// use RDSEED or RDRAND from CPU as source of entropy if enabled
if ( IsCpuRngEnabled() &&
( (HasRDSEED() && RDSEED_getBytes (digest, sizeof (digest)))
|| (HasRDRAND() && RDRAND_getBytes (digest, sizeof (digest)))
))
{
WHIRLPOOL_add (digest, sizeof(digest), &tctx);
}
+#endif
WHIRLPOOL_finalize (&tctx, digest);
count = VC_MIN (cbRandSeed, sizeof (digest));
// copy digest value to seed buffer
memcpy (pbRandSeed, digest, count);
cbRandSeed -= count;
pbRandSeed += count;
}
FAST_ERASE64 (digest, sizeof (digest));
FAST_ERASE64 (&iSeed.QuadPart, 8);
burn (&sysTime, sizeof(sysTime));
burn (&tctx, sizeof(tctx));
}
#endif
/*
* GetBitLockerEncryptionStatus: retuns the BitLocker encryption status of a given drive.
*/
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index 8148bd09..aaaad97e 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -486,41 +486,41 @@ int AskWarnNoYesTopmost (char *stringId, HWND hwnd);
int AskWarnOkCancel (char *stringId, HWND hwnd);
int AskWarnCancelOk (char *stringId, HWND hwnd);
int AskErrYesNo (char *stringId, HWND hwnd);
int AskErrNoYes (char *stringId, HWND hwnd);
int AskMultiChoice (void *strings[], BOOL bBold, HWND hwnd);
BOOL ConfigWriteBegin ();
BOOL ConfigWriteEnd (HWND hwnd);
BOOL ConfigWriteString (char *configKey, char *configValue);
BOOL ConfigWriteStringW (char *configKey, wchar_t *configValue);
BOOL ConfigWriteInt (char *configKey, int configValue);
int ConfigReadInt (char *configKey, int defaultValue);
char *ConfigReadString (char *configKey, char *defaultValue, char *str, int maxLen);
void ConfigReadCompareInt(char *configKey, int defaultValue, int* pOutputValue, BOOL bOnlyCheckModified, BOOL* pbModified);
void ConfigReadCompareString (char *configKey, char *defaultValue, char *str, int maxLen, BOOL bOnlyCheckModified, BOOL *pbModified);
void RestoreDefaultKeyFilesParam (void);
BOOL LoadDefaultKeyFilesParam (void);
void Debug (char *format, ...);
void DebugMsgBox (char *format, ...);
BOOL IsOSAtLeast (OSVersionEnum reqMinOS);
BOOL IsOSVersionAtLeast (OSVersionEnum reqMinOS, int reqMinServicePack);
-BOOL IsWin10BuildAtLeast(DWORD minBuild);
+BOOL IsWin10BuildAtLeast(int minBuild);
BOOL IsSupportedOS ();
BOOL Is64BitOs ();
BOOL IsARM();
BOOL IsServerOS ();
BOOL IsHiddenOSRunning (void);
BOOL EnableWow64FsRedirection (BOOL enable);
BOOL RestartComputer (BOOL bShutdown);
void Applink (const char *dest);
wchar_t *RelativePath2Absolute (wchar_t *szFileName);
void HandleDriveNotReadyError (HWND hwnd);
BOOL CALLBACK CloseTCWindowsEnum( HWND hwnd, LPARAM lParam);
BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam);
BYTE *MapResource (wchar_t *resourceType, int resourceId, PDWORD size);
void InconsistencyResolved (char *msg);
void ReportUnexpectedState (const char *techInfo);
void OpenOnlineHelp ();
BOOL GetPartitionInfo (const wchar_t *deviceName, PPARTITION_INFORMATION rpartInfo);
BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info);
BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY_EX diskGeometry);
BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY diskGeometry);
diff --git a/src/Common/Random.c b/src/Common/Random.c
index 0aab0cff..10995f74 100644
--- a/src/Common/Random.c
+++ b/src/Common/Random.c
@@ -861,48 +861,50 @@ BOOL SlowPoll (void)
else
{
/* return error in case BCryptGenRandom fails */
CryptoAPILastError = pRtlNtStatusToDosError (bStatus);
return FALSE;
}
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
if (0 == jent_entropy_init ())
{
struct rand_data *ec = jent_entropy_collector_alloc (1, 0);
if (ec)
{
ssize_t rndLen = jent_read_entropy (ec, (char*) buffer, sizeof (buffer));
if (rndLen > 0)
RandaddBuf (buffer, (int) rndLen);
jent_entropy_collector_free (ec);
}
}
+#ifndef _M_ARM64
// use RDSEED or RDRAND from CPU as source of entropy if present
if ( IsCpuRngEnabled() &&
( (HasRDSEED() && RDSEED_getBytes (buffer, sizeof (buffer)))
|| (HasRDRAND() && RDRAND_getBytes (buffer, sizeof (buffer)))
))
{
RandaddBuf (buffer, sizeof (buffer));
}
+#endif
burn(buffer, sizeof (buffer));
/* Mix the pool */
Randmix();
return TRUE;
}
/* This is the fastpoll function which gathers up info by calling various api's */
BOOL FastPoll (void)
{
int nOriginalRandIndex = nRandIndex;
static BOOL addedFixedItems = FALSE;
FILETIME creationTime, exitTime, kernelTime, userTime;
SIZE_T minimumWorkingSetSize, maximumWorkingSetSize;
LARGE_INTEGER performanceCount;
MEMORYSTATUSEX memoryStatus;
HANDLE handle;
@@ -994,45 +996,47 @@ BOOL FastPoll (void)
else
{
/* Millisecond accuracy at best... */
DWORD dwTicks = GetTickCount ();
RandaddBuf ((unsigned char *) &dwTicks, sizeof (dwTicks));
}
bStatus = BCryptGenRandom(NULL, buffer, sizeof(buffer), BCRYPT_USE_SYSTEM_PREFERRED_RNG);
if (NT_SUCCESS(bStatus))
{
RandaddBuf (buffer, sizeof (buffer));
}
else
{
/* return error in case BCryptGenRandom fails */
CryptoAPILastError = pRtlNtStatusToDosError (bStatus);
return FALSE;
}
+#ifndef _M_ARM64
// use RDSEED or RDRAND from CPU as source of entropy if enabled
if ( IsCpuRngEnabled() &&
( (HasRDSEED() && RDSEED_getBytes (buffer, sizeof (buffer)))
|| (HasRDRAND() && RDRAND_getBytes (buffer, sizeof (buffer)))
))
{
RandaddBuf (buffer, sizeof (buffer));
}
+#endif
burn (buffer, sizeof(buffer));
/* Apply the pool mixing function */
Randmix();
/* Restore the original pool cursor position. If this wasn't done, mouse coordinates
could be written to a limited area of the pool, especially when moving the mouse
uninterruptedly. The severity of the problem would depend on the length of data
written by FastPoll (if it was equal to the size of the pool, mouse coordinates
would be written only to a particular 4-byte area, whenever moving the mouse
uninterruptedly). */
nRandIndex = nOriginalRandIndex;
return TRUE;
}
diff --git a/src/Common/Tests.c b/src/Common/Tests.c
index f6a9183d..89af24f1 100644
--- a/src/Common/Tests.c
+++ b/src/Common/Tests.c
@@ -1473,41 +1473,43 @@ BOOL AutoTestAlgorithms (void)
if (!DoAutoTestAlgorithms())
result = FALSE;
EnableHwEncryption (TRUE);
if (!DoAutoTestAlgorithms())
result = FALSE;
EnableHwEncryption (hwEncryptionEnabled);
#if defined (_MSC_VER) && !defined (_UEFI)
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
exceptionCatched = TRUE;
}
if (exceptionCatched)
{
/* unexepected exception raised. Disable all CPU extended feature and try again */
EnableHwEncryption (hwEncryptionEnabled);
+#ifndef _M_ARM64
DisableCPUExtendedFeatures ();
+#endif
__try
{
result = DoAutoTestAlgorithms();
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
/* exception still occuring. Report failure. */
result = FALSE;
}
}
#endif
return result;
}
BOOL test_hmac_sha256 ()
{
unsigned int i;
int nTestsPerformed = 0;
for (i = 0; i < sizeof (hmac_sha256_test_data) / sizeof(char *); i++)
diff --git a/src/Crypto/Aes_hw_armv8.c b/src/Crypto/Aes_hw_armv8.c
new file mode 100644
index 00000000..b67ed1a5
--- /dev/null
+++ b/src/Crypto/Aes_hw_armv8.c
@@ -0,0 +1,316 @@
+/*
+* AES using ARMv8
+* Contributed by Jeffrey Walton
+*
+* Further changes
+* (C) 2017,2018 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+/* Modified and adapted for VeraCrypt */
+
+#include "Common/Tcdefs.h"
+#include "Aes_hw_cpu.h"
+#if !defined(_UEFI)
+#include <memory.h>
+#include <stdlib.h>
+#endif
+#include "cpu.h"
+#include "misc.h"
+
+#if CRYPTOPP_ARM_AES_AVAILABLE
+
+#include <arm_neon.h>
+
+// Single block encryption operations
+VC_INLINE void aes_enc_block(uint8x16_t* B, uint8x16_t K)
+{
+ *B = vaesmcq_u8(vaeseq_u8(*B, K));
+}
+
+VC_INLINE void aes_enc_block_last(uint8x16_t* B, uint8x16_t K, uint8x16_t K2)
+{
+ *B = veorq_u8(vaeseq_u8(*B, K), K2);
+}
+
+// 4-block parallel encryption operations
+VC_INLINE void aes_enc_4_blocks(uint8x16_t* B0, uint8x16_t* B1,
+ uint8x16_t* B2, uint8x16_t* B3, uint8x16_t K)
+{
+ *B0 = vaesmcq_u8(vaeseq_u8(*B0, K));
+ *B1 = vaesmcq_u8(vaeseq_u8(*B1, K));
+ *B2 = vaesmcq_u8(vaeseq_u8(*B2, K));
+ *B3 = vaesmcq_u8(vaeseq_u8(*B3, K));
+}
+
+VC_INLINE void aes_enc_4_blocks_last(uint8x16_t* B0, uint8x16_t* B1,
+ uint8x16_t* B2, uint8x16_t* B3,
+ uint8x16_t K, uint8x16_t K2)
+{
+ *B0 = veorq_u8(vaeseq_u8(*B0, K), K2);
+ *B1 = veorq_u8(vaeseq_u8(*B1, K), K2);
+ *B2 = veorq_u8(vaeseq_u8(*B2, K), K2);
+ *B3 = veorq_u8(vaeseq_u8(*B3, K), K2);
+}
+
+// Single block decryption operations
+VC_INLINE void aes_dec_block(uint8x16_t* B, uint8x16_t K)
+{
+ *B = vaesimcq_u8(vaesdq_u8(*B, K));
+}
+
+VC_INLINE void aes_dec_block_last(uint8x16_t* B, uint8x16_t K, uint8x16_t K2)
+{
+ *B = veorq_u8(vaesdq_u8(*B, K), K2);
+}
+
+// 4-block parallel decryption operations
+VC_INLINE void aes_dec_4_blocks(uint8x16_t* B0, uint8x16_t* B1,
+ uint8x16_t* B2, uint8x16_t* B3, uint8x16_t K)
+{
+ *B0 = vaesimcq_u8(vaesdq_u8(*B0, K));
+ *B1 = vaesimcq_u8(vaesdq_u8(*B1, K));
+ *B2 = vaesimcq_u8(vaesdq_u8(*B2, K));
+ *B3 = vaesimcq_u8(vaesdq_u8(*B3, K));
+}
+
+VC_INLINE void aes_dec_4_blocks_last(uint8x16_t* B0, uint8x16_t* B1,
+ uint8x16_t* B2, uint8x16_t* B3,
+ uint8x16_t K, uint8x16_t K2)
+{
+ *B0 = veorq_u8(vaesdq_u8(*B0, K), K2);
+ *B1 = veorq_u8(vaesdq_u8(*B1, K), K2);
+ *B2 = veorq_u8(vaesdq_u8(*B2, K), K2);
+ *B3 = veorq_u8(vaesdq_u8(*B3, K), K2);
+}
+
+VC_INLINE void aes256_hw_encrypt_blocks(uint8 buffer[], size_t blocks, const uint8* ks)
+{
+ const uint8x16_t K0 = vld1q_u8(ks + 0 * 16);
+ const uint8x16_t K1 = vld1q_u8(ks + 1 * 16);
+ const uint8x16_t K2 = vld1q_u8(ks + 2 * 16);
+ const uint8x16_t K3 = vld1q_u8(ks + 3 * 16);
+ const uint8x16_t K4 = vld1q_u8(ks + 4 * 16);
+ const uint8x16_t K5 = vld1q_u8(ks + 5 * 16);
+ const uint8x16_t K6 = vld1q_u8(ks + 6 * 16);
+ const uint8x16_t K7 = vld1q_u8(ks + 7 * 16);
+ const uint8x16_t K8 = vld1q_u8(ks + 8 * 16);
+ const uint8x16_t K9 = vld1q_u8(ks + 9 * 16);
+ const uint8x16_t K10 = vld1q_u8(ks + 10 * 16);
+ const uint8x16_t K11 = vld1q_u8(ks + 11 * 16);
+ const uint8x16_t K12 = vld1q_u8(ks + 12 * 16);
+ const uint8x16_t K13 = vld1q_u8(ks + 13 * 16);
+ const uint8x16_t K14 = vld1q_u8(ks + 14 * 16);
+
+ while(blocks >= 4) {
+ uint8x16_t B0 = vld1q_u8(buffer);
+ uint8x16_t B1 = vld1q_u8(buffer + 16);
+ uint8x16_t B2 = vld1q_u8(buffer + 32);
+ uint8x16_t B3 = vld1q_u8(buffer + 48);
+
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K0);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K1);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K2);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K3);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K4);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K5);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K6);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K7);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K8);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K9);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K10);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K11);
+ aes_enc_4_blocks(&B0, &B1, &B2, &B3, K12);
+ aes_enc_4_blocks_last(&B0, &B1, &B2, &B3, K13, K14);
+
+ vst1q_u8(buffer, B0);
+ vst1q_u8(buffer + 16, B1);
+ vst1q_u8(buffer + 32, B2);
+ vst1q_u8(buffer + 48, B3);
+
+ buffer += 16 * 4;
+ blocks -= 4;
+ }
+
+ for(size_t i = 0; i != blocks; ++i) {
+ uint8x16_t B = vld1q_u8(buffer + 16 * i);
+ aes_enc_block(&B, K0);
+ aes_enc_block(&B, K1);
+ aes_enc_block(&B, K2);
+ aes_enc_block(&B, K3);
+ aes_enc_block(&B, K4);
+ aes_enc_block(&B, K5);
+ aes_enc_block(&B, K6);
+ aes_enc_block(&B, K7);
+ aes_enc_block(&B, K8);
+ aes_enc_block(&B, K9);
+ aes_enc_block(&B, K10);
+ aes_enc_block(&B, K11);
+ aes_enc_block(&B, K12);
+ aes_enc_block_last(&B, K13, K14);
+ vst1q_u8(buffer + 16 * i, B);
+ }
+}
+
+VC_INLINE void aes256_hw_encrypt_block(uint8 buffer[], const uint8* ks)
+{
+ const uint8x16_t K0 = vld1q_u8(ks + 0 * 16);
+ const uint8x16_t K1 = vld1q_u8(ks + 1 * 16);
+ const uint8x16_t K2 = vld1q_u8(ks + 2 * 16);
+ const uint8x16_t K3 = vld1q_u8(ks + 3 * 16);
+ const uint8x16_t K4 = vld1q_u8(ks + 4 * 16);
+ const uint8x16_t K5 = vld1q_u8(ks + 5 * 16);
+ const uint8x16_t K6 = vld1q_u8(ks + 6 * 16);
+ const uint8x16_t K7 = vld1q_u8(ks + 7 * 16);
+ const uint8x16_t K8 = vld1q_u8(ks + 8 * 16);
+ const uint8x16_t K9 = vld1q_u8(ks + 9 * 16);
+ const uint8x16_t K10 = vld1q_u8(ks + 10 * 16);
+ const uint8x16_t K11 = vld1q_u8(ks + 11 * 16);
+ const uint8x16_t K12 = vld1q_u8(ks + 12 * 16);
+ const uint8x16_t K13 = vld1q_u8(ks + 13 * 16);
+ const uint8x16_t K14 = vld1q_u8(ks + 14 * 16);
+
+ uint8x16_t B = vld1q_u8(buffer);
+ aes_enc_block(&B, K0);
+ aes_enc_block(&B, K1);
+ aes_enc_block(&B, K2);
+ aes_enc_block(&B, K3);
+ aes_enc_block(&B, K4);
+ aes_enc_block(&B, K5);
+ aes_enc_block(&B, K6);
+ aes_enc_block(&B, K7);
+ aes_enc_block(&B, K8);
+ aes_enc_block(&B, K9);
+ aes_enc_block(&B, K10);
+ aes_enc_block(&B, K11);
+ aes_enc_block(&B, K12);
+ aes_enc_block_last(&B, K13, K14);
+ vst1q_u8(buffer, B);
+}
+
+VC_INLINE void aes256_hw_decrypt_blocks(uint8 buffer[], size_t blocks, const uint8* ks)
+{
+ const uint8x16_t K0 = vld1q_u8(ks + 0 * 16);
+ const uint8x16_t K1 = vld1q_u8(ks + 1 * 16);
+ const uint8x16_t K2 = vld1q_u8(ks + 2 * 16);
+ const uint8x16_t K3 = vld1q_u8(ks + 3 * 16);
+ const uint8x16_t K4 = vld1q_u8(ks + 4 * 16);
+ const uint8x16_t K5 = vld1q_u8(ks + 5 * 16);
+ const uint8x16_t K6 = vld1q_u8(ks + 6 * 16);
+ const uint8x16_t K7 = vld1q_u8(ks + 7 * 16);
+ const uint8x16_t K8 = vld1q_u8(ks + 8 * 16);
+ const uint8x16_t K9 = vld1q_u8(ks + 9 * 16);
+ const uint8x16_t K10 = vld1q_u8(ks + 10 * 16);
+ const uint8x16_t K11 = vld1q_u8(ks + 11 * 16);
+ const uint8x16_t K12 = vld1q_u8(ks + 12 * 16);
+ const uint8x16_t K13 = vld1q_u8(ks + 13 * 16);
+ const uint8x16_t K14 = vld1q_u8(ks + 14 * 16);
+
+ while(blocks >= 4) {
+ uint8x16_t B0 = vld1q_u8(buffer);
+ uint8x16_t B1 = vld1q_u8(buffer + 16);
+ uint8x16_t B2 = vld1q_u8(buffer + 32);
+ uint8x16_t B3 = vld1q_u8(buffer + 48);
+
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K0);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K1);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K2);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K3);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K4);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K5);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K6);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K7);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K8);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K9);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K10);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K11);
+ aes_dec_4_blocks(&B0, &B1, &B2, &B3, K12);
+ aes_dec_4_blocks_last(&B0, &B1, &B2, &B3, K13, K14);
+
+ vst1q_u8(buffer, B0);
+ vst1q_u8(buffer + 16, B1);
+ vst1q_u8(buffer + 32, B2);
+ vst1q_u8(buffer + 48, B3);
+
+ buffer += 16 * 4;
+ blocks -= 4;
+ }
+
+ for(size_t i = 0; i != blocks; ++i) {
+ uint8x16_t B = vld1q_u8(buffer + 16 * i);
+ aes_dec_block(&B, K0);
+ aes_dec_block(&B, K1);
+ aes_dec_block(&B, K2);
+ aes_dec_block(&B, K3);
+ aes_dec_block(&B, K4);
+ aes_dec_block(&B, K5);
+ aes_dec_block(&B, K6);
+ aes_dec_block(&B, K7);
+ aes_dec_block(&B, K8);
+ aes_dec_block(&B, K9);
+ aes_dec_block(&B, K10);
+ aes_dec_block(&B, K11);
+ aes_dec_block(&B, K12);
+ aes_dec_block_last(&B, K13, K14);
+ vst1q_u8(buffer + 16 * i, B);
+ }
+}
+
+VC_INLINE void aes256_hw_decrypt_block(uint8 buffer[], const uint8* ks)
+{
+ const uint8x16_t K0 = vld1q_u8(ks + 0 * 16);
+ const uint8x16_t K1 = vld1q_u8(ks + 1 * 16);
+ const uint8x16_t K2 = vld1q_u8(ks + 2 * 16);
+ const uint8x16_t K3 = vld1q_u8(ks + 3 * 16);
+ const uint8x16_t K4 = vld1q_u8(ks + 4 * 16);
+ const uint8x16_t K5 = vld1q_u8(ks + 5 * 16);
+ const uint8x16_t K6 = vld1q_u8(ks + 6 * 16);
+ const uint8x16_t K7 = vld1q_u8(ks + 7 * 16);
+ const uint8x16_t K8 = vld1q_u8(ks + 8 * 16);
+ const uint8x16_t K9 = vld1q_u8(ks + 9 * 16);
+ const uint8x16_t K10 = vld1q_u8(ks + 10 * 16);
+ const uint8x16_t K11 = vld1q_u8(ks + 11 * 16);
+ const uint8x16_t K12 = vld1q_u8(ks + 12 * 16);
+ const uint8x16_t K13 = vld1q_u8(ks + 13 * 16);
+ const uint8x16_t K14 = vld1q_u8(ks + 14 * 16);
+
+ uint8x16_t B = vld1q_u8(buffer);
+ aes_dec_block(&B, K0);
+ aes_dec_block(&B, K1);
+ aes_dec_block(&B, K2);
+ aes_dec_block(&B, K3);
+ aes_dec_block(&B, K4);
+ aes_dec_block(&B, K5);
+ aes_dec_block(&B, K6);
+ aes_dec_block(&B, K7);
+ aes_dec_block(&B, K8);
+ aes_dec_block(&B, K9);
+ aes_dec_block(&B, K10);
+ aes_dec_block(&B, K11);
+ aes_dec_block(&B, K12);
+ aes_dec_block_last(&B, K13, K14);
+ vst1q_u8(buffer, B);
+}
+
+void aes_hw_cpu_decrypt (const uint8 *ks, uint8 *data)
+{
+ aes256_hw_decrypt_block(data, ks);
+}
+
+void aes_hw_cpu_decrypt_32_blocks (const uint8 *ks, uint8 *data)
+{
+ aes256_hw_decrypt_blocks(data, 32, ks);
+}
+
+void aes_hw_cpu_encrypt (const uint8 *ks, uint8 *data)
+{
+ aes256_hw_encrypt_block(data, ks);
+}
+
+void aes_hw_cpu_encrypt_32_blocks (const uint8 *ks, uint8 *data)
+{
+ aes256_hw_encrypt_blocks(data, 32, ks);
+}
+
+#endif
diff --git a/src/Crypto/Aes_hw_cpu.h b/src/Crypto/Aes_hw_cpu.h
index 685a1dff..d9dda1af 100644
--- a/src/Crypto/Aes_hw_cpu.h
+++ b/src/Crypto/Aes_hw_cpu.h
@@ -5,32 +5,32 @@
Modifications and additions to the original source code (contained in this file)
and all other portions of this file are Copyright (c) 2013-2025 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
#ifndef TC_HEADER_Crypto_Aes_Hw_Cpu
#define TC_HEADER_Crypto_Aes_Hw_Cpu
#include "Common/Tcdefs.h"
#if defined(__cplusplus)
extern "C"
{
#endif
#if defined (TC_WINDOWS_BOOT)
uint8 is_aes_hw_cpu_supported ();
-#endif
void aes_hw_cpu_enable_sse ();
+#endif
void aes_hw_cpu_decrypt (const uint8 *ks, uint8 *data);
void VC_CDECL aes_hw_cpu_decrypt_32_blocks (const uint8 *ks, uint8 *data);
void aes_hw_cpu_encrypt (const uint8 *ks, uint8 *data);
void VC_CDECL aes_hw_cpu_encrypt_32_blocks (const uint8 *ks, uint8 *data);
#if defined(__cplusplus)
}
#endif
#endif // TC_HEADER_Crypto_Aes_Hw_Cpu
diff --git a/src/Crypto/Crypto.vcxproj b/src/Crypto/Crypto.vcxproj
index 4aebc084..c17bd607 100644
--- a/src/Crypto/Crypto.vcxproj
+++ b/src/Crypto/Crypto.vcxproj
@@ -209,40 +209,44 @@
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(TargetDir)\%(Filename).obj;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(TargetDir)\%(Filename).obj;%(Outputs)</Outputs>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">echo %(Filename)%(Extension) &amp; nasm.exe -Xvc -f win32 -Ox --prefix _ -o "$(TargetDir)\%(Filename).obj" -l "$(TargetDir)\%(Filename).lst" "%(FullPath)"
</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">echo %(Filename)%(Extension) &amp; nasm.exe -Xvc -f win32 -Ox --prefix _ -o "$(TargetDir)\%(Filename).obj" -l "$(TargetDir)\%(Filename).lst" "%(FullPath)"
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(TargetDir)\%(Filename).obj;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(TargetDir)\%(Filename).obj;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Aescrypt.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="Aeskey.c" />
<ClCompile Include="Aestab.c" />
+ <ClCompile Include="Aes_hw_armv8.c">
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+ </ClCompile>
<ClCompile Include="blake2s.c" />
<ClCompile Include="blake2s_SSE2.c" />
<ClCompile Include="blake2s_SSE41.c" />
<ClCompile Include="blake2s_SSSE3.c" />
<ClCompile Include="Camellia.c" />
<ClCompile Include="chacha-xmm.c" />
<ClCompile Include="chacha256.c" />
<ClCompile Include="chachaRng.c" />
<ClCompile Include="cpu.c" />
<ClCompile Include="jitterentropy-base.c">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Disabled</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Disabled</Optimization>
</ClCompile>
<ClCompile Include="kuznyechik.c" />
<ClCompile Include="kuznyechik_simd.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="rdrand.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
diff --git a/src/Crypto/Crypto.vcxproj.filters b/src/Crypto/Crypto.vcxproj.filters
index 3d384f97..f2b1b54d 100644
--- a/src/Crypto/Crypto.vcxproj.filters
+++ b/src/Crypto/Crypto.vcxproj.filters
@@ -73,40 +73,46 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="t1ha2_selfcheck.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="blake2s.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="blake2s_SSE2.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="blake2s_SSE41.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="blake2s_SSSE3.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Sha2Intel.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Aescrypt.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Aes_hw_armv8.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Aes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Aes_hw_cpu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Aesopt.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Aestab.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Camellia.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="config.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -150,49 +156,40 @@
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="chachaRng.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="jitterentropy.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="jitterentropy-base-user.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="t1ha.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="t1ha_bits.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="t1ha_selfcheck.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="blake2s-load-sse2.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="blake2s-load-sse41.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="blake2s-round.h">
- <Filter>Header Files</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="Aes_hw_cpu.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="Aes_x64.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="Aes_x86.asm">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="Twofish_x64.S">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="Camellia_x64.S">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="Camellia_aesni_x64.S">
<Filter>Source Files</Filter>
</CustomBuild>
diff --git a/src/Crypto/config.h b/src/Crypto/config.h
index 1c2aff72..dd8e3f06 100644
--- a/src/Crypto/config.h
+++ b/src/Crypto/config.h
@@ -12,40 +12,45 @@
// Clang pretends to be VC++, too.
// See http://github.com/weidai11/cryptopp/issues/147
#if defined(_MSC_VER) && defined(__clang__) && !defined(_DCSPKG_ANALYZE)
# error: "Unsupported configuration"
#endif
#ifdef __GNUC__
#define CRYPTOPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
// Apple and LLVM's Clang. Apple Clang version 7.0 roughly equals LLVM Clang version 3.7
#if defined(__clang__ ) && !defined(__apple_build_version__) && !defined(_DCSPKG_ANALYZE)
#define CRYPTOPP_LLVM_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1
#elif defined(__clang__ ) && defined(__apple_build_version__) && !defined(_DCSPKG_ANALYZE)
#define CRYPTOPP_APPLE_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1
#endif
+#if defined(_MSC_VER) && !defined(__clang__)
+# undef CRYPTOPP_LLVM_CLANG_VERSION
+# define CRYPTOPP_MSC_VERSION (_MSC_VER)
+#endif
+
// Clang due to "Inline assembly operands don't work with .intel_syntax", http://llvm.org/bugs/show_bug.cgi?id=24232
// TODO: supply the upper version when LLVM fixes it. We set it to 20.0 for compilation purposes.
#if (defined(CRYPTOPP_LLVM_CLANG_VERSION) && CRYPTOPP_LLVM_CLANG_VERSION <= 200000) || (defined(CRYPTOPP_APPLE_CLANG_VERSION) && CRYPTOPP_APPLE_CLANG_VERSION <= 200000) || defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER)
#define CRYPTOPP_DISABLE_INTEL_ASM 1
#endif
#ifndef CRYPTOPP_L1_CACHE_LINE_SIZE
// This should be a lower bound on the L1 cache line size. It's used for defense against timing attacks.
// Also see http://stackoverflow.com/questions/794632/programmatically-get-the-cache-line-size.
#if defined(_M_X64) || defined(__x86_64__) || (__ILP32__ >= 1)
#define CRYPTOPP_L1_CACHE_LINE_SIZE 64
#else
// L1 cache line size is 32 on Pentium III and earlier
#define CRYPTOPP_L1_CACHE_LINE_SIZE 32
#endif
#endif
#if defined(_MSC_VER) && (_MSC_VER > 1200)
#define CRYPTOPP_MSVC6PP_OR_LATER
#endif
@@ -184,40 +189,74 @@
// the System V ABI specs calls out, like on just about any 32-bit system with Clang.
#if ((__ILP32__ >= 1) || (_ILP32 >= 1)) && defined(__x86_64__)
#define CRYPTOPP_BOOL_X32 1
#else
#define CRYPTOPP_BOOL_X32 0
#endif
// see http://predef.sourceforge.net/prearch.html
#if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__)) && !CRYPTOPP_BOOL_X32
#define CRYPTOPP_BOOL_X86 1
#else
#define CRYPTOPP_BOOL_X86 0
#endif
#if (defined(_M_X64) || defined(__x86_64__)) && !CRYPTOPP_BOOL_X32
#define CRYPTOPP_BOOL_X64 1
#else
#define CRYPTOPP_BOOL_X64 0
#endif
+#if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
+ #define CRYPTOPP_BOOL_ARMV8 1
+ #define CRYPTOPP_BOOL_ARM64 1
+#else
+ #define CRYPTOPP_BOOL_ARMV8 0
+ #define CRYPTOPP_BOOL_ARM64 0
+#endif
+
+// ARMv8 and ASIMD. -march=armv8-a or above must be present
+// Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
+// Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
+#if !defined(CRYPTOPP_ARM_ASIMD_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_ASIMD)
+# if defined(__aarch32__) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
+# if defined(__ARM_NEON) || defined(__ARM_ASIMD) || defined(__ARM_FEATURE_NEON) || defined(__ARM_FEATURE_ASIMD) || \
+ (CRYPTOPP_GCC_VERSION >= 40800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || \
+ (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || (CRYPTOPP_MSC_VERSION >= 1916)
+# define CRYPTOPP_ARM_NEON_AVAILABLE 1
+# define CRYPTOPP_ARM_ASIMD_AVAILABLE 1
+# endif // Compilers
+# endif // Platforms
+#endif
+
+// ARMv8 and AES. -march=armv8-a+crypto or above must be present
+// Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
+#if !defined(CRYPTOPP_ARM_AES_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_AES)
+# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
+# if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
+ (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300) || \
+ (CRYPTOPP_MSC_VERSION >= 1916)
+# define CRYPTOPP_ARM_AES_AVAILABLE 1
+# endif // Compilers
+# endif // Platforms
+#endif
+
// Undo the ASM and Intrinsic related defines due to X32.
#if CRYPTOPP_BOOL_X32
# undef CRYPTOPP_BOOL_X64
# undef CRYPTOPP_X64_ASM_AVAILABLE
# undef CRYPTOPP_X64_MASM_AVAILABLE
#endif
#if !defined(CRYPTOPP_NO_UNALIGNED_DATA_ACCESS) && !defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS)
#if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || defined(__powerpc__) || (__ARM_FEATURE_UNALIGNED >= 1))
#define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
#endif
#endif
// this version of the macro is fastest on Pentium 3 and Pentium 4 with MSVC 6 SP5 w/ Processor Pack
#define GETBYTE(x, y) (unsigned int)((unsigned char)((x)>>(8*(y))))
// these may be faster on other CPUs/compilers
// #define GETBYTE(x, y) (unsigned int)(((x)>>(8*(y)))&255)
// #define GETBYTE(x, y) (((uint8 *)&(x))[y])
#define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) ((uint8)((x)>>(8*(y))))
diff --git a/src/Crypto/cpu.c b/src/Crypto/cpu.c
index e611e9bb..85278a92 100644
--- a/src/Crypto/cpu.c
+++ b/src/Crypto/cpu.c
@@ -452,20 +452,58 @@ void DisableCPUExtendedFeatures ()
{
g_hasSSE2 = 0;
g_hasISSE = 0;
g_hasMMX = 0;
g_hasSSE2 = 0;
g_hasISSE = 0;
g_hasMMX = 0;
g_hasAVX = 0;
g_hasAVX2 = 0;
g_hasBMI2 = 0;
g_hasSSE42 = 0;
g_hasSSE41 = 0;
g_hasSSSE3 = 0;
g_hasAESNI = 0;
g_hasCLMUL = 0;
g_hasSHA256 = 0;
}
#endif
+#if CRYPTOPP_BOOL_ARMV8
+
+volatile int g_hasAESARM = 0;
+
+#ifndef HWCAP_AES
+# define HWCAP_AES (1 << 3)
+#endif
+
+inline int CPU_QueryAES()
+{
+#if defined(CRYPTOPP_ARM_AES_AVAILABLE)
+#if defined(__linux__) && defined(__aarch64__)
+ if ((getauxval(AT_HWCAP) & HWCAP_AES) != 0)
+ return 1;
+#elif defined(__APPLE__) && defined(__aarch64__)
+ // Apple Sillcon (M1) and later
+ return 1;
+#elif defined(_WIN32) && defined(_M_ARM64)
+#ifdef TC_WINDOWS_DRIVER
+ if (ExIsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0)
+ return 1;
+#else
+ if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0)
+ return 1;
+#endif
+#endif
+ return 0;
+#else
+ return 0;
+#endif
+}
+
+void DetectArmFeatures()
+{
+ g_hasAESARM = CPU_QueryAES();
+}
+
+#endif \ No newline at end of file
diff --git a/src/Crypto/cpu.h b/src/Crypto/cpu.h
index b0df6462..761258f2 100644
--- a/src/Crypto/cpu.h
+++ b/src/Crypto/cpu.h
@@ -271,40 +271,58 @@ void DisableCPUExtendedFeatures ();
#define HasSSE42() g_hasSSE42
#define HasSSE41() g_hasSSE41
#define HasSAVX() g_hasAVX
#define HasSAVX2() g_hasAVX2
#define HasSBMI2() g_hasBMI2
#define HasSSSE3() g_hasSSSE3
#define HasAESNI() g_hasAESNI
#define HasCLMUL() g_hasCLMUL
#define IsP4() g_isP4
#define HasRDRAND() g_hasRDRAND
#define HasRDSEED() g_hasRDSEED
#define HasSHA256() g_hasSHA256
#define IsCpuIntel() g_isIntel
#define IsCpuAMD() g_isAMD
#define GetCacheLineSize() g_cacheLineSize
#if defined(__cplusplus)
}
#endif
+#elif CRYPTOPP_BOOL_ARMV8
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#if !defined(CRYPTOPP_DISABLE_AESNI) && !defined(WOLFCRYPT_BACKEND)
+#define TC_AES_HW_CPU
+#endif
+
+extern volatile int g_hasAESARM;
+void DetectArmFeatures();
+
+#define HasAESNI() g_hasAESARM
+
+#if defined(__cplusplus)
+}
+#endif
+
#else
#define HasSSE2() 0
#define HasISSE() 0
#define HasMMX() 0
#define HasSSE42() 0
#define HasSSE41() 0
#define HasSAVX() 0
#define HasSAVX2() 0
#define HasSBMI2() 0
#define HasSSSE3() 0
#define HasAESNI() 0
#define HasCLMUL() 0
#define IsP4() 0
#define HasRDRAND() 0
#define HasRDSEED() 0
#define IsCpuIntel() 0
#define IsCpuAMD() 0
#define GetCacheLineSize() CRYPTOPP_L1_CACHE_LINE_SIZE
diff --git a/src/Driver/Driver.vcxproj b/src/Driver/Driver.vcxproj
index aa920225..628e24a4 100644
--- a/src/Driver/Driver.vcxproj
+++ b/src/Driver/Driver.vcxproj
@@ -211,40 +211,44 @@ copy $(OutDir)veracrypt.inf "$(SolutionDir)Debug\Setup Files\veracrypt.inf"</Com
<FilesToPackage Include="$(TargetPath)" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Common\Cache.c" />
<ClCompile Include="..\Common\Crc.c" />
<ClCompile Include="..\Common\Crypto.c" />
<ClCompile Include="..\Common\EncryptionThreadPool.c" />
<ClCompile Include="..\Common\Endian.c" />
<ClCompile Include="..\Common\GfMul.c" />
<ClCompile Include="..\Common\Pkcs5.c" />
<ClCompile Include="..\Common\Tests.c" />
<ClCompile Include="..\Common\Volumes.c" />
<ClCompile Include="..\Common\Wipe.c" />
<ClCompile Include="..\Common\Xts.c" />
<ClCompile Include="..\Crypto\Aescrypt.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Crypto\Aeskey.c" />
<ClCompile Include="..\Crypto\Aestab.c" />
+ <ClCompile Include="..\Crypto\Aes_hw_armv8.c">
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+ </ClCompile>
<ClCompile Include="..\Crypto\blake2s.c" />
<ClCompile Include="..\Crypto\blake2s_SSE2.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Crypto\blake2s_SSE41.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Crypto\blake2s_SSSE3.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Crypto\Camellia.c" />
<ClCompile Include="..\Crypto\chacha-xmm.c" />
<ClCompile Include="..\Crypto\chacha256.c" />
<ClCompile Include="..\Crypto\chachaRng.c" />
<ClCompile Include="..\Crypto\cpu.c" />
<ClCompile Include="..\Crypto\jitterentropy-base.c" />
<ClCompile Include="..\Crypto\kuznyechik.c" />
diff --git a/src/Driver/Driver.vcxproj.filters b/src/Driver/Driver.vcxproj.filters
index 478432fa..6f43b0e8 100644
--- a/src/Driver/Driver.vcxproj.filters
+++ b/src/Driver/Driver.vcxproj.filters
@@ -148,40 +148,43 @@
<Filter>Crypto\Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Driver\DriveFilter.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Driver\DumpFilter.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Driver\EncryptedIoQueue.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Driver\Ntdriver.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Driver\Ntvol.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Driver\VolumeFilter.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Crypto\Aes_hw_armv8.c">
+ <Filter>Crypto\Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Common\Tcdefs.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Crypto\Aes.h">
<Filter>Crypto\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\Crypto\Aesopt.h">
<Filter>Crypto\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\Crypto\AesSmall.h">
<Filter>Crypto\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\Crypto\Aestab.h">
<Filter>Crypto\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\Crypto\Aes_hw_cpu.h">
<Filter>Crypto\Header Files</Filter>
</ClInclude>
diff --git a/src/Driver/Ntdriver.c b/src/Driver/Ntdriver.c
index ab208019..6d218517 100644
--- a/src/Driver/Ntdriver.c
+++ b/src/Driver/Ntdriver.c
@@ -215,102 +215,111 @@ void GetDriverRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed)
iSeed = KeQueryPerformanceCounter (&iSeed2);
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
iSeed.QuadPart = KeQueryInterruptTimePrecise ((PULONG64) & iSeed2.QuadPart);
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
if (0 == jent_entropy_init ())
{
struct rand_data *ec = jent_entropy_collector_alloc (1, 0);
if (ec)
{
ssize_t rndLen = jent_read_entropy (ec, (char*) digest, sizeof (digest));
if (rndLen > 0)
WHIRLPOOL_add (digest, (unsigned int) rndLen, &tctx);
jent_entropy_collector_free (ec);
}
}
-
+#ifndef _M_ARM64
// use RDSEED or RDRAND from CPU as source of entropy if enabled
if ( IsCpuRngEnabled() &&
( (HasRDSEED() && RDSEED_getBytes (digest, sizeof (digest)))
|| (HasRDRAND() && RDRAND_getBytes (digest, sizeof (digest)))
))
{
WHIRLPOOL_add (digest, sizeof(digest), &tctx);
}
+#endif
WHIRLPOOL_finalize (&tctx, digest);
count = VC_MIN (cbRandSeed, sizeof (digest));
// copy digest value to seed buffer
memcpy (pbRandSeed, digest, count);
cbRandSeed -= count;
pbRandSeed += count;
}
FAST_ERASE64 (digest, sizeof (digest));
FAST_ERASE64 (&iSeed.QuadPart, 8);
FAST_ERASE64 (&iSeed2.QuadPart, 8);
burn (&tctx, sizeof(tctx));
}
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
PKEY_VALUE_PARTIAL_INFORMATION startKeyValue;
LONG version;
int i;
Dump("DriverEntry " TC_APP_NAME " " VERSION_STRING VERSION_STRING_SUFFIX "\n");
+#ifndef _M_ARM64
DetectX86Features();
+#else
+ DetectArmFeatures();
+#endif
PsGetVersion(&OsMajorVersion, &OsMinorVersion, NULL, NULL);
Dump("OsMajorVersion=%d OsMinorVersion=%d\n", OsMajorVersion, OsMinorVersion);
// Load dump filter if the main driver is already loaded
if (NT_SUCCESS(TCDeviceIoControl(NT_ROOT_PREFIX, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &version, sizeof(version))))
return DumpFilterEntry((PFILTER_EXTENSION)DriverObject, (PFILTER_INITIALIZATION_DATA)RegistryPath);
TCDriverObject = DriverObject;
memset(VirtualVolumeDeviceObjects, 0, sizeof(VirtualVolumeDeviceObjects));
ReadRegistryConfigFlags(TRUE);
EncryptionThreadPoolStart(EncryptionThreadPoolFreeCpuCountLimit);
SelfTestsPassed = AutoTestAlgorithms();
// Enable device class filters and load boot arguments if the driver is set to start at system boot
if (NT_SUCCESS(TCReadRegistryKey(RegistryPath, L"Start", &startKeyValue)))
{
if (startKeyValue->Type == REG_DWORD && *((uint32*)startKeyValue->Data) == SERVICE_BOOT_START)
{
if (!SelfTestsPassed)
{
// in case of system encryption, if self-tests fail, disable all extended CPU
// features and try again in order to workaround faulty configurations
+#ifndef _M_ARM64
DisableCPUExtendedFeatures();
+#else
+ EnableHwEncryption(FALSE);
+#endif
SelfTestsPassed = AutoTestAlgorithms();
// BUG CHECK if the self-tests still fail
if (!SelfTestsPassed)
TC_BUG_CHECK(STATUS_INVALID_PARAMETER);
}
LoadBootArguments(IsUefiBoot());
VolumeClassFilterRegistered = IsVolumeClassFilterRegistered();
DriverObject->DriverExtension->AddDevice = DriverAddDevice;
}
TCfree(startKeyValue);
}
if (RamEncryptionActivated)
{
if (t1ha_selfcheck__t1ha2() != 0)
diff --git a/src/ExpandVolume/WinMain.cpp b/src/ExpandVolume/WinMain.cpp
index b7a14662..64fccd55 100644
--- a/src/ExpandVolume/WinMain.cpp
+++ b/src/ExpandVolume/WinMain.cpp
@@ -1076,40 +1076,44 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpszCommandLine, int nCmdShow)
{
int status;
atexit (VeraCryptExpander::localcleanup);
SetProcessShutdownParameters (0x100, 0);
VirtualLock (&VeraCryptExpander::VolumePassword, sizeof (VeraCryptExpander::VolumePassword));
VirtualLock (&VeraCryptExpander::CmdVolumePassword, sizeof (VeraCryptExpander::CmdVolumePassword));
VirtualLock (&VeraCryptExpander::mountOptions, sizeof (VeraCryptExpander::mountOptions));
VirtualLock (&VeraCryptExpander::defaultMountOptions, sizeof (VeraCryptExpander::defaultMountOptions));
VirtualLock (&VeraCryptExpander::szFileName, sizeof(VeraCryptExpander::szFileName));
InitApp (hInstance, lpszCommandLine);
/* application title */
lpszTitle = L"VeraCrypt Expander";
+#ifndef _M_ARM64
DetectX86Features();
+#else
+ DetectArmFeatures();
+#endif
status = DriverAttach ();
if (status != 0)
{
if (status == ERR_OS_ERROR)
handleWin32Error (NULL, SRC_POS);
else
handleError (NULL, status, SRC_POS);
AbortProcess ("NODRIVER");
}
/* Create the main dialog box */
DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) VeraCryptExpander::MainDialogProc,
(LPARAM) lpszCommandLine);
/* Terminate */
return 0;
}
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c
index 3c2422a5..4afeb174 100644
--- a/src/Format/Tcformat.c
+++ b/src/Format/Tcformat.c
@@ -10571,41 +10571,45 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz
VirtualLock (&outerVolumePassword, sizeof(outerVolumePassword));
VirtualLock (szVerify, sizeof(szVerify));
VirtualLock (szRawPassword, sizeof(szRawPassword));
VirtualLock (&volumePim, sizeof(volumePim));
VirtualLock (&outerVolumePim, sizeof(outerVolumePim));
VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
VirtualLock (MasterKeyGUIView, sizeof(MasterKeyGUIView));
VirtualLock (HeaderKeyGUIView, sizeof(HeaderKeyGUIView));
VirtualLock (randPool, sizeof(randPool));
VirtualLock (lastRandPool, sizeof(lastRandPool));
VirtualLock (outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer));
VirtualLock (&mouseEntropyGathered, sizeof(mouseEntropyGathered));
VirtualLock (&mouseEventsInitialCount, sizeof(mouseEventsInitialCount));
VirtualLock (maskRandPool, sizeof(maskRandPool));
VirtualLock (&szFileName, sizeof(szFileName));
VirtualLock (&szDiskFile, sizeof(szDiskFile));
+#ifndef _M_ARM64
DetectX86Features();
+#else
+ DetectArmFeatures();
+#endif
try
{
BootEncObj = new BootEncryption (NULL);
}
catch (Exception &e)
{
e.Show (NULL);
}
if (BootEncObj == NULL)
AbortProcess ("INIT_SYS_ENC");
InitApp (hInstance, lpszCommandLine);
#if TC_MAX_VOLUME_SECTOR_SIZE > 64 * 1024
#error TC_MAX_VOLUME_SECTOR_SIZE > 64 * 1024
#endif
nPbar = IDC_PROGRESS_BAR;
diff --git a/src/Main/UserInterface.cpp b/src/Main/UserInterface.cpp
index 8da77f5b..5f82db49 100644
--- a/src/Main/UserInterface.cpp
+++ b/src/Main/UserInterface.cpp
@@ -539,40 +539,43 @@ namespace VeraCrypt
#ifdef TC_MACOSX
EX2MSG (HigherFuseVersionRequired, LangString["LINUX_EX2MSG_HIGHERFUSEVERSIONREQUIRED"]);
#endif
EX2MSG (MountPointBlocked, LangString["MOUNTPOINT_BLOCKED"]);
EX2MSG (MountPointNotAllowed, LangString["MOUNTPOINT_NOTALLOWED"]);
#undef EX2MSG
return L"";
}
void UserInterface::Init ()
{
SetAppName (Application::GetName());
SetClassName (Application::GetName());
#ifdef CRYPTOPP_CPUID_AVAILABLE
DetectX86Features ();
#endif
+#if CRYPTOPP_BOOL_ARMV8
+ DetectArmFeatures();
+#endif
LangString.Init();
Core->Init();
CmdLine.reset (new CommandLineInterface (argc, argv, InterfaceType));
SetPreferences (CmdLine->Preferences);
Core->SetApplicationExecutablePath (Application::GetExecutablePath());
Core->SetUserEnvPATH (getenv ("PATH"));
if (!Preferences.NonInteractive)
{
Core->SetAdminPasswordCallback (GetAdminPasswordRequestHandler());
}
else
{
Core->SetAdminPasswordCallback (shared_ptr <GetStringFunctor> (new AdminPasswordRequestHandler));
}
Core->ForceUseDummySudoPassword (CmdLine->ArgUseDummySudoPassword);
diff --git a/src/Makefile b/src/Makefile
index b176975e..4f282e5a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -145,40 +145,43 @@ export CPU_ARCH ?= unknown
export SIMD_SUPPORTED := 0
export DISABLE_AESNI ?= 0
export ENABLE_WOLFCRYPT ?= 0
export GCC_GTEQ_440 := 0
export GCC_GTEQ_430 := 0
export GCC_GTEQ_500 := 0
export GTK_VERSION := 0
ARCH ?= $(shell uname -m)
ifneq (,$(filter i386 i486 i586 i686 x86,$(ARCH)))
CPU_ARCH = x86
ASFLAGS += -f elf32 -D __BITS__=32
else ifneq (,$(filter x86_64 x86-64 amd64 x64,$(ARCH)))
CPU_ARCH = x64
ASFLAGS += -f elf64 -D __BITS__=64
else ifneq (,$(filter armv7l,$(ARCH)))
PLATFORM_ARCH := armv7
CPU_ARCH = armv7
+else ifneq (,$(filter aarch64 arm64 armv8l,$(ARCH)))
+ PLATFORM_ARCH := arm64
+ CPU_ARCH = arm64
endif
ifeq "$(origin NOASM)" "command line"
CPU_ARCH = unknown
C_CXX_FLAGS += -DCRYPTOPP_DISABLE_X86ASM
endif
ifeq "$(CPU_ARCH)" "x86"
PLATFORM_ARCH := i386
SIMD_SUPPORTED := 1
C_CXX_FLAGS += -D TC_ARCH_X86
else ifeq "$(CPU_ARCH)" "x64"
PLATFORM_ARCH := amd64
SIMD_SUPPORTED := 1
C_CXX_FLAGS += -D TC_ARCH_X64
endif
ifeq "$(origin NOSSE2)" "command line"
SIMD_SUPPORTED := 0
endif
@@ -321,40 +324,43 @@ $(error Specified SDK version was not found, ensure your active developer direct
GCC_GTEQ_500 := 1
CXXFLAGS += -std=c++11
C_CXX_FLAGS += -DTC_UNIX -DTC_BSD -DTC_MACOSX -mmacosx-version-min=$(VC_OSX_TARGET) -isysroot $(VC_OSX_SDK_PATH)
LFLAGS += -mmacosx-version-min=$(VC_OSX_TARGET) -Wl,-syslibroot $(VC_OSX_SDK_PATH) -Wl,-export_dynamic
# Xcode 15 linker emits a warning "no platform load command found" when linking object files generated by yasm
# To suppress this warning, we need to use -Wl,-ld_classic flag in order to use the old ld64 linker
# https://mjtsai.com/blog/2024/03/15/xcode-15-no-platform-load-command-found/
# We can check whether newer linker is in use if ld -v reports dyld instead of ld64.
ifeq ($(shell xcrun --sdk macosx$(VC_OSX_SDK) ld -v 2>&1 | grep -oE 'PROJECT:[^-]+' | cut -d: -f2),dyld)
LFLAGS += -Wl,-ld_classic
endif
WX_CONFIGURE_FLAGS += --with-macosx-version-min=$(VC_OSX_TARGET) --with-macosx-sdk=$(VC_OSX_SDK_PATH)
ifneq "$(VC_OSX_FUSET)" "0"
C_CXX_FLAGS += -DVC_MACOSX_FUSET
VC_FUSE_PACKAGE := fuse-t
endif
+ export CFLAGS_ARM64 := $(CFLAGS) $(C_CXX_FLAGS) -arch arm64 -march=armv8-a+crypto
+ export CFLAGS_X64 := $(CFLAGS) $(C_CXX_FLAGS) -arch x86_64
+
# Set x86 assembly flags (-msse2, -mssse3, -msse4.1)
# Apply flags if SIMD_SUPPORTED is 1 or if not in local development build (we are creating universal binary in this case)
ifneq "$(LOCAL_DEVELOPMENT_BUILD)" "true"
SIMD_SUPPORTED = 1
endif
ifeq "$(SIMD_SUPPORTED)" "1"
CFLAGS += -msse2
CXXFLAGS += -msse2
ifeq "$(origin SSSE3)" "command line"
CFLAGS += -mssse3
CXXFLAGS += -mssse3
endif
ifeq "$(origin SSE41)" "command line"
CFLAGS += -mssse3 -msse4.1
CXXFLAGS += -mssse3 -msse4.1
endif
endif
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index c90e2bb3..f543f371 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -10115,41 +10115,45 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpsz
BootEncryption bootEnc (NULL, true);
bootEnc.InstallBootLoader (true);
}
catch (...)
{
}
return 0;
}
int status;
atexit (localcleanup);
SetProcessShutdownParameters (0x100, 0);
DeobfuscateMagEndMarker ();
VirtualLock (&VolumePassword, sizeof (VolumePassword));
VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
VirtualLock (&mountOptions, sizeof (mountOptions));
VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
VirtualLock (&szFileName, sizeof(szFileName));
+#ifndef _M_ARM64
DetectX86Features();
+#else
+ DetectArmFeatures();
+#endif
try
{
BootEncObj = new BootEncryption (NULL);
}
catch (Exception &e)
{
e.Show (NULL);
}
if (BootEncObj == NULL)
AbortProcess ("INIT_SYS_ENC");
InitApp (hInstance, lpszCommandLine);
RegisterRedTick(hInstance);
/* Allocate, dup, then store away the application title */
lpszTitle = L"VeraCrypt";
diff --git a/src/Volume/Volume.make b/src/Volume/Volume.make
index 52d212eb..e38542bb 100644
--- a/src/Volume/Volume.make
+++ b/src/Volume/Volume.make
@@ -26,75 +26,79 @@ OBJS += Keyfile.o
OBJS += Pkcs5Kdf.o
OBJS += Volume.o
OBJS += VolumeException.o
OBJS += VolumeHeader.o
OBJS += VolumeInfo.o
OBJS += VolumeLayout.o
OBJS += VolumePassword.o
OBJS += VolumePasswordCache.o
ifeq "$(ENABLE_WOLFCRYPT)" "0"
OBJS += EncryptionModeXTS.o
else
OBJS += EncryptionModeWolfCryptXTS.o
endif
ifeq "$(ENABLE_WOLFCRYPT)" "0"
ifeq "$(PLATFORM)" "MacOSX"
ifneq "$(COMPILE_ASM)" "false"
OBJSEX += ../Crypto/Aes_asm.oo
OBJS += ../Crypto/Aes_hw_cpu.o
+ OBJSEX += ../Crypto/Aes_hw_armv8.oo
OBJS += ../Crypto/Aescrypt.o
OBJSEX += ../Crypto/Twofish_asm.oo
OBJSEX += ../Crypto/Camellia_asm.oo
OBJSEX += ../Crypto/Camellia_aesni_asm.oo
OBJSEX += ../Crypto/sha256-nayuki.oo
OBJSEX += ../Crypto/sha512-nayuki.oo
OBJSEX += ../Crypto/sha256_avx1.oo
OBJSEX += ../Crypto/sha256_avx2.oo
OBJSEX += ../Crypto/sha256_sse4.oo
OBJSEX += ../Crypto/sha512_avx1.oo
OBJSEX += ../Crypto/sha512_avx2.oo
OBJSEX += ../Crypto/sha512_sse4.oo
endif
else ifeq "$(CPU_ARCH)" "x86"
OBJS += ../Crypto/Aes_x86.o
ifeq "$(DISABLE_AESNI)" "0"
OBJS += ../Crypto/Aes_hw_cpu.o
endif
OBJS += ../Crypto/sha256-x86-nayuki.o
OBJS += ../Crypto/sha512-x86-nayuki.o
else ifeq "$(CPU_ARCH)" "x64"
OBJS += ../Crypto/Aes_x64.o
ifeq "$(DISABLE_AESNI)" "0"
OBJS += ../Crypto/Aes_hw_cpu.o
endif
OBJS += ../Crypto/Twofish_x64.o
OBJS += ../Crypto/Camellia_x64.o
OBJS += ../Crypto/Camellia_aesni_x64.o
OBJS += ../Crypto/sha512-x64-nayuki.o
OBJS += ../Crypto/sha256_avx1_x64.o
OBJS += ../Crypto/sha256_avx2_x64.o
OBJS += ../Crypto/sha256_sse4_x64.o
OBJS += ../Crypto/sha512_avx1_x64.o
OBJS += ../Crypto/sha512_avx2_x64.o
OBJS += ../Crypto/sha512_sse4_x64.o
+else ifeq "$(CPU_ARCH)" "arm64"
+ OBJARMV8CRYPTO += ../Crypto/Aes_hw_armv8.oarmv8crypto
+ OBJS += ../Crypto/Aescrypt.o
else
OBJS += ../Crypto/Aescrypt.o
endif
ifeq "$(GCC_GTEQ_430)" "1"
OBJSSSE41 += ../Crypto/blake2s_SSE41.osse41
OBJSSSSE3 += ../Crypto/blake2s_SSSE3.ossse3
else
OBJS += ../Crypto/blake2s_SSE41.o
OBJS += ../Crypto/blake2s_SSSE3.o
endif
ifeq "$(GCC_GTEQ_500)" "1"
OBJSHANI += ../Crypto/Sha2Intel.oshani
else
OBJS += ../Crypto/Sha2Intel.o
endif
else
OBJS += ../Crypto/wolfCrypt.o
endif
@@ -123,40 +127,46 @@ OBJS += ../Common/CommandAPDU.o
OBJS += ../Common/PCSCException.o
OBJS += ../Common/ResponseAPDU.o
OBJS += ../Common/SCard.o
OBJS += ../Common/SCardLoader.o
OBJS += ../Common/SCardManager.o
OBJS += ../Common/SCardReader.o
OBJS += ../Common/Token.o
OBJS += ../Common/Crc.o
OBJS += ../Common/TLVParser.o
OBJS += ../Common/EMVCard.o
OBJS += ../Common/EMVToken.o
OBJS += ../Common/Endian.o
OBJS += ../Common/GfMul.o
OBJS += ../Common/SecurityToken.o
VolumeLibrary: Volume.a
ifeq "$(ENABLE_WOLFCRYPT)" "0"
ifeq "$(PLATFORM)" "MacOSX"
ifneq "$(COMPILE_ASM)" "false"
+../Crypto/Aes_hw_armv8.oo: ../Crypto/Aes_hw_armv8.c
+ @echo Compiling $(<F)
+ $(CC) $(CFLAGS_ARM64) -c ../Crypto/Aes_hw_armv8.c -o ../Crypto/Aes_hw_armv8_arm64.o
+ $(CC) $(CFLAGS_X64) -c ../Crypto/Aes_hw_armv8.c -o ../Crypto/Aes_hw_armv8_x64.o
+ lipo -create ../Crypto/Aes_hw_armv8_arm64.o ../Crypto/Aes_hw_armv8_x64.o -output ../Crypto/Aes_hw_armv8.oo
+ rm -fr ../Crypto/Aes_hw_armv8_arm64.o ../Crypto/Aes_hw_armv8_x64.o
../Crypto/Aes_asm.oo: ../Crypto/Aes_x86.asm ../Crypto/Aes_x64.asm
@echo Assembling $(<F)
$(AS) $(ASFLAGS32) -o ../Crypto/Aes_x86.o ../Crypto/Aes_x86.asm
$(AS) $(ASFLAGS64) -o ../Crypto/Aes_x64.o ../Crypto/Aes_x64.asm
lipo -create ../Crypto/Aes_x86.o ../Crypto/Aes_x64.o -output ../Crypto/Aes_asm.oo
rm -fr ../Crypto/Aes_x86.o ../Crypto/Aes_x64.o
../Crypto/Twofish_asm.oo: ../Crypto/Twofish_x64.S
@echo Assembling $(<F)
$(AS) $(ASFLAGS64) -p gas -o ../Crypto/Twofish_asm.oo ../Crypto/Twofish_x64.S
../Crypto/Camellia_asm.oo: ../Crypto/Camellia_x64.S
@echo Assembling $(<F)
$(AS) $(ASFLAGS64) -p gas -o ../Crypto/Camellia_asm.oo ../Crypto/Camellia_x64.S
../Crypto/Camellia_aesni_asm.oo: ../Crypto/Camellia_aesni_x64.S
@echo Assembling $(<F)
$(AS) $(ASFLAGS64) -p gas -o ../Crypto/Camellia_aesni_asm.oo ../Crypto/Camellia_aesni_x64.S
../Crypto/sha256-nayuki.oo: ../Crypto/sha256-x86-nayuki.S
@echo Assembling $(<F)
$(AS) $(ASFLAGS32) -p gas -o ../Crypto/sha256-x86-nayuki.o ../Crypto/sha256-x86-nayuki.S
$(AS) $(ASFLAGS64) -p gas -o ../Crypto/sha256-x64-nayuki.o ../Crypto/sha256-x64-nayuki.S
lipo -create ../Crypto/sha256-x86-nayuki.o ../Crypto/sha256-x64-nayuki.o -output ../Crypto/sha256-nayuki.oo