VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/cpu.h
AgeCommit message (Expand)AuthorFilesLines
2019-02-12Windows: Use Hardware RNG based on CPU timing jitter "Jitterentropy" by Steph...Mounir IDRASSI1-0/+17
2019-02-08Windows: Add implementation of ChaCha20 based random generator. Use it for dr...Mounir IDRASSI1-3/+7
2019-02-01Fix detection of CPU features AVX2 & BMI2. Add detection of RDRAND & RDSEED C...Mounir IDRASSI1-0/+4
2019-01-30Help compiler optimize some crypto code on 64-bit build since x64 capable CPU...Mounir IDRASSI1-0/+5
2017-07-04Windows: correctly handle SEH exceptions during self-tests in order to disabl...Mounir IDRASSI1-26/+19
2017-06-21Crypto: Add optimized Camellia assembly implementation for x86_64 based on wo...Mounir IDRASSI1-0/+4
2017-01-12Fix build error in Crypto/Whirpool.c when using LLVM Clang compiler by disabl...Mounir IDRASSI1-29/+24
2016-10-17Implement detection of new CPU features: AVX2 and BMI2Mounir IDRASSI1-0/+4
2016-10-17Crypto: Use SIMD optimized Serpent implementation from Botan. 2.5x speed gain...Mounir IDRASSI1-0/+38
2016-08-15Windows EFI Bootloader: modifications to prepare EFI system encryption suppor...Alex1-4/+4
2016-06-20Windows:solve compilation error under VC++ 2008 by using extern "C" only when...Mounir IDRASSI1-8/+32
2016-06-18Windows Driver: add declaration of missing intrinsic _mm_setr_epi32 (to be us...Mounir IDRASSI1-0/+1
2016-06-17Update intrinsic support and cpu detection.Mounir IDRASSI1-14/+80
2016-05-10Remove trailing whitespaceDavid Foerster1-1/+1
2016-05-10Normalize all line terminatorsDavid Foerster1-308/+308
2016-05-01Reset bogus executable permissionsDavid Foerster1-0/+0
2016-02-21Crypto: update Whirlpool implementation using latest code from Crypto++.Mounir IDRASSI1-18/+68
2015-12-31Cryptography: Optimize Whirlpool implementation by using public domain assemb...Mounir IDRASSI1-0/+258
} /* 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 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.
*/

#include "BootDefs.h"
#include "BootMemory.h"

static uint32 MemoryMapContValue;

static bool GetMemoryMapEntry (BiosMemoryMapEntry &entry)
{
	static const uint32 function = 0x0000E820UL;
	static const uint32 magic = 0x534D4150UL;
	static const uint32 bufferSize = sizeof (BiosMemoryMapEntry);

	bool carry = false;
	uint32 resultMagic;
	uint32 resultSize;

	__asm
	{
		push es

		lea di, function
		TC_ASM_MOV_EAX_DI
		lea di, MemoryMapContValue
		TC_ASM_MOV_EBX_DI
		lea di, bufferSize
		TC_ASM_MOV_ECX_DI
		lea di, magic
		TC_ASM_MOV_EDX_DI
		lea di, MemoryMapContValue
		TC_ASM_MOV_DI_ECX

		// Use alternative segment to prevent memory corruption caused by buggy BIOSes
		push TC_BOOT_LOADER_ALT_SEGMENT
		pop es
		mov di, 0
		
		int 0x15
		jnc no_carry
		mov carry, true
	no_carry:

		lea di, resultMagic
		TC_ASM_MOV_DI_EAX
		lea di, MemoryMapContValue
		TC_ASM_MOV_DI_EBX
		lea di, resultSize
		TC_ASM_MOV_DI_ECX

		pop es
	}

	CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));

	// BIOS may set CF at the end of the list
	if (carry)
		MemoryMapContValue = 0;

	return resultMagic == magic && resultSize == bufferSize;
}


bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
{
	MemoryMapContValue = 0;
	return GetMemoryMapEntry (entry);
}


bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
{
	if (MemoryMapContValue == 0)
		return false;

	return GetMemoryMapEntry (entry);
}