VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main/Forms/WaitDialog.cpp
blob: d3372db0b2b5be100fdc423086c5e5ce38b15863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 Copyright (c) 2013-2017 IDRIX. All rights reserved.

 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.
*/

#include "System.h"
#include "Volume/EncryptionModeXTS.h"
#include "Main/GraphicUserInterface.h"
#include "Common/SecurityToken.h"
#include "WaitDialog.h"

namespace VeraCrypt
{
	DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED)
	DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_ADMIN_PASSWORD)
	DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_PIN)
	DEFINE_EVENT_TYPE(wxEVT_COMMAND_WAITDIALOG_SHOW_MSG)

	wxThread::ExitCode WaitThread::Entry()
	{
		m_pRoutine->Execute();
		wxQueueEvent (m_pHandler, new wxCommandEvent( wxEVT_COMMAND_WAITDIALOGTHREAD_COMPLETED,0));
		return (wxThread::ExitCode)0; // success
	}

	void WaitDialog::ThrowException(Exception* ex)
	{
	#define VC_CONVERT_EXCEPTION(NAME) if (dynamic_cast<NAME*> (ex)) throw (NAME&) *ex;
		VC_CONVERT_EXCEPTION (PasswordIncorrect);
		VC_CONVERT_EXCEPTION (PasswordKeyfilesIncorrect);
		VC_CONVERT_EXCEPTION (PasswordOrKeyboardLayoutIncorrect);
		VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect);
		VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect);
		VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect);
		VC_CONVERT_EXCEPTION (PasswordEmpty);
		VC_CONVERT_EXCEPTION (PasswordTooLong);
		VC_CONVERT_EXCEPTION (PasswordUTF8TooLong);
		VC_CONVERT_EXCEPTION (PasswordUTF8Invalid);
		VC_CONVERT_EXCEPTION (UnportablePassword);
		VC_CONVERT_EXCEPTION (ElevationFailed);
		VC_CONVERT_EXCEPTION (RootDeviceUnavailable);
		VC_CONVERT_EXCEPTION (DriveLetterUnavailable);
		VC_CONVERT_EXCEPTION (DriverError);
		VC_CONVERT_EXCEPTION (EncryptedSystemRequired);
		VC_CONVERT_EXCEPTION (HigherFuseVersionRequired);
		VC_CONVERT_EXCEPTION (KernelCryptoServiceTestFailed);
		VC_CONVERT_EXCEPTION (LoopDeviceSetupFailed);
		VC_CONVERT_EXCEPTION (MountPointRequired);
		VC_CONVERT_EXCEPTION (MountPointUnavailable);
		VC_CONVERT_EXCEPTION (NoDriveLetterAvailable);
		VC_CONVERT_EXCEPTION (TemporaryDirectoryFailure);
		VC_CONVERT_EXCEPTION (UnsupportedSectorSizeHiddenVolumeProtection);
		VC_CONVERT_EXCEPTION (UnsupportedSectorSizeNoKernelCrypto);
		VC_CONVERT_EXCEPTION (VolumeAlreadyMounted);
		VC_CONVERT_EXCEPTION (VolumeSlotUnavailable);
		VC_CONVERT_EXCEPTION (UserInterfaceException);
		VC_CONVERT_EXCEPTION (MissingArgument);
		VC_CONVERT_EXCEPTION (NoItemSelected);
		VC_CONVERT_EXCEPTION (StringFormatterException);
		VC_CONVERT_EXCEPTION (ExecutedProcessFailed);
		VC_CONVERT_EXCEPTION (AlreadyInitialized);
		VC_CONVERT_EXCEPTION (AssertionFailed);
		VC_CONVERT_EXCEPTION (ExternalException);
		VC_CONVERT_EXCEPTION (InsufficientData);
		VC_CONVERT_EXCEPTION (NotApplicable);
		VC_CONVERT_EXCEPTION (NotImplemented);
		VC_CONVERT_EXCEPTION (NotInitialized);
		VC_CONVERT_EXCEPTION (ParameterIncorrect);
		VC_CONVERT_EXCEPTION (ParameterTooLarge);
		VC_CONVERT_EXCEPTION (PartitionDeviceRequired);
		VC_CONVERT_EXCEPTION (StringConversionFailed);
		VC_CONVERT_EXCEPTION (TestFailed);
		VC_CONVERT_EXCEPTION (TimeOut);
		VC_CONVERT_EXCEPTION (UnknownException);
		VC_CONVERT_EXCEPTION (UserAbort)
		VC_CONVERT_EXCEPTION (CipherInitError);
		VC_CONVERT_EXCEPTION (WeakKeyDetected);
		VC_CONVERT_EXCEPTION (HigherVersionRequired);
		VC_CONVERT_EXCEPTION (KeyfilePathEmpty);
		VC_CONVERT_EXCEPTION (MissingVolumeData);
		VC_CONVERT_EXCEPTION (MountedVolumeInUse);
		VC_CONVERT_EXCEPTION (UnsupportedSectorSize);
		VC_CONVERT_EXCEPTION (VolumeEncryptionNotCompleted);
		VC_CONVERT_EXCEPTION (VolumeHostInUse);
		VC_CONVERT_EXCEPTION (VolumeProtected);
		VC_CONVERT_EXCEPTION (VolumeReadOnly);
		VC_CONVERT_EXCEPTION (Pkcs11Exception);
		VC_CONVERT_EXCEPTION (InvalidSecurityTokenKeyfilePath);
		VC_CONVERT_EXCEPTION (SecurityTokenLibraryNotInitialized);
		VC_CONVERT_EXCEPTION (SecurityTokenKeyfileAlreadyExists);
		VC_CONVERT_EXCEPTION (SecurityTokenKeyfileNotFound);
		VC_CONVERT_EXCEPTION (UnsupportedAlgoInTrueCryptMode);
		VC_CONVERT_EXCEPTION (UnsupportedTrueCryptFormat);
		VC_CONVERT_EXCEPTION (SystemException);
		VC_CONVERT_EXCEPTION (CipherException);
		VC_CONVERT_EXCEPTION (VolumeException);
		VC_CONVERT_EXCEPTION (PasswordException);
		throw *ex;
	}
}
>%2 - %1 + 1) %endmacro %macro aes_hw_cpu 2 %define OPERATION %1 %define BLOCK_COUNT %2 ; Load data blocks %assign block 1 %rep BLOCK_COUNT movdqu xmm%[block], [%[R]dx + 16 * (block - 1)] %assign block block+1 %endrep ; Encrypt/decrypt data blocks %assign round 0 %rep 15 movdqu xmm0, [%[R]cx + 16 * round] %assign block 1 %rep BLOCK_COUNT %if round = 0 pxor xmm%[block], xmm0 %else %if round < 14 aes%[OPERATION] xmm%[block], xmm0 %else aes%[OPERATION]last xmm%[block], xmm0 %endif %endif %assign block block+1 %endrep %assign round round+1 %endrep ; Store data blocks %assign block 1 %rep BLOCK_COUNT movdqu [%[R]dx + 16 * (block - 1)], xmm%[block] %assign block block+1 %endrep %undef OPERATION %undef BLOCK_COUNT %endmacro %macro aes_hw_cpu_32_blocks 1 %define OPERATION_32_BLOCKS %1 %ifidn __BITS__, 64 %define MAX_REG_BLOCK_COUNT 15 %else %define MAX_REG_BLOCK_COUNT 7 %endif %ifidn __OUTPUT_FORMAT__, win64 %if MAX_REG_BLOCK_COUNT > 5 push_xmm 6, MAX_REG_BLOCK_COUNT %endif %endif mov eax, 32 / MAX_REG_BLOCK_COUNT .1: aes_hw_cpu %[OPERATION_32_BLOCKS], MAX_REG_BLOCK_COUNT add %[R]dx, 16 * MAX_REG_BLOCK_COUNT dec eax jnz .1 %if (32 % MAX_REG_BLOCK_COUNT) != 0 aes_hw_cpu %[OPERATION_32_BLOCKS], (32 % MAX_REG_BLOCK_COUNT) %endif %ifidn __OUTPUT_FORMAT__, win64 %if MAX_REG_BLOCK_COUNT > 5 pop_xmm 6, MAX_REG_BLOCK_COUNT %endif %endif %undef OPERATION_32_BLOCKS %undef MAX_REG_BLOCK_COUNT %endmacro %ifidn __BITS__, 16 USE16 SEGMENT _TEXT PUBLIC CLASS=CODE USE16 SEGMENT _DATA PUBLIC CLASS=DATA USE16 GROUP DGROUP _TEXT _DATA SECTION _TEXT %else SECTION .text %endif ; void aes_hw_cpu_enable_sse (); export_function aes_hw_cpu_enable_sse mov %[R]ax, cr4 or ax, 1 << 9 mov cr4, %[R]ax ret %ifidn __BITS__, 16 ; byte is_aes_hw_cpu_supported (); export_function is_aes_hw_cpu_supported mov eax, 1 cpuid mov eax, ecx shr eax, 25 and al, 1 ret ; void aes_hw_cpu_decrypt (const byte *ks, byte *data); export_function aes_hw_cpu_decrypt mov ax, -16 jmp aes_hw_cpu_encrypt_decrypt ; void aes_hw_cpu_encrypt (const byte *ks, byte *data); export_function aes_hw_cpu_encrypt mov ax, 16 aes_hw_cpu_encrypt_decrypt: push bp mov bp, sp push di push si mov si, [bp + 4] ; ks mov di, [bp + 4 + 2] ; data movdqu xmm0, [si] movdqu xmm1, [di] pxor xmm1, xmm0 mov cx, 13 .round1_13: add si, ax movdqu xmm0, [si] cmp ax, 0 jl .decrypt aesenc xmm1, xmm0 jmp .2 .decrypt: aesdec xmm1, xmm0 .2: loop .round1_13 add si, ax movdqu xmm0, [si] cmp ax, 0 jl .decrypt_last aesenclast xmm1, xmm0 jmp .3 .decrypt_last: aesdeclast xmm1, xmm0 .3: movdqu [di], xmm1 pop si pop di pop bp ret %else ; __BITS__ != 16 ; byte is_aes_hw_cpu_supported (); export_function is_aes_hw_cpu_supported push %[R]bx mov eax, 1 cpuid mov eax, ecx shr eax, 25 and eax, 1 pop %[R]bx ret ; void aes_hw_cpu_decrypt (const byte *ks, byte *data); aes_function_entry aes_hw_cpu_decrypt aes_hw_cpu dec, 1 aes_function_exit ; void aes_hw_cpu_decrypt_32_blocks (const byte *ks, byte *data); aes_function_entry aes_hw_cpu_decrypt_32_blocks aes_hw_cpu_32_blocks dec aes_function_exit ; void aes_hw_cpu_encrypt (const byte *ks, byte *data); aes_function_entry aes_hw_cpu_encrypt aes_hw_cpu enc, 1 aes_function_exit ; void aes_hw_cpu_encrypt_32_blocks (const byte *ks, byte *data); aes_function_entry aes_hw_cpu_encrypt_32_blocks aes_hw_cpu_32_blocks enc aes_function_exit %endif ; __BITS__ != 16