VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/Sources
AgeCommit message (Collapse)AuthorFilesLines
2019-10-30Windows: use separate assembly files for RDRAND and RDSEED in order to fix a ↵Mounir IDRASSI1-0/+1
mysterious crash when MASM_RDSEED_GenerateBlock is called after MASM_RDRAND_GenerateBlock.
2019-03-01Windows: Implement RAM encryption for keys on 64-bit machines using ChaCha12 ↵Mounir IDRASSI1-0/+3
cipher and t1ha non-cryptographic fast hash (https://github.com/leo-yuriev/t1ha)
2019-02-12Windows: Use Hardware RNG based on CPU timing jitter "Jitterentropy" by ↵Mounir IDRASSI1-0/+1
Stephan Mueller as a good alternative to RDRAND (http://www.chronox.de/jent.html, smueller@chronox.de)
2019-02-08Windows: Add implementation of ChaCha20 based random generator. Use it for ↵Mounir IDRASSI1-1/+3
driver need of random bytes (currently only wipe bytes but more to come later).
2019-02-01Windows: use CPU RDRAND or RDSEED as an additional entropy source for our ↵Mounir IDRASSI1-0/+4
random generator when available
2017-11-27SIMD speed optimization for Kuznyechik cipher implementation (up to 2x ↵Mounir IDRASSI1-0/+1
speedup). Based on https://github.com/aprelev/libgost15.
2017-06-23Crypto: Add optimized SHA-512 and SHA-256 assembly implementations for ↵Mounir IDRASSI1-3/+18
x86_64 and x86. This improves speed by 30%.
2017-06-21Crypto: Add optimized Camellia assembly implementation for x86_64 based on ↵Mounir IDRASSI1-2/+7
work by Jussi Kivilinna (https://github.com/jkivilin/supercop-blockciphers). This improve speed by a factor of 2.5 when AES-NI supported by CPU and by 30% if AES-NI not supported.
2016-12-07Crypto: Add optimized Twofish assembly implementation for x86_64.Mounir IDRASSI1-1/+3
2016-10-17Crypto: Use SIMD optimized Serpent implementation from Botan. 2.5x speed ↵Mounir IDRASSI1-1/+2
gain factor. Update credits and copyrights notice.
2016-08-15Windows: Add support for Streebog (hash) and kuznyechik (encryption)Mounir IDRASSI1-0/+2
2016-08-15Windows: Add Magma cipher (GOST-89)Mounir IDRASSI1-1/+4
2016-06-02Crypto: Add support for Japanese encryption standard Camellia, including for ↵Mounir IDRASSI1-1/+2
system encryption.
2016-05-10Normalize all line terminatorsDavid Foerster1-20/+20
2015-12-31Cryptography: Optimize Whirlpool implementation by using public domain ↵Mounir IDRASSI1-0/+1
assembly code developed by Wei Dai
2014-11-08Remove remaining legacy cryptographic algorithms that are never used by ↵Mounir IDRASSI1-4/+0
VeraCrypt.
2014-11-08Add original TrueCrypt 7.1a sourcesMounir IDRASSI1-0/+23
hlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
;
; Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved.
;
; Governed by the TrueCrypt License 3.0 the full text of which is contained in
; the file License.txt included in TrueCrypt binary and source code distribution
; packages.
;

.MODEL tiny
.386
_TEXT SEGMENT USE16

INCLUDE BootDefs.i

ORG 7C00h	; Standard boot sector offset

start:
	; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
	; Far jump to the next instruction sets IP to the standard offset 7C00.
	db 0EAh				; jmp 0:main
	dw main, 0

loader_name_msg:
	db ' VeraCrypt Boot Loader', 13, 10, 0
	
main:
	cli	
	xor ax, ax
	mov ds, ax
	mov ss, ax
	mov sp, 7C00h
	sti

	; Display boot loader name
	test byte ptr [start + TC_BOOT_SECTOR_USER_CONFIG_OFFSET], TC_BOOT_USER_CFG_FLAG_SILENT_MODE
	jnz skip_loader_name_msg

	lea si, loader_name_msg
	call print
skip_loader_name_msg:

	; Determine boot loader segment
	mov ax, TC_BOOT_LOADER_SEGMENT

	; Check available memory
	cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
	jge memory_ok
	
	mov ax, TC_BOOT_LOADER_SEGMENT_LOW
	
	cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
	jge memory_ok
	
	; Insufficient memory
	mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT

memory_ok:
	mov es, ax

	; Clear BSS section
	xor al, al
	mov di, TC_COM_EXECUTABLE_OFFSET
	mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - TC_COM_EXECUTABLE_OFFSET - 1
	cld
	rep stosb
	
	mov ax, es
	sub ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16	; Decompressor segment
	mov es, ax
	
	; Load decompressor
	mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR
retry_backup:
	mov al, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
	mov bx, TC_COM_EXECUTABLE_OFFSET
	call read_sectors

	; Decompressor checksum
	xor ebx, ebx
	mov si, TC_COM_EXECUTABLE_OFFSET
	mov cx, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_LB_SIZE
	call checksum
	push ebx
	
	; Load compressed boot loader
	mov bx, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
	mov cl, TC_BOOT_LOADER_START_SECTOR
	mov al, TC_MAX_BOOT_LOADER_SECTOR_COUNT
	
	test backup_loader_used, 1
	jz non_backup
	mov al, TC_BOOT_LOADER_BACKUP_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
	mov cl, TC_BOOT_LOADER_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
	
non_backup:
	call read_sectors

	; Boot loader checksum
	pop ebx
	mov si, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
	mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
	call checksum
	
	; Verify checksum
	cmp ebx, dword ptr [start + TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET]
	je checksum_ok

	; Checksum incorrect - try using backup if available
	test backup_loader_used, 1
	jnz loader_damaged
	
	mov backup_loader_used, 1
	mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
	
	test TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
	jnz retry_backup
	
loader_damaged:
	lea si, loader_damaged_msg
	call print
	lea si, loader_name_msg
	call print
	jmp $
checksum_ok:

	; Set up decompressor segment
	mov ax, es
	mov ds, ax
	cli
	mov ss, ax
	mov sp, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
	sti
	
	push dx
	
	; Decompress boot loader
	push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE			; Compressed data
	push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE									; Output buffer size
	push TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE + TC_COM_EXECUTABLE_OFFSET		; Output buffer

	push cs
	push decompressor_ret
	push es
	push TC_COM_EXECUTABLE_OFFSET
	retf
decompressor_ret:

	add sp, 6
	pop dx
	
	; Restore boot sector segment
	push cs
	pop ds

	; Check decompression result
	test ax, ax
	jz decompression_ok

	lea si, loader_damaged_msg
	call print
	jmp $
decompression_ok:

	; DH = boot sector flags
	mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
	
	; Set up boot loader segment
	mov ax, es
	add ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16
	mov es, ax
	mov ds, ax
	cli
	mov ss, ax
	mov sp, TC_BOOT_LOADER_STACK_TOP
	sti

	; Execute boot loader
	push es
	push TC_COM_EXECUTABLE_OFFSET
	retf
	
	; Print string
print:
	xor bx, bx
	mov ah, 0eh
	cld
	
@@:	lodsb
	test al, al
	jz print_end
	
	int 10h
	jmp @B

print_end:
	ret

	; Read sectors of the first cylinder
read_sectors:
	mov ch, 0           ; Cylinder
	mov dh, 0           ; Head
						; DL = drive number passed from BIOS
	mov ah, 2
	int 13h
	jnc read_ok
	
	lea si, disk_error_msg
	call print
read_ok:
	ret
	
	; Calculate checksum
checksum:
	push ds
	push es
	pop ds
	xor eax, eax
	cld
	
@@:	lodsb
	add ebx, eax
	rol ebx, 1
	loop @B
	
	pop ds
	ret

backup_loader_used		db 0
	
disk_error_msg			db 'Disk error', 13, 10, 7, 0
loader_damaged_msg		db 7, 'Loader damaged! Use Rescue Disk: Repair Options > Restore', 0

ORG 7C00h + 510
	dw 0AA55h			; Boot sector signature

_TEXT ENDS
END start