기존에 사용하는 aes를 aes-ni로 바꾸고싶은데 잘 모르겠네요
안녕하세요.
aes-ni를 공부하고, 이를 기존에 동작하던 aes 시스템에 적용하려고 하는데.. 잘 안되네요.
우선 기존 aes는 openssl에서 사용되는 라이브러리를 이용했습니다.
문제는 이 openssl의 aes를 intel에서 지원하는 aes-ni로 어떻게 '대치'하느냐가 좀 어렵네요 (사실 이해가 안가서..)
aes-ni 소스코드는 intel 홈페이지에서 얻었는데요.
(인텔 홈페이지 가면 무료로 다운받을 수 있습니다: https://software.intel.com/en-us/articles/download-the-intel-aesni-sample-library)
예시로 128비트 cbc로 동작하는 소스는 다음과 같습니다.
int test128_CBC(unsigned long numBlocks)
{
unsigned int buffer_size = numBlocks * BLOCK_SIZE;
unsigned int i;
UCHAR *testVector = (UCHAR*)_alloca(buffer_size);
UCHAR *testResult = (UCHAR*)_alloca(buffer_size);
UCHAR local_test_iv[BLOCK_SIZE];
unsigned int half_size;
// Init the test vector and the test result
for (i=0;i
{
testVector[i] = test_plain_text[i];
testResult[i] = 0xee;
}
// Init the Initialization Vector
memcpy(local_test_iv,test_init_vector,BLOCK_SIZE);
intel_AES_enc128_CBC(testVector, testResult, test_key_128, numBlocks, local_test_iv);
// check the encrypted buffer against the known cipher text
for (i=0;i
{
if (testResult[i] != test_cipher_128_cbc[i])
{
printf("%d",i);
return TEST_FAIL_DEC;
}
}
//test chaining as well
memcpy(local_test_iv,test_init_vector,BLOCK_SIZE);
half_size = numBlocks/2;
intel_AES_dec128_CBC(testResult,testVector,test_key_128,half_size,local_test_iv);
intel_AES_dec128_CBC(testResult+BLOCK_SIZE*(half_size),testVector+BLOCK_SIZE*(half_size),test_key_128,numBlocks - half_size,local_test_iv);
for (i=0;i
{
if (testVector[i] != test_plain_text[i])
{
printf("%d",i);
return TEST_FAIL_DEC;
}
}
return TEST_PASS;
}
그리고 기존 openssl에서 쓰던 aes_cbc 128비트는 다음과 같거든요.
AES_cbc_encrypt(inbuf, outbuf, inlength, key, iv, AES_ENCRYPT);
문제는 위에 있는 소스코드에서 보이는
intel_AES_enc128_CBC(testVector, testResult, test_key_128, numBlocks, local_test_iv);
여기에 testvector, numblocks 등등 이런게 기존에 있는거랑 뭐가 호환되는건지를 모르겠네여..
벡터가 왜 또 나오는지도 모르겠고ㅠㅠ 도움 부탁드립니다.
OpenSSL은 AES-NI를 기본값으로 사용합니다.
OpenSSL은 AES-NI를 기본값으로 사용합니다.
https://askubuntu.com/questions/843769/how-do-i-ensure-that-openssl-is-using-aes-ni-acceleration
그럼 아무조작안해도 그냥사용되는건가요?
코드를 수정할필요없이 cpu가 자동으로 aes-ni로 암복호화를 하나요?
음 ..
intel_AES_enc128_CBC() 의 prototype 을 보세요.
먼저 parameter 를 확인하고, 그 담에 argument 가 어떻게 전달되는지를 봐야죠.
그리고 AES_cbc_encrypt() 는 다음과 같이 생겼으니..
잘 보면 한 번 더 래핑했을 뿐, parameter 가 같다는 걸 알 수 있을 겁니다.
그리고 OpenSSL 의 crypto module 에 있는 aes 만 떼와서 다른 암호 모듈에 붙인거라면..
aesni 는 crypto/aes/asm/aesni-*.pl 에 perl 로 구현되어 있습니다.
그걸 실행해서 어셈 코드를 생성한 다음에, 그걸 빌드해서 링크합니다.
관련 함수들에 대한 prototype 은 crypto/evp/e_aes.c 에서 확인해 보세요.
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
댓글 달기