diff options
author | Matt Johnston <matt@ucc.asn.au> | 2018-02-17 19:29:51 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2018-02-17 19:29:51 +0800 |
commit | 7e8094d53a1c01ac671156ff2e67157b64d01a3a (patch) | |
tree | c88345f5bdd118eb9414dff5ab5c307bb1806c57 /libtomcrypt/src/modes/ctr | |
parent | f7a664f127d3dfde0e7c7a9ca74b1d14f9a2f983 (diff) | |
parent | f042eb41ab0d31f8ba0c5ccc9c848ad01f08f986 (diff) |
merge from main
--HG--
branch : fuzz
Diffstat (limited to 'libtomcrypt/src/modes/ctr')
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_decrypt.c | 8 | ||||
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_done.c | 10 | ||||
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_encrypt.c | 20 | ||||
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_getiv.c | 14 | ||||
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_setiv.c | 22 | ||||
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_start.c | 20 | ||||
-rw-r--r-- | libtomcrypt/src/modes/ctr/ctr_test.c | 12 |
7 files changed, 47 insertions, 59 deletions
diff --git a/libtomcrypt/src/modes/ctr/ctr_decrypt.c b/libtomcrypt/src/modes/ctr/ctr_decrypt.c index 9537249..5008089 100644 --- a/libtomcrypt/src/modes/ctr/ctr_decrypt.c +++ b/libtomcrypt/src/modes/ctr/ctr_decrypt.c @@ -5,8 +5,6 @@ * * 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" @@ -37,6 +35,6 @@ int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/ctr/ctr_done.c b/libtomcrypt/src/modes/ctr/ctr_done.c index 26391fd..3de13c2 100644 --- a/libtomcrypt/src/modes/ctr/ctr_done.c +++ b/libtomcrypt/src/modes/ctr/ctr_done.c @@ -5,8 +5,6 @@ * * 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" @@ -33,10 +31,10 @@ int ctr_done(symmetric_CTR *ctr) return CRYPT_OK; } - + #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/ctr/ctr_encrypt.c b/libtomcrypt/src/modes/ctr/ctr_encrypt.c index 0b08359..7319cf5 100644 --- a/libtomcrypt/src/modes/ctr/ctr_encrypt.c +++ b/libtomcrypt/src/modes/ctr/ctr_encrypt.c @@ -5,8 +5,6 @@ * * 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" @@ -37,7 +35,7 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) { return err; } - + /* is blocklen/padlen valid? */ if (ctr->blocklen < 1 || ctr->blocklen > (int)sizeof(ctr->ctr) || ctr->padlen < 0 || ctr->padlen > (int)sizeof(ctr->pad)) { @@ -49,12 +47,14 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s return CRYPT_INVALID_ARG; } #endif - + /* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */ if ((ctr->padlen == ctr->blocklen) && cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL && (len >= (unsigned long)ctr->blocklen)) { if ((err = cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key)) != CRYPT_OK) { return err; } + pt += (len / ctr->blocklen) * ctr->blocklen; + ct += (len / ctr->blocklen) * ctr->blocklen; len %= ctr->blocklen; } @@ -89,8 +89,8 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s #ifdef LTC_FAST if (ctr->padlen == 0 && len >= (unsigned long)ctr->blocklen) { for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) { - *((LTC_FAST_TYPE*)((unsigned char *)ct + x)) = *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) ^ - *((LTC_FAST_TYPE*)((unsigned char *)ctr->pad + x)); + *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) ^ + *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ctr->pad + x)); } pt += ctr->blocklen; ct += ctr->blocklen; @@ -98,7 +98,7 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s ctr->padlen = ctr->blocklen; continue; } -#endif +#endif *ct++ = *pt++ ^ ctr->pad[ctr->padlen++]; --len; } @@ -107,6 +107,6 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/ctr/ctr_getiv.c b/libtomcrypt/src/modes/ctr/ctr_getiv.c index 6242323..cbf92db 100644 --- a/libtomcrypt/src/modes/ctr/ctr_getiv.c +++ b/libtomcrypt/src/modes/ctr/ctr_getiv.c @@ -5,8 +5,6 @@ * * 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" @@ -18,9 +16,9 @@ #ifdef LTC_CTR_MODE /** - Get the current initial vector - @param IV [out] The destination of the initial vector - @param len [in/out] The max size and resulting size of the initial vector + 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 ctr The CTR state @return CRYPT_OK if successful */ @@ -41,6 +39,6 @@ int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr) #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/ctr/ctr_setiv.c b/libtomcrypt/src/modes/ctr/ctr_setiv.c index 56a3c97..64d73a1 100644 --- a/libtomcrypt/src/modes/ctr/ctr_setiv.c +++ b/libtomcrypt/src/modes/ctr/ctr_setiv.c @@ -5,8 +5,6 @@ * * 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" @@ -14,12 +12,12 @@ @file ctr_setiv.c CTR implementation, set IV, Tom St Denis */ - + #ifdef LTC_CTR_MODE /** - Set an initial vector - @param IV The initial vector + Set an initialization vector + @param IV The initialization vector @param len The length of the vector (in octets) @param ctr The CTR state @return CRYPT_OK if successful @@ -27,7 +25,7 @@ int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr) { int err; - + LTC_ARGCHK(IV != NULL); LTC_ARGCHK(ctr != NULL); @@ -35,22 +33,22 @@ int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr) if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) { return err; } - + if (len != (unsigned long)ctr->blocklen) { return CRYPT_INVALID_ARG; } /* set IV */ XMEMCPY(ctr->ctr, IV, len); - + /* force next block */ ctr->padlen = 0; return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key); } -#endif +#endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/ctr/ctr_start.c b/libtomcrypt/src/modes/ctr/ctr_start.c index b27bed0..039fdd6 100644 --- a/libtomcrypt/src/modes/ctr/ctr_start.c +++ b/libtomcrypt/src/modes/ctr/ctr_start.c @@ -5,8 +5,6 @@ * * 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" @@ -21,17 +19,17 @@ /** Initialize a CTR context @param cipher The index of the cipher desired - @param IV The initial vector - @param key The secret key + @param IV The initialization vector + @param key The secret key @param keylen The length of the secret key (octets) @param num_rounds Number of rounds in the cipher desired (0 for default) @param ctr_mode The counter mode (CTR_COUNTER_LITTLE_ENDIAN or CTR_COUNTER_BIG_ENDIAN) @param ctr The CTR state to initialize @return CRYPT_OK if successful */ -int ctr_start( int cipher, - const unsigned char *IV, - const unsigned char *key, int keylen, +int ctr_start( int cipher, + const unsigned char *IV, + const unsigned char *key, int keylen, int num_rounds, int ctr_mode, symmetric_CTR *ctr) { @@ -91,11 +89,11 @@ int ctr_start( int cipher, } } - return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key); + return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key); } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/modes/ctr/ctr_test.c b/libtomcrypt/src/modes/ctr/ctr_test.c index 9962afd..878d425 100644 --- a/libtomcrypt/src/modes/ctr/ctr_test.c +++ b/libtomcrypt/src/modes/ctr/ctr_test.c @@ -5,8 +5,6 @@ * * 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" @@ -52,7 +50,7 @@ int ctr_test(void) unsigned char buf[64]; symmetric_CTR ctr; - /* AES can be under rijndael or aes... try to find it */ + /* AES can be under rijndael or aes... try to find it */ if ((idx = find_cipher("aes")) == -1) { if ((idx = find_cipher("rijndael")) == -1) { return CRYPT_NOP; @@ -67,7 +65,7 @@ int ctr_test(void) return err; } ctr_done(&ctr); - if (XMEMCMP(buf, tests[x].ct, tests[x].msglen)) { + if (compare_testvector(buf, tests[x].msglen, tests[x].ct, tests[x].msglen, "CTR", x)) { return CRYPT_FAIL_TESTVECTOR; } } @@ -77,9 +75,9 @@ int ctr_test(void) #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ |