summaryrefslogtreecommitdiffhomepage
path: root/libtomcrypt/src/modes/xts
diff options
context:
space:
mode:
Diffstat (limited to 'libtomcrypt/src/modes/xts')
-rw-r--r--libtomcrypt/src/modes/xts/xts_decrypt.c113
-rw-r--r--libtomcrypt/src/modes/xts/xts_done.c15
-rw-r--r--libtomcrypt/src/modes/xts/xts_encrypt.c113
-rw-r--r--libtomcrypt/src/modes/xts/xts_init.c26
-rw-r--r--libtomcrypt/src/modes/xts/xts_mult_x.c33
-rw-r--r--libtomcrypt/src/modes/xts/xts_test.c195
6 files changed, 309 insertions, 186 deletions
diff --git a/libtomcrypt/src/modes/xts/xts_decrypt.c b/libtomcrypt/src/modes/xts/xts_decrypt.c
index 3e46c53..4580991 100644
--- a/libtomcrypt/src/modes/xts/xts_decrypt.c
+++ b/libtomcrypt/src/modes/xts/xts_decrypt.c
@@ -5,18 +5,16 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
-/**
- 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
+ */
#ifdef LTC_XTS_MODE
-static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char *T, symmetric_xts *xts)
+static int _tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char *T, symmetric_xts *xts)
{
unsigned long x;
int err;
@@ -24,23 +22,23 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
/* tweak encrypt block i */
#ifdef LTC_FAST
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&P[x]) = *((LTC_FAST_TYPE*)&C[x]) ^ *((LTC_FAST_TYPE*)&T[x]);
+ *(LTC_FAST_TYPE_PTR_CAST(&P[x])) = *(LTC_FAST_TYPE_PTR_CAST(&C[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
}
#else
for (x = 0; x < 16; x++) {
- P[x] = C[x] ^ T[x];
+ P[x] = C[x] ^ T[x];
}
#endif
-
- err = cipher_descriptor[xts->cipher].ecb_decrypt(P, P, &xts->key1);
+
+ err = cipher_descriptor[xts->cipher].ecb_decrypt(P, P, &xts->key1);
#ifdef LTC_FAST
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&P[x]) ^= *((LTC_FAST_TYPE*)&T[x]);
+ *(LTC_FAST_TYPE_PTR_CAST(&P[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
}
#else
for (x = 0; x < 16; x++) {
- P[x] = P[x] ^ T[x];
+ P[x] = P[x] ^ T[x];
}
#endif
@@ -48,30 +46,28 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
xts_mult_x(T);
return err;
-}
+}
/** XTS Decryption
- @param ct [in] Ciphertext
- @param ptlen Length of plaintext (and ciphertext)
- @param pt [out] Plaintext
- @param tweak [in] The 128--bit encryption tweak (e.g. sector number)
- @param xts The XTS structure
- Returns CRYPT_OK upon success
-*/int xts_decrypt(
- const unsigned char *ct, unsigned long ptlen,
- unsigned char *pt,
- const unsigned char *tweak,
- symmetric_xts *xts)
+ @param ct [in] Ciphertext
+ @param ptlen Length of plaintext (and ciphertext)
+ @param pt [out] Plaintext
+ @param tweak [in] The 128--bit encryption tweak (e.g. sector number)
+ @param xts The XTS structure
+ Returns CRYPT_OK upon success
+ */
+int xts_decrypt(const unsigned char *ct, unsigned long ptlen, unsigned char *pt, unsigned char *tweak,
+ symmetric_xts *xts)
{
unsigned char PP[16], CC[16], T[16];
unsigned long i, m, mo, lim;
- int err;
+ int err;
/* check inputs */
- LTC_ARGCHK(pt != NULL);
- LTC_ARGCHK(ct != NULL);
+ LTC_ARGCHK(pt != NULL);
+ LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(tweak != NULL);
- LTC_ARGCHK(xts != NULL);
+ LTC_ARGCHK(xts != NULL);
/* check if valid */
if ((err = cipher_is_valid(xts->cipher)) != CRYPT_OK) {
@@ -79,7 +75,7 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
}
/* get number of blocks */
- m = ptlen >> 4;
+ m = ptlen >> 4;
mo = ptlen & 15;
/* must have at least one full block */
@@ -87,55 +83,74 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
return CRYPT_INVALID_ARG;
}
- /* encrypt the tweak */
- if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
- return err;
- }
-
- /* for i = 0 to m-2 do */
if (mo == 0) {
lim = m;
} else {
lim = m - 1;
}
- for (i = 0; i < lim; i++) {
- err = tweak_uncrypt(ct, pt, T, xts);
- ct += 16;
- pt += 16;
+ if (cipher_descriptor[xts->cipher].accel_xts_decrypt && lim > 0) {
+
+ /* use accelerated decryption for whole blocks */
+ if ((err = cipher_descriptor[xts->cipher].accel_xts_decrypt(ct, pt, lim, tweak, &xts->key1, &xts->key2)) !=
+ CRYPT_OK) {
+ return err;
+ }
+ ct += lim * 16;
+ pt += lim * 16;
+
+ /* tweak is encrypted on output */
+ XMEMCPY(T, tweak, sizeof(T));
+ } else {
+ /* encrypt the tweak */
+ if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
+ return err;
+ }
+
+ for (i = 0; i < lim; i++) {
+ if ((err = _tweak_uncrypt(ct, pt, T, xts)) != CRYPT_OK) {
+ return err;
+ }
+ ct += 16;
+ pt += 16;
+ }
}
-
+
/* if ptlen not divide 16 then */
if (mo > 0) {
XMEMCPY(CC, T, 16);
xts_mult_x(CC);
/* PP = tweak decrypt block m-1 */
- if ((err = tweak_uncrypt(ct, PP, CC, xts)) != CRYPT_OK) {
+ if ((err = _tweak_uncrypt(ct, PP, CC, xts)) != CRYPT_OK) {
return err;
}
/* Pm = first ptlen % 16 bytes of PP */
for (i = 0; i < mo; i++) {
- CC[i] = ct[16+i];
- pt[16+i] = PP[i];
+ CC[i] = ct[16 + i];
+ pt[16 + i] = PP[i];
}
for (; i < 16; i++) {
- CC[i] = PP[i];
+ CC[i] = PP[i];
}
/* Pm-1 = Tweak uncrypt CC */
- if ((err = tweak_uncrypt(CC, pt, T, xts)) != CRYPT_OK) {
+ if ((err = _tweak_uncrypt(CC, pt, T, xts)) != CRYPT_OK) {
return err;
}
}
+ /* Decrypt the tweak back */
+ if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
+ return err;
+ }
+
return CRYPT_OK;
}
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
-
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/xts/xts_done.c b/libtomcrypt/src/modes/xts/xts_done.c
index 7c04277..558c043 100644
--- a/libtomcrypt/src/modes/xts/xts_done.c
+++ b/libtomcrypt/src/modes/xts/xts_done.c
@@ -5,19 +5,17 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
-/**
+/**
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
*/
#ifdef LTC_XTS_MODE
-/** Terminate XTS state
- @param XTS The state to terminate
+/** Terminate XTS state
+ @param xts The state to terminate
*/
void xts_done(symmetric_xts *xts)
{
@@ -28,7 +26,6 @@ void xts_done(symmetric_xts *xts)
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
-
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/xts/xts_encrypt.c b/libtomcrypt/src/modes/xts/xts_encrypt.c
index ab53d3c..787c302 100644
--- a/libtomcrypt/src/modes/xts/xts_encrypt.c
+++ b/libtomcrypt/src/modes/xts/xts_encrypt.c
@@ -5,18 +5,16 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
-/**
- 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
+ */
#ifdef LTC_XTS_MODE
-static int tweak_crypt(const unsigned char *P, unsigned char *C, unsigned char *T, symmetric_xts *xts)
+static int _tweak_crypt(const unsigned char *P, unsigned char *C, unsigned char *T, symmetric_xts *xts)
{
unsigned long x;
int err;
@@ -24,25 +22,25 @@ static int tweak_crypt(const unsigned char *P, unsigned char *C, unsigned char *
/* tweak encrypt block i */
#ifdef LTC_FAST
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&C[x]) = *((LTC_FAST_TYPE*)&P[x]) ^ *((LTC_FAST_TYPE*)&T[x]);
+ *(LTC_FAST_TYPE_PTR_CAST(&C[x])) = *(LTC_FAST_TYPE_PTR_CAST(&P[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
}
#else
for (x = 0; x < 16; x++) {
C[x] = P[x] ^ T[x];
}
#endif
-
+
if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(C, C, &xts->key1)) != CRYPT_OK) {
return err;
}
#ifdef LTC_FAST
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
- *((LTC_FAST_TYPE*)&C[x]) ^= *((LTC_FAST_TYPE*)&T[x]);
+ *(LTC_FAST_TYPE_PTR_CAST(&C[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
}
#else
for (x = 0; x < 16; x++) {
- C[x] = C[x] ^ T[x];
+ C[x] = C[x] ^ T[x];
}
#endif
@@ -50,31 +48,28 @@ static int tweak_crypt(const unsigned char *P, unsigned char *C, unsigned char *
xts_mult_x(T);
return CRYPT_OK;
-}
+}
/** XTS Encryption
- @param pt [in] Plaintext
- @param ptlen Length of plaintext (and ciphertext)
- @param ct [out] Ciphertext
- @param tweak [in] The 128--bit encryption tweak (e.g. sector number)
- @param xts The XTS structure
- Returns CRYPT_OK upon success
-*/
-int xts_encrypt(
- const unsigned char *pt, unsigned long ptlen,
- unsigned char *ct,
- const unsigned char *tweak,
- symmetric_xts *xts)
+ @param pt [in] Plaintext
+ @param ptlen Length of plaintext (and ciphertext)
+ @param ct [out] Ciphertext
+ @param tweak [in] The 128--bit encryption tweak (e.g. sector number)
+ @param xts The XTS structure
+ Returns CRYPT_OK upon success
+ */
+int xts_encrypt(const unsigned char *pt, unsigned long ptlen, unsigned char *ct, unsigned char *tweak,
+ symmetric_xts *xts)
{
unsigned char PP[16], CC[16], T[16];
unsigned long i, m, mo, lim;
- int err;
+ int err;
/* check inputs */
- LTC_ARGCHK(pt != NULL);
- LTC_ARGCHK(ct != NULL);
+ LTC_ARGCHK(pt != NULL);
+ LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(tweak != NULL);
- LTC_ARGCHK(xts != NULL);
+ LTC_ARGCHK(xts != NULL);
/* check if valid */
if ((err = cipher_is_valid(xts->cipher)) != CRYPT_OK) {
@@ -82,61 +77,81 @@ int xts_encrypt(
}
/* get number of blocks */
- m = ptlen >> 4;
+ m = ptlen >> 4;
mo = ptlen & 15;
- /* must have at least one full block */
+ /* must have at least one full block */
if (m == 0) {
return CRYPT_INVALID_ARG;
}
- /* encrypt the tweak */
- if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
- return err;
- }
-
- /* for i = 0 to m-2 do */
if (mo == 0) {
lim = m;
} else {
lim = m - 1;
}
- for (i = 0; i < lim; i++) {
- err = tweak_crypt(pt, ct, T, xts);
- ct += 16;
- pt += 16;
+ if (cipher_descriptor[xts->cipher].accel_xts_encrypt && lim > 0) {
+
+ /* use accelerated encryption for whole blocks */
+ if ((err = cipher_descriptor[xts->cipher].accel_xts_encrypt(pt, ct, lim, tweak, &xts->key1, &xts->key2)) !=
+ CRYPT_OK) {
+ return err;
+ }
+ ct += lim * 16;
+ pt += lim * 16;
+
+ /* tweak is encrypted on output */
+ XMEMCPY(T, tweak, sizeof(T));
+ } else {
+
+ /* encrypt the tweak */
+ if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
+ return err;
+ }
+
+ for (i = 0; i < lim; i++) {
+ if ((err = _tweak_crypt(pt, ct, T, xts)) != CRYPT_OK) {
+ return err;
+ }
+ ct += 16;
+ pt += 16;
+ }
}
-
+
/* if ptlen not divide 16 then */
if (mo > 0) {
/* CC = tweak encrypt block m-1 */
- if ((err = tweak_crypt(pt, CC, T, xts)) != CRYPT_OK) {
+ if ((err = _tweak_crypt(pt, CC, T, xts)) != CRYPT_OK) {
return err;
}
/* Cm = first ptlen % 16 bytes of CC */
for (i = 0; i < mo; i++) {
- PP[i] = pt[16+i];
- ct[16+i] = CC[i];
+ PP[i] = pt[16 + i];
+ ct[16 + i] = CC[i];
}
for (; i < 16; i++) {
- PP[i] = CC[i];
+ PP[i] = CC[i];
}
/* Cm-1 = Tweak encrypt PP */
- if ((err = tweak_crypt(PP, ct, T, xts)) != CRYPT_OK) {
+ if ((err = _tweak_crypt(PP, ct, T, xts)) != CRYPT_OK) {
return err;
}
}
+ /* Decrypt the tweak back */
+ if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
+ return err;
+ }
+
return err;
}
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
-
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/xts/xts_init.c b/libtomcrypt/src/modes/xts/xts_init.c
index f38c01e..be0ac6a 100644
--- a/libtomcrypt/src/modes/xts/xts_init.c
+++ b/libtomcrypt/src/modes/xts/xts_init.c
@@ -5,18 +5,15 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
-/**
+/**
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
*/
#ifdef LTC_XTS_MODE
-
/** Start XTS mode
@param cipher The index of the cipher to use
@param key1 The encrypt key
@@ -26,19 +23,15 @@
@param xts [out] XTS structure
Returns CRYPT_OK upon success.
*/
-int xts_start( int cipher,
- const unsigned char *key1,
- const unsigned char *key2,
- unsigned long keylen,
- int num_rounds,
- symmetric_xts *xts)
+int xts_start(int cipher, const unsigned char *key1, const unsigned char *key2, unsigned long keylen, int num_rounds,
+ symmetric_xts *xts)
{
int err;
/* check inputs */
- LTC_ARGCHK(key1 != NULL);
- LTC_ARGCHK(key2 != NULL);
- LTC_ARGCHK(xts != NULL);
+ LTC_ARGCHK(key1 != NULL);
+ LTC_ARGCHK(key2 != NULL);
+ LTC_ARGCHK(xts != NULL);
/* check if valid */
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
@@ -63,7 +56,6 @@ int xts_start( int cipher,
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
-
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/xts/xts_mult_x.c b/libtomcrypt/src/modes/xts/xts_mult_x.c
index e5b7c11..3fad22b 100644
--- a/libtomcrypt/src/modes/xts/xts_mult_x.c
+++ b/libtomcrypt/src/modes/xts/xts_mult_x.c
@@ -5,38 +5,35 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
-/**
+/**
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
*/
#ifdef LTC_XTS_MODE
-/** multiply by x
+/** multiply by x
@param I The value to multiply by x (LFSR shift)
*/
void xts_mult_x(unsigned char *I)
{
- int x;
- unsigned char t, tt;
+ int x;
+ unsigned char t, tt;
- for (x = t = 0; x < 16; x++) {
- tt = I[x] >> 7;
- I[x] = ((I[x] << 1) | t) & 0xFF;
- t = tt;
- }
- if (tt) {
- I[0] ^= 0x87;
- }
+ for (x = t = 0; x < 16; x++) {
+ tt = I[x] >> 7;
+ I[x] = ((I[x] << 1) | t) & 0xFF;
+ t = tt;
+ }
+ if (tt) {
+ I[0] ^= 0x87;
+ }
}
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
-
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtomcrypt/src/modes/xts/xts_test.c b/libtomcrypt/src/modes/xts/xts_test.c
index b91e0f4..347fb4b 100644
--- a/libtomcrypt/src/modes/xts/xts_test.c
+++ b/libtomcrypt/src/modes/xts/xts_test.c
@@ -5,15 +5,70 @@
*
* The library is free for all purposes without any express
* guarantee it works.
- *
- * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
#ifdef LTC_XTS_MODE
-/**
+#ifndef LTC_NO_TEST
+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;
+ int (*orig)(const unsigned char *, unsigned char *,
+ unsigned long , unsigned char *, symmetric_key *,
+ symmetric_key *);
+
+ /* 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;
+ }
+ }
+ 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;
+ int (*orig)(const unsigned char *, unsigned char *,
+ unsigned long , unsigned char *, symmetric_key *,
+ symmetric_key *);
+
+ /* 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;
+ }
+ }
+ 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;
+}
+#endif
+
+/**
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
+
Returns CRYPT_OK upon success.
*/
int xts_test(void)
@@ -21,7 +76,8 @@ int xts_test(void)
#ifdef LTC_NO_TEST
return CRYPT_NOP;
#else
- static const struct {
+ static const struct
+ {
int keylen;
unsigned char key1[32];
unsigned char key2[32];
@@ -142,50 +198,102 @@ int xts_test(void)
},
};
- unsigned char OUT[512], T[16];
- ulong64 seq;
+ unsigned char OUT[512], Torg[16], T[16];
+ ulong64 seq;
symmetric_xts xts;
- int i, err, idx;
+ int i, j, k, err, idx;
+ 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 */
if ((idx = find_cipher("aes")) == -1) {
if ((idx = find_cipher("rijndael")) == -1) {
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 (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
+ /* skip the cases where
+ * the length is smaller than 2*blocklen
+ * or the length is not a multiple of 32
+ */
+ if ((j == 1) && ((tests[i].PTLEN < 32) || (tests[i].PTLEN % 32))) {
+ continue;
+ }
+ if ((k > 0) && (j == 1)) {
+ continue;
+ }
+ len = tests[i].PTLEN / 2;
+
+ err = xts_start(idx, tests[i].key1, tests[i].key2, tests[i].keylen / 2, 0, &xts);
+ if (err != CRYPT_OK) {
+ return err;
+ }
+
+ seq = tests[i].seqnum;
+ STORE64L(seq, Torg);
+ XMEMSET(Torg + 8, 0, 8);
+
+ XMEMCPY(T, Torg, sizeof(T));
+ if (j == 0) {
+ err = xts_encrypt(tests[i].PTX, tests[i].PTLEN, OUT, T, &xts);
+ if (err != CRYPT_OK) {
+ xts_done(&xts);
+ return err;
+ }
+ } else {
+ err = xts_encrypt(tests[i].PTX, len, OUT, T, &xts);
+ if (err != CRYPT_OK) {
+ xts_done(&xts);
+ return err;
+ }
+ err = xts_encrypt(&tests[i].PTX[len], len, &OUT[len], T, &xts);
+ if (err != CRYPT_OK) {
+ xts_done(&xts);
+ return err;
+ }
+ }
- for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
- err = xts_start(idx, tests[i].key1, tests[i].key2, tests[i].keylen/2, 0, &xts);
- if (err != CRYPT_OK) {
- return err;
- }
-
- seq = tests[i].seqnum;
- STORE64L(seq,T);
- XMEMSET(T+8, 0, 8);
-
- err = xts_encrypt(tests[i].PTX, tests[i].PTLEN, OUT, T, &xts);
- if (err != CRYPT_OK) {
- xts_done(&xts);
- return err;
- }
-
- if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) {
- xts_done(&xts);
- return CRYPT_FAIL_TESTVECTOR;
- }
-
- err = xts_decrypt(tests[i].CTX, tests[i].PTLEN, OUT, T, &xts);
- if (err != CRYPT_OK) {
- xts_done(&xts);
- return err;
- }
-
- if (XMEMCMP(OUT, tests[i].PTX, tests[i].PTLEN)) {
- xts_done(&xts);
- return CRYPT_FAIL_TESTVECTOR;
- }
- xts_done(&xts);
+ if (compare_testvector(OUT, tests[i].PTLEN, tests[i].CTX, tests[i].PTLEN, "XTS encrypt", i)) {
+ xts_done(&xts);
+ return CRYPT_FAIL_TESTVECTOR;
+ }
+
+ XMEMCPY(T, Torg, sizeof(T));
+ if (j == 0) {
+ err = xts_decrypt(tests[i].CTX, tests[i].PTLEN, OUT, T, &xts);
+ if (err != CRYPT_OK) {
+ xts_done(&xts);
+ return err;
+ }
+ } else {
+ err = xts_decrypt(tests[i].CTX, len, OUT, T, &xts);
+ if (err != CRYPT_OK) {
+ xts_done(&xts);
+ return err;
+ }
+ err = xts_decrypt(&tests[i].CTX[len], len, &OUT[len], T, &xts);
+ if (err != CRYPT_OK) {
+ xts_done(&xts);
+ return err;
+ }
+ }
+
+ if (compare_testvector(OUT, tests[i].PTLEN, tests[i].PTX, tests[i].PTLEN, "XTS decrypt", i)) {
+ xts_done(&xts);
+ return CRYPT_FAIL_TESTVECTOR;
+ }
+ xts_done(&xts);
+ }
+ }
}
return CRYPT_OK;
#endif
@@ -193,7 +301,6 @@ int xts_test(void)
#endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
-
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */