diff options
Diffstat (limited to 'libtomcrypt/src/mac/f9')
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_done.c | 10 | ||||
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_file.c | 66 | ||||
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_init.c | 12 | ||||
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_memory.c | 12 | ||||
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_memory_multi.c | 18 | ||||
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_process.c | 26 | ||||
-rw-r--r-- | libtomcrypt/src/mac/f9/f9_test.c | 14 |
7 files changed, 77 insertions, 81 deletions
diff --git a/libtomcrypt/src/mac/f9/f9_done.c b/libtomcrypt/src/mac/f9/f9_done.c index 8da4c73..8d2ccb0 100644 --- a/libtomcrypt/src/mac/f9/f9_done.c +++ b/libtomcrypt/src/mac/f9/f9_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" @@ -62,7 +60,7 @@ int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen) out[x] = f9->ACC[x]; } *outlen = x; - + #ifdef LTC_CLEAN_STACK zeromem(f9, sizeof(*f9)); #endif @@ -71,7 +69,7 @@ int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen) #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/f9/f9_file.c b/libtomcrypt/src/mac/f9/f9_file.c index 88216a9..a6e6532 100644 --- a/libtomcrypt/src/mac/f9/f9_file.c +++ b/libtomcrypt/src/mac/f9/f9_file.c @@ -5,12 +5,10 @@ * * 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" -/** +/** @file f9_file.c f9 support, process a file, Tom St Denis */ @@ -22,62 +20,72 @@ @param cipher The index of the cipher desired @param key The secret key @param keylen The length of the secret key (octets) - @param filename The name of the file you wish to f9 + @param fname The name of the file you wish to f9 @param out [out] Where the authentication tag is to be stored @param outlen [in/out] The max size and resulting size of the authentication tag @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled */ int f9_file(int cipher, const unsigned char *key, unsigned long keylen, - const char *filename, + const char *fname, unsigned char *out, unsigned long *outlen) { #ifdef LTC_NO_FILE return CRYPT_NOP; #else - int err, x; + size_t x; + int err; f9_state f9; FILE *in; - unsigned char buf[512]; + unsigned char *buf; - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(filename != NULL); - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); + LTC_ARGCHK(key != NULL); + LTC_ARGCHK(fname != NULL); + LTC_ARGCHK(out != NULL); + LTC_ARGCHK(outlen != NULL); - in = fopen(filename, "rb"); - if (in == NULL) { - return CRYPT_FILE_NOTFOUND; + if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) { + return CRYPT_MEM; } if ((err = f9_init(&f9, cipher, key, keylen)) != CRYPT_OK) { - fclose(in); - return err; + goto LBL_ERR; + } + + in = fopen(fname, "rb"); + if (in == NULL) { + err = CRYPT_FILE_NOTFOUND; + goto LBL_ERR; } do { - x = fread(buf, 1, sizeof(buf), in); - if ((err = f9_process(&f9, buf, x)) != CRYPT_OK) { + x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in); + if ((err = f9_process(&f9, buf, (unsigned long)x)) != CRYPT_OK) { fclose(in); - return err; + goto LBL_CLEANBUF; } - } while (x == sizeof(buf)); - fclose(in); + } while (x == LTC_FILE_READ_BUFSIZE); - if ((err = f9_done(&f9, out, outlen)) != CRYPT_OK) { - return err; + if (fclose(in) != 0) { + err = CRYPT_ERROR; + goto LBL_CLEANBUF; } + err = f9_done(&f9, out, outlen); + +LBL_CLEANBUF: + zeromem(buf, LTC_FILE_READ_BUFSIZE); +LBL_ERR: #ifdef LTC_CLEAN_STACK - zeromem(buf, sizeof(buf)); + zeromem(&f9, sizeof(f9_state)); #endif - - return CRYPT_OK; + XFREE(buf); + return err; #endif } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/f9/f9_init.c b/libtomcrypt/src/mac/f9/f9_init.c index b6b878f..ba59b20 100644 --- a/libtomcrypt/src/mac/f9/f9_init.c +++ b/libtomcrypt/src/mac/f9/f9_init.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" @@ -45,12 +43,12 @@ int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long ke if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &f9->key)) != CRYPT_OK) { goto done; } - + /* make the second key */ for (x = 0; (unsigned)x < keylen; x++) { f9->akey[x] = key[x] ^ 0xAA; } - + /* setup struct */ zeromem(f9->IV, cipher_descriptor[cipher].block_length); zeromem(f9->ACC, cipher_descriptor[cipher].block_length); @@ -64,7 +62,7 @@ done: #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/f9/f9_memory.c b/libtomcrypt/src/mac/f9/f9_memory.c index 0850dc3..70c694b 100644 --- a/libtomcrypt/src/mac/f9/f9_memory.c +++ b/libtomcrypt/src/mac/f9/f9_memory.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" @@ -17,7 +15,7 @@ #ifdef LTC_F9_MODE -/** f9-MAC a block of memory +/** f9-MAC a block of memory @param cipher Index of cipher to use @param key [in] Secret key @param keylen Length of key in octets @@ -27,7 +25,7 @@ @param outlen [in/out] Output size and final tag size Return CRYPT_OK on success. */ -int f9_memory(int cipher, +int f9_memory(int cipher, const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen) @@ -66,6 +64,6 @@ done: #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/f9/f9_memory_multi.c b/libtomcrypt/src/mac/f9/f9_memory_multi.c index 7a13ff9..2c1d31a 100644 --- a/libtomcrypt/src/mac/f9/f9_memory_multi.c +++ b/libtomcrypt/src/mac/f9/f9_memory_multi.c @@ -5,13 +5,11 @@ * * 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" #include <stdarg.h> -/** +/** @file f9_memory_multi.c f9 support, process multiple blocks of memory, Tom St Denis */ @@ -19,7 +17,7 @@ #ifdef LTC_F9_MODE /** - f9 multiple blocks of memory + f9 multiple blocks of memory @param cipher The index of the desired cipher @param key The secret key @param keylen The length of the secret key (octets) @@ -30,7 +28,7 @@ @param ... tuples of (data,len) pairs to f9, terminated with a (NULL,x) (x=don't care) @return CRYPT_OK if successful */ -int f9_memory_multi(int cipher, +int f9_memory_multi(int cipher, const unsigned char *key, unsigned long keylen, unsigned char *out, unsigned long *outlen, const unsigned char *in, unsigned long inlen, ...) @@ -57,7 +55,7 @@ int f9_memory_multi(int cipher, goto LBL_ERR; } va_start(args, inlen); - curptr = in; + curptr = in; curlen = inlen; for (;;) { /* process buf */ @@ -80,11 +78,11 @@ LBL_ERR: #endif XFREE(f9); va_end(args); - return err; + return err; } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/f9/f9_process.c b/libtomcrypt/src/mac/f9/f9_process.c index bf54d71..ba4d39f 100644 --- a/libtomcrypt/src/mac/f9/f9_process.c +++ b/libtomcrypt/src/mac/f9/f9_process.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" @@ -44,35 +42,35 @@ int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen) if (f9->buflen == 0) { while (inlen >= (unsigned long)f9->blocksize) { for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) { - *((LTC_FAST_TYPE*)&(f9->IV[x])) ^= *((LTC_FAST_TYPE*)&(in[x])); + *(LTC_FAST_TYPE_PTR_CAST(&(f9->IV[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(in[x]))); } cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key); for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) { - *((LTC_FAST_TYPE*)&(f9->ACC[x])) ^= *((LTC_FAST_TYPE*)&(f9->IV[x])); + *(LTC_FAST_TYPE_PTR_CAST(&(f9->ACC[x]))) ^= *(LTC_FAST_TYPE_PTR_CAST(&(f9->IV[x]))); } in += f9->blocksize; inlen -= f9->blocksize; } - } + } #endif while (inlen) { - if (f9->buflen == f9->blocksize) { + if (f9->buflen == f9->blocksize) { cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key); for (x = 0; x < f9->blocksize; x++) { f9->ACC[x] ^= f9->IV[x]; } f9->buflen = 0; - } - f9->IV[f9->buflen++] ^= *in++; - --inlen; - } - return CRYPT_OK; + } + f9->IV[f9->buflen++] ^= *in++; + --inlen; + } + return CRYPT_OK; } #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/f9/f9_test.c b/libtomcrypt/src/mac/f9/f9_test.c index b92c630..ca23acc 100644 --- a/libtomcrypt/src/mac/f9/f9_test.c +++ b/libtomcrypt/src/mac/f9/f9_test.c @@ -5,14 +5,12 @@ * * 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" /** @file f9_test.c - f9 Support, Test F9 mode + f9 Support, Test F9 mode */ #ifdef LTC_F9_MODE @@ -39,7 +37,7 @@ int f9_test(void) { 105, { 0x83, 0xFD, 0x23, 0xA2, 0x44, 0xA7, 0x4C, 0xF3, 0x58, 0xDA, 0x30, 0x19, 0xF1, 0x72, 0x26, 0x35 }, - { 0x36, 0xAF, 0x61, 0x44, 0x4F, 0x30, 0x2A, 0xD2, + { 0x36, 0xAF, 0x61, 0x44, 0x4F, 0x30, 0x2A, 0xD2, 0x35, 0xC6, 0x87, 0x16, 0x63, 0x3C, 0x66, 0xFB, 0x75, 0x0C, 0x26, 0x68, 0x65, 0xD5, 0x3C, 0x11, 0xEA, 0x05, 0xB1, 0xE9, 0xFA, 0x49, 0xC8, 0x39, 0x8D, 0x48, 0xE1, 0xEF, 0xA5, 0x90, 0x9D, 0x39, 0x47, 0x90, 0x28, 0x37, 0xF5, 0xAE, 0x96, 0xD5, 0xA0, 0x5B, 0xC8, 0xD6, 0x1C, 0xA8, 0xDB, 0xEF, 0x1B, 0x13, 0xA4, 0xB4, 0xAB, 0xFE, 0x4F, 0xB1, 0x00, 0x60, 0x45, 0xB6, 0x74, 0xBB, 0x54, 0x72, 0x93, 0x04, 0xC3, 0x82, 0xBE, 0x53, 0xA5, 0xAF, 0x05, 0x55, 0x61, 0x76, 0xF6, 0xEA, 0xA2, 0xEF, 0x1D, 0x05, 0xE4, 0xB0, 0x83, 0x18, 0x1E, 0xE6, 0x74, 0xCD, 0xA5, 0xA4, 0x85, 0xF7, 0x4D, 0x7A, @@ -61,7 +59,7 @@ int f9_test(void) if ((err = f9_memory(idx, tests[x].K, 16, tests[x].M, tests[x].msglen, T, &taglen)) != CRYPT_OK) { return err; } - if (taglen != 4 || XMEMCMP(T, tests[x].T, 4)) { + if (compare_testvector(T, taglen, tests[x].T, 4, "F9", x)) { return CRYPT_FAIL_TESTVECTOR; } } @@ -72,7 +70,7 @@ int f9_test(void) #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ |