mirror of
https://github.com/clearml/dropbear
synced 2025-06-26 18:17:32 +00:00
update to libtomcrypt 1.17 (with Dropbear changes)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -92,6 +92,6 @@ int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_decrypt.c,v $ */
|
||||
/* $Revision: 1.15 $ */
|
||||
/* $Date: 2006/11/21 00:18:23 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int cbc_done(symmetric_CBC *cbc)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_done.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -93,6 +93,6 @@ int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_encrypt.c,v $ */
|
||||
/* $Revision: 1.13 $ */
|
||||
/* $Date: 2006/11/21 00:18:23 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -41,6 +41,6 @@ int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_getiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -39,6 +39,6 @@ int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc)
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_setiv.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -57,6 +57,6 @@ int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_start.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -62,6 +62,6 @@ int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_decrypt.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/26 01:45:14 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int cfb_done(symmetric_CFB *cfb)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_done.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -60,6 +60,6 @@ int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_encrypt.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/26 01:45:14 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -41,6 +41,6 @@ int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_getiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -47,6 +47,6 @@ int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb)
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_setiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -60,6 +60,6 @@ int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_start.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_decrypt.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int ctr_done(symmetric_CTR *ctr)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_done.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -64,7 +64,7 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
/* increment counter */
|
||||
if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
|
||||
/* little-endian */
|
||||
for (x = 0; x < ctr->blocklen; x++) {
|
||||
for (x = 0; x < ctr->ctrlen; x++) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
@@ -72,7 +72,7 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
}
|
||||
} else {
|
||||
/* big-endian */
|
||||
for (x = ctr->blocklen-1; x >= 0; x--) {
|
||||
for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
@@ -107,6 +107,6 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_encrypt.c,v $ */
|
||||
/* $Revision: 1.20 $ */
|
||||
/* $Date: 2006/11/21 00:18:23 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -41,6 +41,6 @@ int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_getiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -51,6 +51,6 @@ int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_setiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:46:46 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -46,6 +46,16 @@ int ctr_start( int cipher,
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ctrlen == counter width */
|
||||
ctr->ctrlen = (ctr_mode & 255) ? (ctr_mode & 255) : cipher_descriptor[cipher].block_length;
|
||||
if (ctr->ctrlen > cipher_descriptor[cipher].block_length) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((ctr_mode & 0x1000) == CTR_COUNTER_BIG_ENDIAN) {
|
||||
ctr->ctrlen = cipher_descriptor[cipher].block_length - ctr->ctrlen;
|
||||
}
|
||||
|
||||
/* setup cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
@@ -55,7 +65,7 @@ int ctr_start( int cipher,
|
||||
ctr->blocklen = cipher_descriptor[cipher].block_length;
|
||||
ctr->cipher = cipher;
|
||||
ctr->padlen = 0;
|
||||
ctr->mode = ctr_mode & 1;
|
||||
ctr->mode = ctr_mode & 0x1000;
|
||||
for (x = 0; x < ctr->blocklen; x++) {
|
||||
ctr->ctr[x] = IV[x];
|
||||
}
|
||||
@@ -64,7 +74,7 @@ int ctr_start( int cipher,
|
||||
/* increment the IV as per RFC 3686 */
|
||||
if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
|
||||
/* little-endian */
|
||||
for (x = 0; x < ctr->blocklen; x++) {
|
||||
for (x = 0; x < ctr->ctrlen; x++) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
@@ -72,7 +82,7 @@ int ctr_start( int cipher,
|
||||
}
|
||||
} else {
|
||||
/* big-endian */
|
||||
for (x = ctr->blocklen-1; x >= 0; x--) {
|
||||
for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
@@ -86,6 +96,6 @@ int ctr_start( int cipher,
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_start.c,v $ */
|
||||
/* $Revision: 1.11 $ */
|
||||
/* $Date: 2006/11/05 01:46:35 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -77,9 +77,9 @@ int ctr_test(void)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_test.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2006/11/05 02:06:49 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -56,6 +56,6 @@ int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_decrypt.c,v $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int ecb_done(symmetric_ECB *ecb)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_done.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -56,6 +56,6 @@ int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_encrypt.c,v $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -43,6 +43,6 @@ int ecb_start(int cipher, const unsigned char *key, int keylen, int num_rounds,
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_start.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -38,6 +38,6 @@ int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, sy
|
||||
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_decrypt.c,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2006/06/16 22:49:25 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int f8_done(symmetric_F8 *f8)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_done.c,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2006/06/16 22:49:25 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -98,6 +98,6 @@ int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, sy
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_encrypt.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/11/05 04:16:32 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -41,6 +41,6 @@ int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_getiv.c,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2006/06/16 22:49:25 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -47,6 +47,6 @@ int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8)
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_setiv.c,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2006/06/16 22:49:25 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -93,6 +93,6 @@ int f8_start( int cipher, const unsigned char *IV,
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_start.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/05 01:36:43 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -71,6 +71,6 @@ int f8_test_mode(void)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/f8/f8_test_mode.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2006/11/13 11:55:25 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -46,6 +46,6 @@ int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_decrypt.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int lrw_done(symmetric_LRW *lrw)
|
||||
}
|
||||
|
||||
#endif
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_done.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -45,6 +45,6 @@ int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
|
||||
|
||||
#endif
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_encrypt.c,v $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -40,6 +40,6 @@ int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw)
|
||||
}
|
||||
|
||||
#endif
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_getiv.c,v $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -115,6 +115,6 @@ int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, i
|
||||
}
|
||||
|
||||
#endif
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_process.c,v $ */
|
||||
/* $Revision: 1.10 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -74,6 +74,6 @@ int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
|
||||
|
||||
|
||||
#endif
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_setiv.c,v $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -98,6 +98,6 @@ int lrw_start( int cipher,
|
||||
|
||||
|
||||
#endif
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_start.c,v $ */
|
||||
/* $Revision: 1.11 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -131,6 +131,6 @@ int lrw_test(void)
|
||||
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_test.c,v $ */
|
||||
/* $Revision: 1.11 $ */
|
||||
/* $Date: 2006/06/29 01:53:13 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -38,6 +38,6 @@ int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_decrypt.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,6 +37,6 @@ int ofb_done(symmetric_OFB *ofb)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_done.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -55,6 +55,6 @@ int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_encrypt.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/26 01:45:14 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -41,6 +41,6 @@ int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_getiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -47,6 +47,6 @@ int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb)
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_setiv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -55,6 +55,6 @@ int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_start.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/29 01:51:34 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
141
libtomcrypt/src/modes/xts/xts_decrypt.c
Normal file
141
libtomcrypt/src/modes/xts/xts_decrypt.c
Normal file
@@ -0,0 +1,141 @@
|
||||
/* 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.
|
||||
*
|
||||
* 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
|
||||
|
||||
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*)&P[x]) = *((LTC_FAST_TYPE*)&C[x]) ^ *((LTC_FAST_TYPE*)&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*)&P[x]) ^= *((LTC_FAST_TYPE*)&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,
|
||||
const 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;
|
||||
}
|
||||
|
||||
/* 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 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;
|
||||
}
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
34
libtomcrypt/src/modes/xts/xts_done.c
Normal file
34
libtomcrypt/src/modes/xts/xts_done.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
142
libtomcrypt/src/modes/xts/xts_encrypt.c
Normal file
142
libtomcrypt/src/modes/xts/xts_encrypt.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/* 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.
|
||||
*
|
||||
* 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
|
||||
|
||||
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*)&C[x]) = *((LTC_FAST_TYPE*)&P[x]) ^ *((LTC_FAST_TYPE*)&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]);
|
||||
}
|
||||
#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,
|
||||
const 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;
|
||||
}
|
||||
|
||||
/* 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 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;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
69
libtomcrypt/src/modes/xts/xts_init.c
Normal file
69
libtomcrypt/src/modes/xts/xts_init.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* 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.
|
||||
*
|
||||
* 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
|
||||
@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
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
42
libtomcrypt/src/modes/xts/xts_mult_x.c
Normal file
42
libtomcrypt/src/modes/xts/xts_mult_x.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* 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.
|
||||
*
|
||||
* 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
|
||||
@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
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
199
libtomcrypt/src/modes/xts/xts_test.c
Normal file
199
libtomcrypt/src/modes/xts/xts_test.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/* 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.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
/**
|
||||
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], T[16];
|
||||
ulong64 seq;
|
||||
symmetric_xts xts;
|
||||
int i, err, idx;
|
||||
|
||||
/* 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 (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);
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
Reference in New Issue
Block a user