diff options
author | Matt Johnston <matt@ucc.asn.au> | 2017-06-24 17:50:50 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2017-06-24 17:50:50 +0800 |
commit | a79b61517bc7123250d0e2dc21dc18deccf0bb64 (patch) | |
tree | f95c80c6801abd286eaf370dd794859235d1be82 /libtomcrypt/src/mac/xcbc | |
parent | 99361f54ca77e0d1ff821c02d7d8df3a87aafde5 (diff) |
update to libtomcrypt 1.17 (with Dropbear changes)
Diffstat (limited to 'libtomcrypt/src/mac/xcbc')
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_done.c | 8 | ||||
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_file.c | 8 | ||||
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_init.c | 66 | ||||
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_memory.c | 8 | ||||
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c | 8 | ||||
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_process.c | 8 | ||||
-rw-r--r-- | libtomcrypt/src/mac/xcbc/xcbc_test.c | 8 |
7 files changed, 68 insertions, 46 deletions
diff --git a/libtomcrypt/src/mac/xcbc/xcbc_done.c b/libtomcrypt/src/mac/xcbc/xcbc_done.c index 687c24d..6640eeb 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_done.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_done.c @@ -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,7 +71,7 @@ int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen) #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_done.c,v $ */ -/* $Revision: 1.4 $ */ -/* $Date: 2006/11/07 03:23:46 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/libtomcrypt/src/mac/xcbc/xcbc_file.c b/libtomcrypt/src/mac/xcbc/xcbc_file.c index 4a8f7af..3d75b4e 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_file.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_file.c @@ -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" @@ -78,6 +78,6 @@ int xcbc_file(int cipher, #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_file.c,v $ */ -/* $Revision: 1.1 $ */ -/* $Date: 2006/11/03 01:56:41 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/libtomcrypt/src/mac/xcbc/xcbc_init.c b/libtomcrypt/src/mac/xcbc/xcbc_init.c index 3a0dcaf..94c9d79 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_init.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_init.c @@ -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" @@ -28,6 +28,7 @@ int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned l { int x, y, err; symmetric_key *skey; + unsigned long k1; LTC_ARGCHK(xcbc != NULL); LTC_ARGCHK(key != NULL); @@ -43,26 +44,45 @@ int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned l } #endif - /* schedule the user key */ - skey = XCALLOC(1, sizeof(*skey)); - if (skey == NULL) { - return CRYPT_MEM; - } + skey = NULL; - if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) { - goto done; - } + /* are we in pure XCBC mode with three keys? */ + if (keylen & LTC_XCBC_PURE) { + keylen &= ~LTC_XCBC_PURE; + + if (keylen < 2UL*cipher_descriptor[cipher].block_length) { + return CRYPT_INVALID_ARG; + } + + k1 = keylen - 2*cipher_descriptor[cipher].block_length; + XMEMCPY(xcbc->K[0], key, k1); + XMEMCPY(xcbc->K[1], key+k1, cipher_descriptor[cipher].block_length); + XMEMCPY(xcbc->K[2], key+k1 + cipher_descriptor[cipher].block_length, cipher_descriptor[cipher].block_length); + } else { + /* use the key expansion */ + k1 = cipher_descriptor[cipher].block_length; + + /* schedule the user key */ + skey = XCALLOC(1, sizeof(*skey)); + if (skey == NULL) { + return CRYPT_MEM; + } + + if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) { + goto done; + } - /* make the three keys */ - for (y = 0; y < 3; y++) { - for (x = 0; x < cipher_descriptor[cipher].block_length; x++) { - xcbc->K[y][x] = y + 1; - } - cipher_descriptor[cipher].ecb_encrypt(xcbc->K[y], xcbc->K[y], skey); + /* make the three keys */ + for (y = 0; y < 3; y++) { + for (x = 0; x < cipher_descriptor[cipher].block_length; x++) { + xcbc->K[y][x] = y + 1; + } + cipher_descriptor[cipher].ecb_encrypt(xcbc->K[y], xcbc->K[y], skey); + } } - + /* setup K1 */ - err = cipher_descriptor[cipher].setup(xcbc->K[0], cipher_descriptor[cipher].block_length, 0, &xcbc->key); + err = cipher_descriptor[cipher].setup(xcbc->K[0], k1, 0, &xcbc->key); /* setup struct */ zeromem(xcbc->IV, cipher_descriptor[cipher].block_length); @@ -71,16 +91,18 @@ int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned l xcbc->buflen = 0; done: cipher_descriptor[cipher].done(skey); + if (skey != NULL) { #ifdef LTC_CLEAN_STACK - zeromem(skey, sizeof(*skey)); + zeromem(skey, sizeof(*skey)); #endif - XFREE(skey); + XFREE(skey); + } return err; } #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_init.c,v $ */ -/* $Revision: 1.4 $ */ -/* $Date: 2006/11/07 03:23:46 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/libtomcrypt/src/mac/xcbc/xcbc_memory.c b/libtomcrypt/src/mac/xcbc/xcbc_memory.c index 1826b6b..124817a 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_memory.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_memory.c @@ -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" @@ -66,6 +66,6 @@ done: #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_memory.c,v $ */ -/* $Revision: 1.4 $ */ -/* $Date: 2006/11/21 23:02:42 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c b/libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c index ccae9de..a237907 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c @@ -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" #include <stdarg.h> @@ -85,6 +85,6 @@ LBL_ERR: #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_memory_multi.c,v $ */ -/* $Revision: 1.1 $ */ -/* $Date: 2006/11/03 01:53:25 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/libtomcrypt/src/mac/xcbc/xcbc_process.c b/libtomcrypt/src/mac/xcbc/xcbc_process.c index 4dd63b5..46ab4a0 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_process.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_process.c @@ -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" @@ -69,7 +69,7 @@ int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen) #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_process.c,v $ */ -/* $Revision: 1.9 $ */ -/* $Date: 2006/11/09 22:43:52 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/libtomcrypt/src/mac/xcbc/xcbc_test.c b/libtomcrypt/src/mac/xcbc/xcbc_test.c index 2c56c0a..1bd5840 100644 --- a/libtomcrypt/src/mac/xcbc/xcbc_test.c +++ b/libtomcrypt/src/mac/xcbc/xcbc_test.c @@ -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" @@ -122,7 +122,7 @@ int xcbc_test(void) #endif -/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_test.c,v $ */ -/* $Revision: 1.5 $ */ -/* $Date: 2006/11/21 23:02:42 $ */ +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ |