Esempio n. 1
0
void dc_init_encryption()
{
	DbgMsg("dc_init_encryption\n");

	if (aes256_padlock_available() != 0) {
		SetFlag(dc_load_flags, DST_VIA_PADLOCK);
		DbgMsg("CpuFlags_VIA_PadLock: Yes\n");
	} else {
		ClearFlag(dc_load_flags, DST_VIA_PADLOCK);
		DbgMsg("CpuFlags_VIA_PadLock: No\n");
	}
	
	if (xts_aes_ni_available() != 0) {
		SetFlag(dc_load_flags, DST_INTEL_NI);
		DbgMsg("CpuFlags_AES_NI: Yes\n");
	} else {
		ClearFlag(dc_load_flags, DST_INTEL_NI);
		DbgMsg("CpuFlags_AES_NI: No\n");
	}

#ifdef _M_IX86
	if (xts_serpent_sse2_available() != 0) {
		SetFlag(dc_load_flags, DST_INSTR_SSE2);
		DbgMsg("CpuFlags_SSE2: Yes\n");
	} else {
		ClearFlag(dc_load_flags, DST_INSTR_SSE2);
		DbgMsg("CpuFlags_SSE2: No\n");
	}
#else
	DbgMsg("CpuFlags_SSE2: Yes\n");
	SetFlag(dc_load_flags, DST_INSTR_SSE2);
#endif

	if (xts_serpent_avx_available() != 0) {
		SetFlag(dc_load_flags, DST_INSTR_AVX);
		DbgMsg("CpuFlags_AVX: Yes\n");
	} else {
		ClearFlag(dc_load_flags, DST_INSTR_AVX);
		DbgMsg("CpuFlags_AVX: No\n");
	}

	// initialize XTS mode engine and run small encryption test
	xts_init(dc_conf_flags & CONF_HW_CRYPTO);
	dc_simple_encryption_test();
}
int wmain(int argc, wchar_t *argv[])
{
#if !defined(SMALL_CODE) || !defined(_M_X64)
	printf("VIA-Padlock support: %d\n", aes256_padlock_available());
#endif
#ifndef SMALL_CODE
	printf("AES-NI support: %d\n", xts_aes_ni_available());
	printf("SSE2 support: %d\n", xts_serpent_sse2_available());
	printf("AVX  support: %d\n", xts_serpent_avx_available());
	printf("crc32: %d\n", test_crc32());
#endif	
	printf("sha512: %d\n", test_sha512());
	printf("pkcs5: %d\n", test_pkcs5());
	printf("Aes-256: %d\n", test_aes256());
	printf("Twofish-256: %d\n", test_twofish256());
	printf("Seprent-256: %d\n", test_serpent256());
	printf("XTS: %d\n", test_xts_mode());

	_getch(); return 0;
}
Esempio n. 3
0
int test_aes256()
{
	char       tmp[16];
	aes256_key skey;
	int        i;
#ifndef SMALL_CODE	
	u32        old_p;
#endif	

#ifdef SMALL_CODE
	/* initialize AES tables */
	aes256_gentab();
#else
	/* allow execute code from key buffer */
	if (VirtualProtect(&skey, sizeof(skey), PAGE_EXECUTE_READWRITE, &old_p) == 0) {
		return 0;
	}
#endif
	/* test basic assembler inmpementation */
	for (i = 0; i < array_num(aes256_vectors); i++) 
	{
#ifdef SMALL_CODE
		aes256_set_key(aes256_vectors[i].key, &skey);
		aes256_encrypt(aes256_vectors[i].plaintext, tmp, &skey);
#else
		aes256_asm_set_key(aes256_vectors[i].key, &skey);
		aes256_asm_encrypt(aes256_vectors[i].plaintext, tmp, &skey);
#endif
		if (memcmp(aes256_vectors[i].ciphertext, tmp, sizeof(tmp)) != 0) {
			return 0;
		}
#ifdef SMALL_CODE
		aes256_decrypt(aes256_vectors[i].ciphertext, tmp, &skey);
#else
		aes256_asm_decrypt(aes256_vectors[i].ciphertext, tmp, &skey);
#endif
		if (memcmp(aes256_vectors[i].plaintext, tmp, sizeof(tmp)) != 0) {
			return 0;
		}
#if !defined(SMALL_CODE) || !defined(_M_X64)
		/* test AES with VIA Padlock API */
		if (aes256_padlock_available() != 0)
		{
#ifdef SMALL_CODE
			aes256_padlock_encrypt(aes256_vectors[i].plaintext, tmp, &skey);
#else
			aes256_padlock_encrypt(aes256_vectors[i].plaintext, tmp, 1, &skey);
#endif
			if (memcmp(aes256_vectors[i].ciphertext, tmp, sizeof(tmp)) != 0) {
				return 0;
			}
#ifdef SMALL_CODE
			aes256_padlock_decrypt(aes256_vectors[i].ciphertext, tmp, &skey);
#else
			aes256_padlock_decrypt(aes256_vectors[i].ciphertext, tmp, 1, &skey);
#endif
			if (memcmp(aes256_vectors[i].plaintext, tmp, sizeof(tmp)) != 0) {
				return 0;
			}
		}
#endif
	}
	return 1;
}