also test XTS accelerators

This commit is contained in:
Steffen Jaeckel 2015-08-26 00:05:07 +02:00
parent 181d2f2df7
commit f9c8c9c229

View File

@ -12,6 +12,54 @@
#ifdef LTC_XTS_MODE #ifdef LTC_XTS_MODE
static int _xts_test_accel_xts_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long blocks,
unsigned char *tweak, symmetric_key *skey1, symmetric_key *skey2)
{
int ret;
symmetric_xts xts;
/* AES can be under rijndael or aes... try to find it */
if ((xts.cipher = find_cipher("aes")) == -1) {
if ((xts.cipher = find_cipher("rijndael")) == -1) {
return CRYPT_NOP;
}
}
void *orig = cipher_descriptor[xts.cipher].accel_xts_encrypt;
cipher_descriptor[xts.cipher].accel_xts_encrypt = NULL;
XMEMCPY(&xts.key1, skey1, sizeof(symmetric_key));
XMEMCPY(&xts.key2, skey2, sizeof(symmetric_key));
ret = xts_encrypt(pt, blocks << 4, ct, tweak, &xts);
cipher_descriptor[xts.cipher].accel_xts_encrypt = orig;
return ret;
}
static int _xts_test_accel_xts_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long blocks,
unsigned char *tweak, symmetric_key *skey1, symmetric_key *skey2)
{
int ret;
symmetric_xts xts;
/* AES can be under rijndael or aes... try to find it */
if ((xts.cipher = find_cipher("aes")) == -1) {
if ((xts.cipher = find_cipher("rijndael")) == -1) {
return CRYPT_NOP;
}
}
void *orig = cipher_descriptor[xts.cipher].accel_xts_decrypt;
cipher_descriptor[xts.cipher].accel_xts_decrypt = NULL;
XMEMCPY(&xts.key1, skey1, sizeof(symmetric_key));
XMEMCPY(&xts.key2, skey2, sizeof(symmetric_key));
ret = xts_decrypt(ct, blocks << 4, pt, tweak, &xts);
cipher_descriptor[xts.cipher].accel_xts_decrypt = orig;
return ret;
}
/** /**
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
@ -147,7 +195,7 @@ int xts_test(void)
unsigned char OUT[512], Torg[16], T[16]; unsigned char OUT[512], Torg[16], T[16];
ulong64 seq; ulong64 seq;
symmetric_xts xts; symmetric_xts xts;
int i, j, err, idx; int i, j, k, err, idx;
unsigned long len; unsigned long len;
/* AES can be under rijndael or aes... try to find it */ /* AES can be under rijndael or aes... try to find it */
@ -156,6 +204,15 @@ int xts_test(void)
return CRYPT_NOP; return CRYPT_NOP;
} }
} }
for (k = 0; k < 4; ++k) {
cipher_descriptor[idx].accel_xts_encrypt = NULL;
cipher_descriptor[idx].accel_xts_decrypt = NULL;
if (k & 0x1) {
cipher_descriptor[idx].accel_xts_encrypt = _xts_test_accel_xts_encrypt;
}
if (k & 0x2) {
cipher_descriptor[idx].accel_xts_decrypt = _xts_test_accel_xts_decrypt;
}
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
/* skip the cases where /* skip the cases where
@ -165,6 +222,9 @@ int xts_test(void)
if ((j == 1) && ((tests[i].PTLEN < 32) || (tests[i].PTLEN % 32))) { if ((j == 1) && ((tests[i].PTLEN < 32) || (tests[i].PTLEN % 32))) {
continue; continue;
} }
if ((k > 0) && (j == 1)) {
continue;
}
len = tests[i].PTLEN / 2; len = tests[i].PTLEN / 2;
err = xts_start(idx, tests[i].key1, tests[i].key2, tests[i].keylen / 2, 0, &xts); err = xts_start(idx, tests[i].key1, tests[i].key2, tests[i].keylen / 2, 0, &xts);
@ -241,6 +301,7 @@ int xts_test(void)
xts_done(&xts); xts_done(&xts);
} }
} }
}
return CRYPT_OK; return CRYPT_OK;
#endif #endif
} }