From d6319f7ea0a76de91bc01d9734d235b494c40198 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sun, 7 Jul 2019 03:17:05 +0000 Subject: [PATCH] remove f8 lrw xts modes --- Makefile | 21 -- libtomcrypt/src/modes/f8/f8_decrypt.c | 41 ---- libtomcrypt/src/modes/f8/f8_done.c | 40 ---- libtomcrypt/src/modes/f8/f8_encrypt.c | 101 -------- libtomcrypt/src/modes/f8/f8_getiv.c | 44 ---- libtomcrypt/src/modes/f8/f8_setiv.c | 50 ---- libtomcrypt/src/modes/f8/f8_start.c | 96 -------- libtomcrypt/src/modes/f8/f8_test_mode.c | 74 ------ libtomcrypt/src/modes/lrw/lrw_decrypt.c | 49 ---- libtomcrypt/src/modes/lrw/lrw_done.c | 40 ---- libtomcrypt/src/modes/lrw/lrw_encrypt.c | 48 ---- libtomcrypt/src/modes/lrw/lrw_getiv.c | 43 ---- libtomcrypt/src/modes/lrw/lrw_process.c | 118 --------- libtomcrypt/src/modes/lrw/lrw_setiv.c | 77 ------ libtomcrypt/src/modes/lrw/lrw_start.c | 101 -------- libtomcrypt/src/modes/lrw/lrw_test.c | 134 ----------- libtomcrypt/src/modes/xts/xts_decrypt.c | 156 ------------ libtomcrypt/src/modes/xts/xts_done.c | 31 --- libtomcrypt/src/modes/xts/xts_encrypt.c | 157 ------------ libtomcrypt/src/modes/xts/xts_init.c | 61 ----- libtomcrypt/src/modes/xts/xts_mult_x.c | 39 --- libtomcrypt/src/modes/xts/xts_test.c | 306 ------------------------ 22 files changed, 1827 deletions(-) delete mode 100644 libtomcrypt/src/modes/f8/f8_decrypt.c delete mode 100644 libtomcrypt/src/modes/f8/f8_done.c delete mode 100644 libtomcrypt/src/modes/f8/f8_encrypt.c delete mode 100644 libtomcrypt/src/modes/f8/f8_getiv.c delete mode 100644 libtomcrypt/src/modes/f8/f8_setiv.c delete mode 100644 libtomcrypt/src/modes/f8/f8_start.c delete mode 100644 libtomcrypt/src/modes/f8/f8_test_mode.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_decrypt.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_done.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_encrypt.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_getiv.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_process.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_setiv.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_start.c delete mode 100644 libtomcrypt/src/modes/lrw/lrw_test.c delete mode 100644 libtomcrypt/src/modes/xts/xts_decrypt.c delete mode 100644 libtomcrypt/src/modes/xts/xts_done.c delete mode 100644 libtomcrypt/src/modes/xts/xts_encrypt.c delete mode 100644 libtomcrypt/src/modes/xts/xts_init.c delete mode 100644 libtomcrypt/src/modes/xts/xts_mult_x.c delete mode 100644 libtomcrypt/src/modes/xts/xts_test.c diff --git a/Makefile b/Makefile index 80d3061..83cf5a3 100644 --- a/Makefile +++ b/Makefile @@ -521,33 +521,12 @@ LTCOBJ= \ modes/ecb/ecb_done.o \ modes/ecb/ecb_encrypt.o \ modes/ecb/ecb_start.o \ - modes/f8/f8_decrypt.o \ - modes/f8/f8_done.o \ - modes/f8/f8_encrypt.o \ - modes/f8/f8_getiv.o \ - modes/f8/f8_setiv.o \ - modes/f8/f8_start.o \ - modes/f8/f8_test_mode.o \ - modes/lrw/lrw_decrypt.o \ - modes/lrw/lrw_done.o \ - modes/lrw/lrw_encrypt.o \ - modes/lrw/lrw_getiv.o \ - modes/lrw/lrw_process.o \ - modes/lrw/lrw_start.o \ - modes/lrw/lrw_setiv.o \ - modes/lrw/lrw_test.o \ modes/ofb/ofb_decrypt.o \ modes/ofb/ofb_done.o \ modes/ofb/ofb_encrypt.o \ modes/ofb/ofb_getiv.o \ modes/ofb/ofb_setiv.o \ modes/ofb/ofb_start.o \ - modes/xts/xts_decrypt.o \ - modes/xts/xts_done.o \ - modes/xts/xts_encrypt.o \ - modes/xts/xts_init.o \ - modes/xts/xts_mult_x.o \ - modes/xts/xts_test.o \ pk/asn1/der/bit/der_decode_bit_string.o \ pk/asn1/der/bit/der_decode_raw_bit_string.o \ pk/asn1/der/bit/der_encode_bit_string.o \ diff --git a/libtomcrypt/src/modes/f8/f8_decrypt.c b/libtomcrypt/src/modes/f8/f8_decrypt.c deleted file mode 100644 index 9c92952..0000000 --- a/libtomcrypt/src/modes/f8/f8_decrypt.c +++ /dev/null @@ -1,41 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file f8_decrypt.c - F8 implementation, decrypt data, Tom St Denis -*/ - -#ifdef LTC_F8_MODE - -/** - F8 decrypt - @param ct Ciphertext - @param pt [out] Plaintext - @param len Length of ciphertext (octets) - @param f8 F8 state - @return CRYPT_OK if successful -*/ -int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8) -{ - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(f8 != NULL); - return f8_encrypt(ct, pt, len, f8); -} - - -#endif - - - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/f8/f8_done.c b/libtomcrypt/src/modes/f8/f8_done.c deleted file mode 100644 index 3f0af66..0000000 --- a/libtomcrypt/src/modes/f8/f8_done.c +++ /dev/null @@ -1,40 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file f8_done.c - F8 implementation, finish chain, Tom St Denis -*/ - -#ifdef LTC_F8_MODE - -/** Terminate the chain - @param f8 The F8 chain to terminate - @return CRYPT_OK on success -*/ -int f8_done(symmetric_F8 *f8) -{ - int err; - LTC_ARGCHK(f8 != NULL); - - if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { - return err; - } - cipher_descriptor[f8->cipher].done(&f8->key); - return CRYPT_OK; -} - - - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/f8/f8_encrypt.c b/libtomcrypt/src/modes/f8/f8_encrypt.c deleted file mode 100644 index 058f25a..0000000 --- a/libtomcrypt/src/modes/f8/f8_encrypt.c +++ /dev/null @@ -1,101 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file f8_encrypt.c - F8 implementation, encrypt data, Tom St Denis -*/ - -#ifdef LTC_F8_MODE - -/** - F8 encrypt - @param pt Plaintext - @param ct [out] Ciphertext - @param len Length of plaintext (octets) - @param f8 F8 state - @return CRYPT_OK if successful -*/ -int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8) -{ - int err, x; - unsigned char buf[MAXBLOCKSIZE]; - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(f8 != NULL); - if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { - return err; - } - - /* is blocklen/padlen valid? */ - if (f8->blocklen < 0 || f8->blocklen > (int)sizeof(f8->IV) || - f8->padlen < 0 || f8->padlen > (int)sizeof(f8->IV)) { - return CRYPT_INVALID_ARG; - } - - zeromem(buf, sizeof(buf)); - - /* make sure the pad is empty */ - if (f8->padlen == f8->blocklen) { - /* xor of IV, MIV and blockcnt == what goes into cipher */ - STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); - ++(f8->blockcnt); - for (x = 0; x < f8->blocklen; x++) { - f8->IV[x] ^= f8->MIV[x] ^ buf[x]; - } - if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) { - return err; - } - f8->padlen = 0; - } - -#ifdef LTC_FAST - if (f8->padlen == 0) { - while (len >= (unsigned long)f8->blocklen) { - STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); - ++(f8->blockcnt); - for (x = 0; x < f8->blocklen; x += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(&ct[x])) = *(LTC_FAST_TYPE_PTR_CAST(&pt[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&f8->IV[x])); - *(LTC_FAST_TYPE_PTR_CAST(&f8->IV[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&f8->MIV[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&buf[x])); - } - if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) { - return err; - } - len -= x; - pt += x; - ct += x; - } - } -#endif - - while (len > 0) { - if (f8->padlen == f8->blocklen) { - /* xor of IV, MIV and blockcnt == what goes into cipher */ - STORE32H(f8->blockcnt, (buf+(f8->blocklen-4))); - ++(f8->blockcnt); - for (x = 0; x < f8->blocklen; x++) { - f8->IV[x] ^= f8->MIV[x] ^ buf[x]; - } - if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) { - return err; - } - f8->padlen = 0; - } - *ct++ = *pt++ ^ f8->IV[f8->padlen++]; - --len; - } - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/f8/f8_getiv.c b/libtomcrypt/src/modes/f8/f8_getiv.c deleted file mode 100644 index a5885c9..0000000 --- a/libtomcrypt/src/modes/f8/f8_getiv.c +++ /dev/null @@ -1,44 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file ofb_getiv.c - F8 implementation, get IV, Tom St Denis -*/ - -#ifdef LTC_F8_MODE - -/** - Get the current initialization vector - @param IV [out] The destination of the initialization vector - @param len [in/out] The max size and resulting size of the initialization vector - @param f8 The F8 state - @return CRYPT_OK if successful -*/ -int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8) -{ - LTC_ARGCHK(IV != NULL); - LTC_ARGCHK(len != NULL); - LTC_ARGCHK(f8 != NULL); - if ((unsigned long)f8->blocklen > *len) { - *len = f8->blocklen; - return CRYPT_BUFFER_OVERFLOW; - } - XMEMCPY(IV, f8->IV, f8->blocklen); - *len = f8->blocklen; - - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/f8/f8_setiv.c b/libtomcrypt/src/modes/f8/f8_setiv.c deleted file mode 100644 index 8f45a3f..0000000 --- a/libtomcrypt/src/modes/f8/f8_setiv.c +++ /dev/null @@ -1,50 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file f8_setiv.c - F8 implementation, set IV, Tom St Denis -*/ - -#ifdef LTC_F8_MODE - -/** - Set an initialization vector - @param IV The initialization vector - @param len The length of the vector (in octets) - @param f8 The F8 state - @return CRYPT_OK if successful -*/ -int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8) -{ - int err; - - LTC_ARGCHK(IV != NULL); - LTC_ARGCHK(f8 != NULL); - - if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) { - return err; - } - - if (len != (unsigned long)f8->blocklen) { - return CRYPT_INVALID_ARG; - } - - /* force next block */ - f8->padlen = 0; - return cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->IV, &f8->key); -} - -#endif - - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/f8/f8_start.c b/libtomcrypt/src/modes/f8/f8_start.c deleted file mode 100644 index 6801702..0000000 --- a/libtomcrypt/src/modes/f8/f8_start.c +++ /dev/null @@ -1,96 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file f8_start.c - F8 implementation, start chain, Tom St Denis -*/ - - -#ifdef LTC_F8_MODE - -/** - Initialize an F8 context - @param cipher The index of the cipher desired - @param IV The initialization vector - @param key The secret key - @param keylen The length of the secret key (octets) - @param salt_key The salting key for the IV - @param skeylen The length of the salting key (octets) - @param num_rounds Number of rounds in the cipher desired (0 for default) - @param f8 The F8 state to initialize - @return CRYPT_OK if successful -*/ -int f8_start( int cipher, const unsigned char *IV, - const unsigned char *key, int keylen, - const unsigned char *salt_key, int skeylen, - int num_rounds, symmetric_F8 *f8) -{ - int x, err; - unsigned char tkey[MAXBLOCKSIZE]; - - LTC_ARGCHK(IV != NULL); - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(salt_key != NULL); - LTC_ARGCHK(f8 != NULL); - - if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { - return err; - } - -#ifdef LTC_FAST - if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) { - return CRYPT_INVALID_ARG; - } -#endif - - /* copy details */ - f8->blockcnt = 0; - f8->cipher = cipher; - f8->blocklen = cipher_descriptor[cipher].block_length; - f8->padlen = f8->blocklen; - - /* now get key ^ salt_key [extend salt_ket with 0x55 as required to match length] */ - zeromem(tkey, sizeof(tkey)); - for (x = 0; x < keylen && x < (int)sizeof(tkey); x++) { - tkey[x] = key[x]; - } - for (x = 0; x < skeylen && x < (int)sizeof(tkey); x++) { - tkey[x] ^= salt_key[x]; - } - for (; x < keylen && x < (int)sizeof(tkey); x++) { - tkey[x] ^= 0x55; - } - - /* now encrypt with tkey[0..keylen-1] the IV and use that as the IV */ - if ((err = cipher_descriptor[cipher].setup(tkey, keylen, num_rounds, &f8->key)) != CRYPT_OK) { - return err; - } - - /* encrypt IV */ - if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->MIV, &f8->key)) != CRYPT_OK) { - cipher_descriptor[f8->cipher].done(&f8->key); - return err; - } - zeromem(tkey, sizeof(tkey)); - zeromem(f8->IV, sizeof(f8->IV)); - - /* terminate this cipher */ - cipher_descriptor[f8->cipher].done(&f8->key); - - /* init the cipher */ - return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &f8->key); -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/f8/f8_test_mode.c b/libtomcrypt/src/modes/f8/f8_test_mode.c deleted file mode 100644 index 778cd35..0000000 --- a/libtomcrypt/src/modes/f8/f8_test_mode.c +++ /dev/null @@ -1,74 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file f8_test_mode.c - F8 implementation, test, Tom St Denis -*/ - - -#ifdef LTC_F8_MODE - -int f8_test_mode(void) -{ -#ifndef LTC_TEST - return CRYPT_NOP; -#else - static const unsigned char key[16] = { 0x23, 0x48, 0x29, 0x00, 0x84, 0x67, 0xbe, 0x18, - 0x6c, 0x3d, 0xe1, 0x4a, 0xae, 0x72, 0xd6, 0x2c }; - static const unsigned char salt[4] = { 0x32, 0xf2, 0x87, 0x0d }; - static const unsigned char IV[16] = { 0x00, 0x6e, 0x5c, 0xba, 0x50, 0x68, 0x1d, 0xe5, - 0x5c, 0x62, 0x15, 0x99, 0xd4, 0x62, 0x56, 0x4a }; - static const unsigned char pt[39] = { 0x70, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x72, 0x61, - 0x6e, 0x64, 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73, - 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x6e, 0x65, 0x78, 0x74, 0x20, 0x62, 0x65, 0x73, - 0x74, 0x20, 0x74, 0x68, 0x69, 0x6e, 0x67 }; - static const unsigned char ct[39] = { 0x01, 0x9c, 0xe7, 0xa2, 0x6e, 0x78, 0x54, 0x01, - 0x4a, 0x63, 0x66, 0xaa, 0x95, 0xd4, 0xee, 0xfd, - 0x1a, 0xd4, 0x17, 0x2a, 0x14, 0xf9, 0xfa, 0xf4, - 0x55, 0xb7, 0xf1, 0xd4, 0xb6, 0x2b, 0xd0, 0x8f, - 0x56, 0x2c, 0x0e, 0xef, 0x7c, 0x48, 0x02 }; - unsigned char buf[39]; - symmetric_F8 f8; - int err, idx; - - idx = find_cipher("aes"); - if (idx == -1) { - idx = find_cipher("rijndael"); - if (idx == -1) return CRYPT_NOP; - } - - /* initialize the context */ - if ((err = f8_start(idx, IV, key, sizeof(key), salt, sizeof(salt), 0, &f8)) != CRYPT_OK) { - return err; - } - - /* encrypt block */ - if ((err = f8_encrypt(pt, buf, sizeof(pt), &f8)) != CRYPT_OK) { - f8_done(&f8); - return err; - } - f8_done(&f8); - - /* compare */ - if (compare_testvector(buf, sizeof(ct), ct, sizeof(ct), "f8", 0)) { - return CRYPT_FAIL_TESTVECTOR; - } - - return CRYPT_OK; -#endif -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_decrypt.c b/libtomcrypt/src/modes/lrw/lrw_decrypt.c deleted file mode 100644 index bfedb64..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_decrypt.c +++ /dev/null @@ -1,49 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_decrypt.c - LRW_MODE implementation, Decrypt blocks, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - LRW decrypt blocks - @param ct The ciphertext - @param pt [out] The plaintext - @param len The length in octets, must be a multiple of 16 - @param lrw The LRW state -*/ -int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw) -{ - int err; - - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(lrw != NULL); - - if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { - return err; - } - - if (cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) { - return cipher_descriptor[lrw->cipher].accel_lrw_decrypt(ct, pt, len, lrw->IV, lrw->tweak, &lrw->key); - } - - return lrw_process(ct, pt, len, LRW_DECRYPT, lrw); -} - - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_done.c b/libtomcrypt/src/modes/lrw/lrw_done.c deleted file mode 100644 index 0088f62..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_done.c +++ /dev/null @@ -1,40 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_done.c - LRW_MODE implementation, Free resources, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - Terminate a LRW state - @param lrw The state to terminate - @return CRYPT_OK if successful -*/ -int lrw_done(symmetric_LRW *lrw) -{ - int err; - - LTC_ARGCHK(lrw != NULL); - - if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { - return err; - } - cipher_descriptor[lrw->cipher].done(&lrw->key); - - return CRYPT_OK; -} - -#endif -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_encrypt.c b/libtomcrypt/src/modes/lrw/lrw_encrypt.c deleted file mode 100644 index 0738648..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_encrypt.c +++ /dev/null @@ -1,48 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_encrypt.c - LRW_MODE implementation, Encrypt blocks, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - LRW encrypt blocks - @param pt The plaintext - @param ct [out] The ciphertext - @param len The length in octets, must be a multiple of 16 - @param lrw The LRW state -*/ -int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw) -{ - int err; - - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(lrw != NULL); - - if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { - return err; - } - - if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL) { - return cipher_descriptor[lrw->cipher].accel_lrw_encrypt(pt, ct, len, lrw->IV, lrw->tweak, &lrw->key); - } - - return lrw_process(pt, ct, len, LRW_ENCRYPT, lrw); -} - - -#endif -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_getiv.c b/libtomcrypt/src/modes/lrw/lrw_getiv.c deleted file mode 100644 index 6dcd96d..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_getiv.c +++ /dev/null @@ -1,43 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_getiv.c - LRW_MODE implementation, Retrieve the current IV, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - Get the IV for LRW - @param IV [out] The IV, must be 16 octets - @param len Length ... must be at least 16 :-) - @param lrw The LRW state to read - @return CRYPT_OK if successful -*/ -int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw) -{ - LTC_ARGCHK(IV != NULL); - LTC_ARGCHK(len != NULL); - LTC_ARGCHK(lrw != NULL); - if (*len < 16) { - *len = 16; - return CRYPT_BUFFER_OVERFLOW; - } - - XMEMCPY(IV, lrw->IV, 16); - *len = 16; - return CRYPT_OK; -} - -#endif -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_process.c b/libtomcrypt/src/modes/lrw/lrw_process.c deleted file mode 100644 index 0896bc6..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_process.c +++ /dev/null @@ -1,118 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_process.c - LRW_MODE implementation, Encrypt/decrypt blocks, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - Process blocks with LRW, since decrypt/encrypt are largely the same they share this code. - @param pt The "input" data - @param ct [out] The "output" data - @param len The length of the input, must be a multiple of 128-bits (16 octets) - @param mode LRW_ENCRYPT or LRW_DECRYPT - @param lrw The LRW state - @return CRYPT_OK if successful -*/ -int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw) -{ - unsigned char prod[16]; - int x, err; -#ifdef LTC_LRW_TABLES - int y; -#endif - - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(lrw != NULL); - - if (len & 15) { - return CRYPT_INVALID_ARG; - } - - while (len) { - /* copy pad */ - XMEMCPY(prod, lrw->pad, 16); - - /* increment IV */ - for (x = 15; x >= 0; x--) { - lrw->IV[x] = (lrw->IV[x] + 1) & 255; - if (lrw->IV[x]) { - break; - } - } - - /* update pad */ -#ifdef LTC_LRW_TABLES - /* for each byte changed we undo it's affect on the pad then add the new product */ - for (; x < 16; x++) { -#ifdef LTC_FAST - for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(lrw->pad + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][lrw->IV[x]][y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][(lrw->IV[x]-1)&255][y])); - } -#else - for (y = 0; y < 16; y++) { - lrw->pad[y] ^= lrw->PC[x][lrw->IV[x]][y] ^ lrw->PC[x][(lrw->IV[x]-1)&255][y]; - } -#endif - } -#else - gcm_gf_mult(lrw->tweak, lrw->IV, lrw->pad); -#endif - - /* xor prod */ -#ifdef LTC_FAST - for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(pt + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x)); - } -#else - for (x = 0; x < 16; x++) { - ct[x] = pt[x] ^ prod[x]; - } -#endif - - /* send through cipher */ - if (mode == LRW_ENCRYPT) { - if ((err = cipher_descriptor[lrw->cipher].ecb_encrypt(ct, ct, &lrw->key)) != CRYPT_OK) { - return err; - } - } else { - if ((err = cipher_descriptor[lrw->cipher].ecb_decrypt(ct, ct, &lrw->key)) != CRYPT_OK) { - return err; - } - } - - /* xor prod */ -#ifdef LTC_FAST - for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(ct + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x)); - } -#else - for (x = 0; x < 16; x++) { - ct[x] = ct[x] ^ prod[x]; - } -#endif - - /* move to next */ - pt += 16; - ct += 16; - len -= 16; - } - - return CRYPT_OK; -} - -#endif -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_setiv.c b/libtomcrypt/src/modes/lrw/lrw_setiv.c deleted file mode 100644 index 5c04157..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_setiv.c +++ /dev/null @@ -1,77 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_setiv.c - LRW_MODE implementation, Set the current IV, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - Set the IV for LRW - @param IV The IV, must be 16 octets - @param len Length ... must be 16 :-) - @param lrw The LRW state to update - @return CRYPT_OK if successful -*/ -int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw) -{ - int err; -#ifdef LTC_LRW_TABLES - unsigned char T[16]; - int x, y; -#endif - LTC_ARGCHK(IV != NULL); - LTC_ARGCHK(lrw != NULL); - - if (len != 16) { - return CRYPT_INVALID_ARG; - } - - if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) { - return err; - } - - /* copy the IV */ - XMEMCPY(lrw->IV, IV, 16); - - /* check if we have to actually do work */ - if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL && cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) { - /* we have accelerators, let's bail since they don't use lrw->pad anyways */ - return CRYPT_OK; - } - -#ifdef LTC_LRW_TABLES - XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16); - for (x = 1; x < 16; x++) { -#ifdef LTC_FAST - for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][IV[x]][y])); - } -#else - for (y = 0; y < 16; y++) { - T[y] ^= lrw->PC[x][IV[x]][y]; - } -#endif - } - XMEMCPY(lrw->pad, T, 16); -#else - gcm_gf_mult(lrw->tweak, IV, lrw->pad); -#endif - - return CRYPT_OK; -} - - -#endif -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_start.c b/libtomcrypt/src/modes/lrw/lrw_start.c deleted file mode 100644 index e13d3bd..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_start.c +++ /dev/null @@ -1,101 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_start.c - LRW_MODE implementation, start mode, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - Initialize the LRW context - @param cipher The cipher desired, must be a 128-bit block cipher - @param IV The index value, must be 128-bits - @param key The cipher key - @param keylen The length of the cipher key in octets - @param tweak The tweak value (second key), must be 128-bits - @param num_rounds The number of rounds for the cipher (0 == default) - @param lrw [out] The LRW state - @return CRYPT_OK on success. -*/ -int lrw_start( int cipher, - const unsigned char *IV, - const unsigned char *key, int keylen, - const unsigned char *tweak, - int num_rounds, - symmetric_LRW *lrw) -{ - int err; -#ifdef LTC_LRW_TABLES - unsigned char B[16]; - int x, y, z, t; -#endif - - LTC_ARGCHK(IV != NULL); - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(tweak != NULL); - LTC_ARGCHK(lrw != NULL); - -#ifdef LTC_FAST - if (16 % sizeof(LTC_FAST_TYPE)) { - return CRYPT_INVALID_ARG; - } -#endif - - /* is cipher valid? */ - if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { - return err; - } - if (cipher_descriptor[cipher].block_length != 16) { - return CRYPT_INVALID_CIPHER; - } - - /* schedule key */ - if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &lrw->key)) != CRYPT_OK) { - return err; - } - lrw->cipher = cipher; - - /* copy the IV and tweak */ - XMEMCPY(lrw->tweak, tweak, 16); - -#ifdef LTC_LRW_TABLES - /* setup tables */ - /* generate the first table as it has no shifting (from which we make the other tables) */ - zeromem(B, 16); - for (y = 0; y < 256; y++) { - B[0] = y; - gcm_gf_mult(tweak, B, &lrw->PC[0][y][0]); - } - - /* now generate the rest of the tables based the previous table */ - for (x = 1; x < 16; x++) { - for (y = 0; y < 256; y++) { - /* now shift it right by 8 bits */ - t = lrw->PC[x-1][y][15]; - for (z = 15; z > 0; z--) { - lrw->PC[x][y][z] = lrw->PC[x-1][y][z-1]; - } - lrw->PC[x][y][0] = gcm_shift_table[t<<1]; - lrw->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1]; - } - } -#endif - - /* generate first pad */ - return lrw_setiv(IV, 16, lrw); -} - - -#endif -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/lrw/lrw_test.c b/libtomcrypt/src/modes/lrw/lrw_test.c deleted file mode 100644 index 7762d47..0000000 --- a/libtomcrypt/src/modes/lrw/lrw_test.c +++ /dev/null @@ -1,134 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - @file lrw_test.c - LRW_MODE implementation, test LRW, Tom St Denis -*/ - -#ifdef LTC_LRW_MODE - -/** - Test LRW against specs - @return CRYPT_OK if goodly -*/ -int lrw_test(void) -{ -#ifndef LTC_TEST - return CRYPT_NOP; -#else - static const struct { - unsigned char key[16], tweak[16], IV[16], P[16], expected_tweak[16], C[16]; - } tests[] = { - -{ -{ 0x45, 0x62, 0xac, 0x25, 0xf8, 0x28, 0x17, 0x6d, 0x4c, 0x26, 0x84, 0x14, 0xb5, 0x68, 0x01, 0x85 }, -{ 0x25, 0x8e, 0x2a, 0x05, 0xe7, 0x3e, 0x9d, 0x03, 0xee, 0x5a, 0x83, 0x0c, 0xcc, 0x09, 0x4c, 0x87 }, -{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, -{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, -{ 0x25, 0x8e, 0x2a, 0x05, 0xe7, 0x3e, 0x9d, 0x03, 0xee, 0x5a, 0x83, 0x0c, 0xcc, 0x09, 0x4c, 0x87 }, -{ 0xf1, 0xb2, 0x73, 0xcd, 0x65, 0xa3, 0xdf, 0x5f, 0xe9, 0x5d, 0x48, 0x92, 0x54, 0x63, 0x4e, 0xb8 } -}, - -{ -{ 0x59, 0x70, 0x47, 0x14, 0xf5, 0x57, 0x47, 0x8c, 0xd7, 0x79, 0xe8, 0x0f, 0x54, 0x88, 0x79, 0x44 }, -{ 0x35, 0x23, 0xc2, 0xde, 0xc5, 0x69, 0x4f, 0xa8, 0x72, 0xa9, 0xac, 0xa7, 0x0b, 0x2b, 0xee, 0xbc }, -{ 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, -{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, -{ 0x1a, 0x91, 0xe1, 0x6f, 0x62, 0xb4, 0xa7, 0xd4, 0x39, 0x54, 0xd6, 0x53, 0x85, 0x95, 0xf7, 0x5e }, -{ 0x00, 0xc8, 0x2b, 0xae, 0x95, 0xbb, 0xcd, 0xe5, 0x27, 0x4f, 0x07, 0x69, 0xb2, 0x60, 0xe1, 0x36 }, -}, - -{ -{ 0x59, 0x70, 0x47, 0x14, 0xf5, 0x57, 0x47, 0x8c, 0xd7, 0x79, 0xe8, 0x0f, 0x54, 0x88, 0x79, 0x44 }, -{ 0x67, 0x53, 0xc9, 0x0c, 0xb7, 0xd8, 0xcd, 0xe5, 0x06, 0xa0, 0x47, 0x78, 0x1a, 0xad, 0x85, 0x11 }, -{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, -{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, -{ 0x1a, 0x91, 0xe1, 0x6f, 0x62, 0xb4, 0xa7, 0xd4, 0x39, 0x54, 0xd6, 0x53, 0x85, 0x95, 0xf7, 0x5e }, -{ 0x00, 0xc8, 0x2b, 0xae, 0x95, 0xbb, 0xcd, 0xe5, 0x27, 0x4f, 0x07, 0x69, 0xb2, 0x60, 0xe1, 0x36 }, -}, - -{ - -{ 0xd8, 0x2a, 0x91, 0x34, 0xb2, 0x6a, 0x56, 0x50, 0x30, 0xfe, 0x69, 0xe2, 0x37, 0x7f, 0x98, 0x47 }, -{ 0x4e, 0xb5, 0x5d, 0x31, 0x05, 0x97, 0x3a, 0x3f, 0x5e, 0x23, 0xda, 0xfb, 0x5a, 0x45, 0xd6, 0xc0 }, -{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 }, -{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, -{ 0x18, 0xc9, 0x1f, 0x6d, 0x60, 0x1a, 0x1a, 0x37, 0x5d, 0x0b, 0x0e, 0xf7, 0x3a, 0xd5, 0x74, 0xc4 }, -{ 0x76, 0x32, 0x21, 0x83, 0xed, 0x8f, 0xf1, 0x82, 0xf9, 0x59, 0x62, 0x03, 0x69, 0x0e, 0x5e, 0x01 }, - -} -}; - - int idx, err, x; - symmetric_LRW lrw; - unsigned char buf[2][16]; - - idx = find_cipher("aes"); - if (idx == -1) { - idx = find_cipher("rijndael"); - if (idx == -1) { - return CRYPT_NOP; - } - } - - for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { - /* schedule it */ - if ((err = lrw_start(idx, tests[x].IV, tests[x].key, 16, tests[x].tweak, 0, &lrw)) != CRYPT_OK) { - return err; - } - - /* check pad against expected tweak */ - if (compare_testvector(tests[x].expected_tweak, 16, lrw.pad, 16, "LRW Tweak", x)) { - lrw_done(&lrw); - return CRYPT_FAIL_TESTVECTOR; - } - - /* process block */ - if ((err = lrw_encrypt(tests[x].P, buf[0], 16, &lrw)) != CRYPT_OK) { - lrw_done(&lrw); - return err; - } - - if (compare_testvector(buf[0], 16, tests[x].C, 16, "LRW Encrypt", x)) { - lrw_done(&lrw); - return CRYPT_FAIL_TESTVECTOR; - } - - /* process block */ - if ((err = lrw_setiv(tests[x].IV, 16, &lrw)) != CRYPT_OK) { - lrw_done(&lrw); - return err; - } - - if ((err = lrw_decrypt(buf[0], buf[1], 16, &lrw)) != CRYPT_OK) { - lrw_done(&lrw); - return err; - } - - if (compare_testvector(buf[1], 16, tests[x].P, 16, "LRW Decrypt", x)) { - lrw_done(&lrw); - return CRYPT_FAIL_TESTVECTOR; - } - if ((err = lrw_done(&lrw)) != CRYPT_OK) { - return err; - } - } - return CRYPT_OK; -#endif -} - -#endif - - - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/xts/xts_decrypt.c b/libtomcrypt/src/modes/xts/xts_decrypt.c deleted file mode 100644 index 4580991..0000000 --- a/libtomcrypt/src/modes/xts/xts_decrypt.c +++ /dev/null @@ -1,156 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - 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) -{ - unsigned long x; - int err; - - /* tweak encrypt block i */ -#ifdef LTC_FAST - for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { - *(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]; - } -#endif - - 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_PTR_CAST(&P[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&T[x])); - } -#else - for (x = 0; x < 16; x++) { - P[x] = P[x] ^ T[x]; - } -#endif - - /* LFSR the tweak */ - 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, unsigned char *tweak, - symmetric_xts *xts) -{ - unsigned char PP[16], CC[16], T[16]; - unsigned long i, m, mo, lim; - int err; - - /* check inputs */ - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(tweak != NULL); - LTC_ARGCHK(xts != NULL); - - /* check if valid */ - if ((err = cipher_is_valid(xts->cipher)) != CRYPT_OK) { - return err; - } - - /* get number of blocks */ - m = ptlen >> 4; - mo = ptlen & 15; - - /* must have at least one full block */ - if (m == 0) { - return CRYPT_INVALID_ARG; - } - - if (mo == 0) { - lim = m; - } else { - lim = m - 1; - } - - 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) { - 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]; - } - for (; i < 16; i++) { - CC[i] = PP[i]; - } - - /* Pm-1 = Tweak uncrypt CC */ - 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 - -/* 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 deleted file mode 100644 index 558c043..0000000 --- a/libtomcrypt/src/modes/xts/xts_done.c +++ /dev/null @@ -1,31 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#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 -*/ -void xts_done(symmetric_xts *xts) -{ - LTC_ARGCHKVD(xts != NULL); - cipher_descriptor[xts->cipher].done(&xts->key1); - cipher_descriptor[xts->cipher].done(&xts->key2); -} - -#endif - -/* 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 deleted file mode 100644 index 787c302..0000000 --- a/libtomcrypt/src/modes/xts/xts_encrypt.c +++ /dev/null @@ -1,157 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - 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) -{ - unsigned long x; - int err; - - /* tweak encrypt block i */ -#ifdef LTC_FAST - for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { - *(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_PTR_CAST(&C[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&T[x])); - } -#else - for (x = 0; x < 16; x++) { - C[x] = C[x] ^ T[x]; - } -#endif - - /* LFSR the tweak */ - 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, unsigned char *tweak, - symmetric_xts *xts) -{ - unsigned char PP[16], CC[16], T[16]; - unsigned long i, m, mo, lim; - int err; - - /* check inputs */ - LTC_ARGCHK(pt != NULL); - LTC_ARGCHK(ct != NULL); - LTC_ARGCHK(tweak != NULL); - LTC_ARGCHK(xts != NULL); - - /* check if valid */ - if ((err = cipher_is_valid(xts->cipher)) != CRYPT_OK) { - return err; - } - - /* get number of blocks */ - m = ptlen >> 4; - mo = ptlen & 15; - - /* must have at least one full block */ - if (m == 0) { - return CRYPT_INVALID_ARG; - } - - if (mo == 0) { - lim = m; - } else { - lim = m - 1; - } - - 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) { - 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]; - } - - for (; i < 16; i++) { - PP[i] = CC[i]; - } - - /* Cm-1 = Tweak encrypt PP */ - 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 - -/* 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 deleted file mode 100644 index be0ac6a..0000000 --- a/libtomcrypt/src/modes/xts/xts_init.c +++ /dev/null @@ -1,61 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#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 - @param key2 The tweak encrypt key - @param keylen The length of the keys (each) in octets - @param num_rounds The number of rounds for the cipher (0 == default) - @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 err; - - /* check inputs */ - LTC_ARGCHK(key1 != NULL); - LTC_ARGCHK(key2 != NULL); - LTC_ARGCHK(xts != NULL); - - /* check if valid */ - if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { - return err; - } - - if (cipher_descriptor[cipher].block_length != 16) { - return CRYPT_INVALID_ARG; - } - - /* schedule the two ciphers */ - if ((err = cipher_descriptor[cipher].setup(key1, keylen, num_rounds, &xts->key1)) != CRYPT_OK) { - return err; - } - if ((err = cipher_descriptor[cipher].setup(key2, keylen, num_rounds, &xts->key2)) != CRYPT_OK) { - return err; - } - xts->cipher = cipher; - - return err; -} - -#endif - -/* 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 deleted file mode 100644 index 3fad22b..0000000 --- a/libtomcrypt/src/modes/xts/xts_mult_x.c +++ /dev/null @@ -1,39 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#include "tomcrypt.h" - -/** - Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects -*/ - -#ifdef LTC_XTS_MODE - -/** 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; - - 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 - -/* 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 deleted file mode 100644 index 347fb4b..0000000 --- a/libtomcrypt/src/modes/xts/xts_test.c +++ /dev/null @@ -1,306 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ -#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) -{ -#ifdef LTC_NO_TEST - return CRYPT_NOP; -#else - static const struct - { - int keylen; - unsigned char key1[32]; - unsigned char key2[32]; - ulong64 seqnum; - unsigned long PTLEN; - unsigned char PTX[512], CTX[512]; - } tests[] = { - -/* #1 32 byte key, 32 byte PTX */ -{ - 32, - { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, - { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, - 0, - 32, - { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, - { 0x91,0x7c,0xf6,0x9e,0xbd,0x68,0xb2,0xec,0x9b,0x9f,0xe9,0xa3,0xea,0xdd,0xa6,0x92,0xcd,0x43,0xd2,0xf5,0x95,0x98,0xed,0x85,0x8c,0x02,0xc2,0x65,0x2f,0xbf,0x92,0x2e }, -}, - -/* #2, 32 byte key, 32 byte PTX */ -{ - 32, - { 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 }, - { 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22 }, - CONST64(0x3333333333), - 32, - { 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44 }, - { 0xc4,0x54,0x18,0x5e,0x6a,0x16,0x93,0x6e,0x39,0x33,0x40,0x38,0xac,0xef,0x83,0x8b,0xfb,0x18,0x6f,0xff,0x74,0x80,0xad,0xc4,0x28,0x93,0x82,0xec,0xd6,0xd3,0x94,0xf0 }, -}, - -/* #5 from xts.7, 32 byte key, 32 byte PTX */ -{ - 32, - { 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 }, - { 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 }, - CONST64(0x123456789a), - 32, - { 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44 }, - { 0xb0,0x1f,0x86,0xf8,0xed,0xc1,0x86,0x37,0x06,0xfa,0x8a,0x42,0x53,0xe3,0x4f,0x28,0xaf,0x31,0x9d,0xe3,0x83,0x34,0x87,0x0f,0x4d,0xd1,0xf9,0x4c,0xbe,0x98,0x32,0xf1 }, -}, - -/* #4, 32 byte key, 512 byte PTX */ -{ - 32, - { 0x27,0x18,0x28,0x18,0x28,0x45,0x90,0x45,0x23,0x53,0x60,0x28,0x74,0x71,0x35,0x26 }, - { 0x31,0x41,0x59,0x26,0x53,0x58,0x97,0x93,0x23,0x84,0x62,0x64,0x33,0x83,0x27,0x95 }, - 0, - 512, - { -0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, -0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, -0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, -0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f, -0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, -0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, -0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, -0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff, -0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, -0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, -0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, -0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f, -0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, -0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, -0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, -0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff, - }, - { -0x27,0xa7,0x47,0x9b,0xef,0xa1,0xd4,0x76,0x48,0x9f,0x30,0x8c,0xd4,0xcf,0xa6,0xe2,0xa9,0x6e,0x4b,0xbe,0x32,0x08,0xff,0x25,0x28,0x7d,0xd3,0x81,0x96,0x16,0xe8,0x9c, -0xc7,0x8c,0xf7,0xf5,0xe5,0x43,0x44,0x5f,0x83,0x33,0xd8,0xfa,0x7f,0x56,0x00,0x00,0x05,0x27,0x9f,0xa5,0xd8,0xb5,0xe4,0xad,0x40,0xe7,0x36,0xdd,0xb4,0xd3,0x54,0x12, -0x32,0x80,0x63,0xfd,0x2a,0xab,0x53,0xe5,0xea,0x1e,0x0a,0x9f,0x33,0x25,0x00,0xa5,0xdf,0x94,0x87,0xd0,0x7a,0x5c,0x92,0xcc,0x51,0x2c,0x88,0x66,0xc7,0xe8,0x60,0xce, -0x93,0xfd,0xf1,0x66,0xa2,0x49,0x12,0xb4,0x22,0x97,0x61,0x46,0xae,0x20,0xce,0x84,0x6b,0xb7,0xdc,0x9b,0xa9,0x4a,0x76,0x7a,0xae,0xf2,0x0c,0x0d,0x61,0xad,0x02,0x65, -0x5e,0xa9,0x2d,0xc4,0xc4,0xe4,0x1a,0x89,0x52,0xc6,0x51,0xd3,0x31,0x74,0xbe,0x51,0xa1,0x0c,0x42,0x11,0x10,0xe6,0xd8,0x15,0x88,0xed,0xe8,0x21,0x03,0xa2,0x52,0xd8, -0xa7,0x50,0xe8,0x76,0x8d,0xef,0xff,0xed,0x91,0x22,0x81,0x0a,0xae,0xb9,0x9f,0x91,0x72,0xaf,0x82,0xb6,0x04,0xdc,0x4b,0x8e,0x51,0xbc,0xb0,0x82,0x35,0xa6,0xf4,0x34, -0x13,0x32,0xe4,0xca,0x60,0x48,0x2a,0x4b,0xa1,0xa0,0x3b,0x3e,0x65,0x00,0x8f,0xc5,0xda,0x76,0xb7,0x0b,0xf1,0x69,0x0d,0xb4,0xea,0xe2,0x9c,0x5f,0x1b,0xad,0xd0,0x3c, -0x5c,0xcf,0x2a,0x55,0xd7,0x05,0xdd,0xcd,0x86,0xd4,0x49,0x51,0x1c,0xeb,0x7e,0xc3,0x0b,0xf1,0x2b,0x1f,0xa3,0x5b,0x91,0x3f,0x9f,0x74,0x7a,0x8a,0xfd,0x1b,0x13,0x0e, -0x94,0xbf,0xf9,0x4e,0xff,0xd0,0x1a,0x91,0x73,0x5c,0xa1,0x72,0x6a,0xcd,0x0b,0x19,0x7c,0x4e,0x5b,0x03,0x39,0x36,0x97,0xe1,0x26,0x82,0x6f,0xb6,0xbb,0xde,0x8e,0xcc, -0x1e,0x08,0x29,0x85,0x16,0xe2,0xc9,0xed,0x03,0xff,0x3c,0x1b,0x78,0x60,0xf6,0xde,0x76,0xd4,0xce,0xcd,0x94,0xc8,0x11,0x98,0x55,0xef,0x52,0x97,0xca,0x67,0xe9,0xf3, -0xe7,0xff,0x72,0xb1,0xe9,0x97,0x85,0xca,0x0a,0x7e,0x77,0x20,0xc5,0xb3,0x6d,0xc6,0xd7,0x2c,0xac,0x95,0x74,0xc8,0xcb,0xbc,0x2f,0x80,0x1e,0x23,0xe5,0x6f,0xd3,0x44, -0xb0,0x7f,0x22,0x15,0x4b,0xeb,0xa0,0xf0,0x8c,0xe8,0x89,0x1e,0x64,0x3e,0xd9,0x95,0xc9,0x4d,0x9a,0x69,0xc9,0xf1,0xb5,0xf4,0x99,0x02,0x7a,0x78,0x57,0x2a,0xee,0xbd, -0x74,0xd2,0x0c,0xc3,0x98,0x81,0xc2,0x13,0xee,0x77,0x0b,0x10,0x10,0xe4,0xbe,0xa7,0x18,0x84,0x69,0x77,0xae,0x11,0x9f,0x7a,0x02,0x3a,0xb5,0x8c,0xca,0x0a,0xd7,0x52, -0xaf,0xe6,0x56,0xbb,0x3c,0x17,0x25,0x6a,0x9f,0x6e,0x9b,0xf1,0x9f,0xdd,0x5a,0x38,0xfc,0x82,0xbb,0xe8,0x72,0xc5,0x53,0x9e,0xdb,0x60,0x9e,0xf4,0xf7,0x9c,0x20,0x3e, -0xbb,0x14,0x0f,0x2e,0x58,0x3c,0xb2,0xad,0x15,0xb4,0xaa,0x5b,0x65,0x50,0x16,0xa8,0x44,0x92,0x77,0xdb,0xd4,0x77,0xef,0x2c,0x8d,0x6c,0x01,0x7d,0xb7,0x38,0xb1,0x8d, -0xeb,0x4a,0x42,0x7d,0x19,0x23,0xce,0x3f,0xf2,0x62,0x73,0x57,0x79,0xa4,0x18,0xf2,0x0a,0x28,0x2d,0xf9,0x20,0x14,0x7b,0xea,0xbe,0x42,0x1e,0xe5,0x31,0x9d,0x05,0x68, - } -}, - -/* #7, 32 byte key, 17 byte PTX */ -{ - 32, - { 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 }, - { 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 }, - CONST64(0x123456789a), - 17, - { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10 }, - { 0x6c,0x16,0x25,0xdb,0x46,0x71,0x52,0x2d,0x3d,0x75,0x99,0x60,0x1d,0xe7,0xca,0x09,0xed }, -}, - -/* #15, 32 byte key, 25 byte PTX */ -{ - 32, - { 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 }, - { 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 }, - CONST64(0x123456789a), - 25, - { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18 }, - { 0x8f,0x4d,0xcb,0xad,0x55,0x55,0x8d,0x7b,0x4e,0x01,0xd9,0x37,0x9c,0xd4,0xea,0x22,0xed,0xbf,0x9d,0xac,0xe4,0x5d,0x6f,0x6a,0x73 }, -}, - -/* #21, 32 byte key, 31 byte PTX */ -{ - 32, - { 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 }, - { 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 }, - CONST64(0x123456789a), - 31, - { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e }, - { 0xd0,0x5b,0xc0,0x90,0xa8,0xe0,0x4f,0x1b,0x3d,0x3e,0xcd,0xd5,0xba,0xec,0x0f,0xd4,0xed,0xbf,0x9d,0xac,0xe4,0x5d,0x6f,0x6a,0x73,0x06,0xe6,0x4b,0xe5,0xdd,0x82 }, -}, - -}; - unsigned char OUT[512], Torg[16], T[16]; - ulong64 seq; - symmetric_xts xts; - int i, j, k, err, idx; - unsigned long len; - - /* 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; - } - } - - 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 -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ -- 2.40.0