From: Nathan Wagner Date: Sun, 7 Jul 2019 03:13:27 +0000 (+0000) Subject: remove pmac and pelican X-Git-Url: https://pd.if.org/git/?a=commitdiff_plain;ds=sidebyside;h=980fccf87eb6c14113e601b2f8135d904a5e70f6;hp=3a94b002c8fb76df827cb7f1785e4ce313186561;p=zpackage remove pmac and pelican --- diff --git a/Makefile b/Makefile index 1985a80..c4791a6 100644 --- a/Makefile +++ b/Makefile @@ -439,18 +439,6 @@ LTCOBJ= \ mac/omac/omac_process.o \ misc/crypt/crypt_find_prng.o \ mac/omac/omac_test.o \ - mac/pelican/pelican.o \ - mac/pelican/pelican_memory.o \ - mac/pelican/pelican_test.o \ - mac/pmac/pmac_done.o \ - mac/pmac/pmac_file.o \ - mac/pmac/pmac_init.o \ - mac/pmac/pmac_memory.o \ - mac/pmac/pmac_memory_multi.o \ - mac/pmac/pmac_ntz.o \ - mac/pmac/pmac_process.o \ - mac/pmac/pmac_shift_xor.o \ - mac/pmac/pmac_test.o \ mac/poly1305/poly1305.o \ mac/poly1305/poly1305_file.o \ mac/poly1305/poly1305_memory.o \ diff --git a/libtomcrypt/src/mac/pelican/pelican.c b/libtomcrypt/src/mac/pelican/pelican.c deleted file mode 100644 index 6a4dde6..0000000 --- a/libtomcrypt/src/mac/pelican/pelican.c +++ /dev/null @@ -1,164 +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 pelican.c - Pelican MAC, initialize state, by Tom St Denis -*/ - -#ifdef LTC_PELICAN - -#define __LTC_AES_TAB_C__ -#define ENCRYPT_ONLY -#define PELI_TAB -#include "../../ciphers/aes/aes_tab.c" - -/** - Initialize a Pelican state - @param pelmac The Pelican state to initialize - @param key The secret key - @param keylen The length of the secret key (octets) - @return CRYPT_OK if successful -*/ -int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen) -{ - int err; - - LTC_ARGCHK(pelmac != NULL); - LTC_ARGCHK(key != NULL); - -#ifdef LTC_FAST - if (16 % sizeof(LTC_FAST_TYPE)) { - return CRYPT_INVALID_ARG; - } -#endif - - if ((err = aes_setup(key, keylen, 0, &pelmac->K)) != CRYPT_OK) { - return err; - } - - zeromem(pelmac->state, 16); - aes_ecb_encrypt(pelmac->state, pelmac->state, &pelmac->K); - pelmac->buflen = 0; - - return CRYPT_OK; -} - -static void _four_rounds(pelican_state *pelmac) -{ - ulong32 s0, s1, s2, s3, t0, t1, t2, t3; - int r; - - LOAD32H(s0, pelmac->state ); - LOAD32H(s1, pelmac->state + 4); - LOAD32H(s2, pelmac->state + 8); - LOAD32H(s3, pelmac->state + 12); - for (r = 0; r < 4; r++) { - t0 = - Te0(byte(s0, 3)) ^ - Te1(byte(s1, 2)) ^ - Te2(byte(s2, 1)) ^ - Te3(byte(s3, 0)); - t1 = - Te0(byte(s1, 3)) ^ - Te1(byte(s2, 2)) ^ - Te2(byte(s3, 1)) ^ - Te3(byte(s0, 0)); - t2 = - Te0(byte(s2, 3)) ^ - Te1(byte(s3, 2)) ^ - Te2(byte(s0, 1)) ^ - Te3(byte(s1, 0)); - t3 = - Te0(byte(s3, 3)) ^ - Te1(byte(s0, 2)) ^ - Te2(byte(s1, 1)) ^ - Te3(byte(s2, 0)); - s0 = t0; s1 = t1; s2 = t2; s3 = t3; - } - STORE32H(s0, pelmac->state ); - STORE32H(s1, pelmac->state + 4); - STORE32H(s2, pelmac->state + 8); - STORE32H(s3, pelmac->state + 12); -} - -/** - Process a block of text through Pelican - @param pelmac The Pelican MAC state - @param in The input - @param inlen The length input (octets) - @return CRYPT_OK on success - */ -int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen) -{ - - LTC_ARGCHK(pelmac != NULL); - LTC_ARGCHK(in != NULL); - - /* check range */ - if (pelmac->buflen < 0 || pelmac->buflen > 15) { - return CRYPT_INVALID_ARG; - } - -#ifdef LTC_FAST - if (pelmac->buflen == 0) { - while (inlen & ~15) { - int x; - for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pelmac->state + x)) ^= *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)in + x)); - } - _four_rounds(pelmac); - in += 16; - inlen -= 16; - } - } -#endif - - while (inlen--) { - pelmac->state[pelmac->buflen++] ^= *in++; - if (pelmac->buflen == 16) { - _four_rounds(pelmac); - pelmac->buflen = 0; - } - } - return CRYPT_OK; -} - -/** - Terminate Pelican MAC - @param pelmac The Pelican MAC state - @param out [out] The TAG - @return CRYPT_OK on sucess -*/ -int pelican_done(pelican_state *pelmac, unsigned char *out) -{ - LTC_ARGCHK(pelmac != NULL); - LTC_ARGCHK(out != NULL); - - /* check range */ - if (pelmac->buflen < 0 || pelmac->buflen > 16) { - return CRYPT_INVALID_ARG; - } - - if (pelmac->buflen == 16) { - _four_rounds(pelmac); - pelmac->buflen = 0; - } - pelmac->state[pelmac->buflen++] ^= 0x80; - aes_ecb_encrypt(pelmac->state, out, &pelmac->K); - aes_done(&pelmac->K); - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pelican/pelican_memory.c b/libtomcrypt/src/mac/pelican/pelican_memory.c deleted file mode 100644 index 08607a0..0000000 --- a/libtomcrypt/src/mac/pelican/pelican_memory.c +++ /dev/null @@ -1,57 +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 pelican_memory.c - Pelican MAC, MAC a block of memory, by Tom St Denis -*/ - -#ifdef LTC_PELICAN - -/** - Pelican block of memory - @param key The key for the MAC - @param keylen The length of the key (octets) - @param in The input to MAC - @param inlen The length of the input (octets) - @param out [out] The output TAG - @return CRYPT_OK on success -*/ -int pelican_memory(const unsigned char *key, unsigned long keylen, - const unsigned char *in, unsigned long inlen, - unsigned char *out) -{ - pelican_state *pel; - int err; - - pel = XMALLOC(sizeof(*pel)); - if (pel == NULL) { - return CRYPT_MEM; - } - - if ((err = pelican_init(pel, key, keylen)) != CRYPT_OK) { - XFREE(pel); - return err; - } - if ((err = pelican_process(pel, in ,inlen)) != CRYPT_OK) { - XFREE(pel); - return err; - } - err = pelican_done(pel, out); - XFREE(pel); - return err; -} - - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pelican/pelican_test.c b/libtomcrypt/src/mac/pelican/pelican_test.c deleted file mode 100644 index 32a7df3..0000000 --- a/libtomcrypt/src/mac/pelican/pelican_test.c +++ /dev/null @@ -1,113 +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 pelican_test.c - Pelican MAC, test, by Tom St Denis -*/ - -#ifdef LTC_PELICAN - -int pelican_test(void) -{ -#ifndef LTC_TEST - return CRYPT_NOP; -#else - static const struct { - unsigned char K[32], MSG[64], T[16]; - int keylen, ptlen; - } tests[] = { -/* K=16, M=0 */ -{ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, - { 0 }, - { 0xeb, 0x58, 0x37, 0x15, 0xf8, 0x34, 0xde, 0xe5, - 0xa4, 0xd1, 0x6e, 0xe4, 0xb9, 0xd7, 0x76, 0x0e, }, - 16, 0 -}, - -/* K=16, M=3 */ -{ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, - { 0x00, 0x01, 0x02 }, - { 0x1c, 0x97, 0x40, 0x60, 0x6c, 0x58, 0x17, 0x2d, - 0x03, 0x94, 0x19, 0x70, 0x81, 0xc4, 0x38, 0x54, }, - 16, 3 -}, - -/* K=16, M=16 */ -{ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, - { 0x03, 0xcc, 0x46, 0xb8, 0xac, 0xa7, 0x9c, 0x36, - 0x1e, 0x8c, 0x6e, 0xa6, 0x7b, 0x89, 0x32, 0x49, }, - 16, 16 -}, - -/* K=16, M=32 */ -{ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, - { 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 }, - { 0x89, 0xcc, 0x36, 0x58, 0x1b, 0xdd, 0x4d, 0xb5, - 0x78, 0xbb, 0xac, 0xf0, 0xff, 0x8b, 0x08, 0x15, }, - 16, 32 -}, - -/* K=16, M=35 */ -{ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, - { 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, 0x23 }, - { 0x4a, 0x7d, 0x45, 0x4d, 0xcd, 0xb5, 0xda, 0x8d, - 0x48, 0x78, 0x16, 0x48, 0x5d, 0x45, 0x95, 0x99, }, - 16, 35 -}, -}; - int x, err; - unsigned char out[16]; - pelican_state pel; - - for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { - if ((err = pelican_init(&pel, tests[x].K, tests[x].keylen)) != CRYPT_OK) { - return err; - } - if ((err = pelican_process(&pel, tests[x].MSG, tests[x].ptlen)) != CRYPT_OK) { - return err; - } - if ((err = pelican_done(&pel, out)) != CRYPT_OK) { - return err; - } - - if (compare_testvector(out, 16, tests[x].T, 16, "PELICAN", x)) { - 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/mac/pmac/pmac_done.c b/libtomcrypt/src/mac/pmac/pmac_done.c deleted file mode 100644 index de7a5aa..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_done.c +++ /dev/null @@ -1,72 +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 pmac_done.c - PMAC implementation, terminate a session, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen) -{ - int err, x; - - LTC_ARGCHK(state != NULL); - LTC_ARGCHK(out != NULL); - if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) { - return err; - } - - if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) || - (state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) { - return CRYPT_INVALID_ARG; - } - - - /* handle padding. If multiple xor in L/x */ - - if (state->buflen == state->block_len) { - /* xor Lr against the checksum */ - for (x = 0; x < state->block_len; x++) { - state->checksum[x] ^= state->block[x] ^ state->Lr[x]; - } - } else { - /* otherwise xor message bytes then the 0x80 byte */ - for (x = 0; x < state->buflen; x++) { - state->checksum[x] ^= state->block[x]; - } - state->checksum[x] ^= 0x80; - } - - /* encrypt it */ - if ((err = cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key)) != CRYPT_OK) { - return err; - } - cipher_descriptor[state->cipher_idx].done(&state->key); - - /* store it */ - for (x = 0; x < state->block_len && x < (int)*outlen; x++) { - out[x] = state->checksum[x]; - } - *outlen = x; - -#ifdef LTC_CLEAN_STACK - zeromem(state, sizeof(*state)); -#endif - return CRYPT_OK; -} - -#endif - - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_file.c b/libtomcrypt/src/mac/pmac/pmac_file.c deleted file mode 100644 index fe202a2..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_file.c +++ /dev/null @@ -1,98 +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 pmac_file.c - PMAC implementation, process a file, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -/** - PMAC a file - @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 to send through PMAC - @param out [out] Destination for the authentication tag - @param outlen [in/out] Max size and resulting size of the authentication tag - @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled -*/ -int pmac_file(int cipher, - const unsigned char *key, unsigned long keylen, - const char *filename, - unsigned char *out, unsigned long *outlen) -{ -#ifdef LTC_NO_FILE - LTC_UNUSED_PARAM(cipher); - LTC_UNUSED_PARAM(key); - LTC_UNUSED_PARAM(keylen); - LTC_UNUSED_PARAM(filename); - LTC_UNUSED_PARAM(out); - LTC_UNUSED_PARAM(outlen); - return CRYPT_NOP; -#else - size_t x; - int err; - pmac_state pmac; - FILE *in; - unsigned char *buf; - - - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(filename != NULL); - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); - - if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) { - return CRYPT_MEM; - } - - if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) { - goto LBL_ERR; - } - - in = fopen(filename, "rb"); - if (in == NULL) { - err = CRYPT_FILE_NOTFOUND; - goto LBL_ERR; - } - - do { - x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in); - if ((err = pmac_process(&pmac, buf, (unsigned long)x)) != CRYPT_OK) { - fclose(in); - goto LBL_CLEANBUF; - } - } while (x == LTC_FILE_READ_BUFSIZE); - - if (fclose(in) != 0) { - err = CRYPT_ERROR; - goto LBL_CLEANBUF; - } - - err = pmac_done(&pmac, out, outlen); - -LBL_CLEANBUF: - zeromem(buf, LTC_FILE_READ_BUFSIZE); -LBL_ERR: -#ifdef LTC_CLEAN_STACK - zeromem(&pmac, sizeof(pmac_state)); -#endif - XFREE(buf); - return err; -#endif -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_init.c b/libtomcrypt/src/mac/pmac/pmac_init.c deleted file mode 100644 index b1bb400..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_init.c +++ /dev/null @@ -1,148 +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 pmac_init.c - PMAC implementation, initialize state, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -static const struct { - int len; - unsigned char poly_div[MAXBLOCKSIZE], - poly_mul[MAXBLOCKSIZE]; -} polys[] = { -{ - 8, - { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B } -}, { - 16, - { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87 } -} -}; - -/** - Initialize a PMAC state - @param pmac The PMAC state to initialize - @param cipher The index of the desired cipher - @param key The secret key - @param keylen The length of the secret key (octets) - @return CRYPT_OK if successful -*/ -int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen) -{ - int poly, x, y, m, err; - unsigned char *L; - - LTC_ARGCHK(pmac != NULL); - LTC_ARGCHK(key != NULL); - - /* valid cipher? */ - if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { - return err; - } - - /* determine which polys to use */ - pmac->block_len = cipher_descriptor[cipher].block_length; - for (poly = 0; poly < (int)(sizeof(polys)/sizeof(polys[0])); poly++) { - if (polys[poly].len == pmac->block_len) { - break; - } - } - if (poly >= (int)(sizeof(polys)/sizeof(polys[0]))) { - return CRYPT_INVALID_ARG; - } - if (polys[poly].len != pmac->block_len) { - return CRYPT_INVALID_ARG; - } - -#ifdef LTC_FAST - if (pmac->block_len % sizeof(LTC_FAST_TYPE)) { - return CRYPT_INVALID_ARG; - } -#endif - - - /* schedule the key */ - if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &pmac->key)) != CRYPT_OK) { - return err; - } - - /* allocate L */ - L = XMALLOC(pmac->block_len); - if (L == NULL) { - return CRYPT_MEM; - } - - /* find L = E[0] */ - zeromem(L, pmac->block_len); - if ((err = cipher_descriptor[cipher].ecb_encrypt(L, L, &pmac->key)) != CRYPT_OK) { - goto error; - } - - /* find Ls[i] = L << i for i == 0..31 */ - XMEMCPY(pmac->Ls[0], L, pmac->block_len); - for (x = 1; x < 32; x++) { - m = pmac->Ls[x-1][0] >> 7; - for (y = 0; y < pmac->block_len-1; y++) { - pmac->Ls[x][y] = ((pmac->Ls[x-1][y] << 1) | (pmac->Ls[x-1][y+1] >> 7)) & 255; - } - pmac->Ls[x][pmac->block_len-1] = (pmac->Ls[x-1][pmac->block_len-1] << 1) & 255; - - if (m == 1) { - for (y = 0; y < pmac->block_len; y++) { - pmac->Ls[x][y] ^= polys[poly].poly_mul[y]; - } - } - } - - /* find Lr = L / x */ - m = L[pmac->block_len-1] & 1; - - /* shift right */ - for (x = pmac->block_len - 1; x > 0; x--) { - pmac->Lr[x] = ((L[x] >> 1) | (L[x-1] << 7)) & 255; - } - pmac->Lr[0] = L[0] >> 1; - - if (m == 1) { - for (x = 0; x < pmac->block_len; x++) { - pmac->Lr[x] ^= polys[poly].poly_div[x]; - } - } - - /* zero buffer, counters, etc... */ - pmac->block_index = 1; - pmac->cipher_idx = cipher; - pmac->buflen = 0; - zeromem(pmac->block, sizeof(pmac->block)); - zeromem(pmac->Li, sizeof(pmac->Li)); - zeromem(pmac->checksum, sizeof(pmac->checksum)); - err = CRYPT_OK; -error: -#ifdef LTC_CLEAN_STACK - zeromem(L, pmac->block_len); -#endif - - XFREE(L); - - return err; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_memory.c b/libtomcrypt/src/mac/pmac/pmac_memory.c deleted file mode 100644 index 7842781..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_memory.c +++ /dev/null @@ -1,72 +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 pmac_memory.c - PMAC implementation, process a block of memory, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -/** - PMAC a block of memory - @param cipher The index of the cipher desired - @param key The secret key - @param keylen The length of the secret key (octets) - @param in The data you wish to send through PMAC - @param inlen The length of data you wish to send through PMAC (octets) - @param out [out] Destination for the authentication tag - @param outlen [in/out] The max size and resulting size of the authentication tag - @return CRYPT_OK if successful -*/ -int pmac_memory(int cipher, - const unsigned char *key, unsigned long keylen, - const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen) -{ - int err; - pmac_state *pmac; - - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(in != NULL); - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); - - /* allocate ram for pmac state */ - pmac = XMALLOC(sizeof(pmac_state)); - if (pmac == NULL) { - return CRYPT_MEM; - } - - if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) { - goto LBL_ERR; - } - if ((err = pmac_process(pmac, in, inlen)) != CRYPT_OK) { - goto LBL_ERR; - } - if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) { - goto LBL_ERR; - } - - err = CRYPT_OK; -LBL_ERR: -#ifdef LTC_CLEAN_STACK - zeromem(pmac, sizeof(pmac_state)); -#endif - - XFREE(pmac); - return err; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_memory_multi.c b/libtomcrypt/src/mac/pmac/pmac_memory_multi.c deleted file mode 100644 index f3de4b5..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_memory_multi.c +++ /dev/null @@ -1,87 +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" -#include - -/** - @file pmac_memory_multi.c - PMAC implementation, process multiple blocks of memory, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -/** - PMAC multiple blocks of memory - @param cipher The index of the cipher desired - @param key The secret key - @param keylen The length of the secret key (octets) - @param out [out] Destination for the authentication tag - @param outlen [in/out] The max size and resulting size of the authentication tag - @param in The data you wish to send through PMAC - @param inlen The length of data you wish to send through PMAC (octets) - @param ... tuples of (data,len) pairs to PMAC, terminated with a (NULL,x) (x=don't care) - @return CRYPT_OK if successful -*/ -int pmac_memory_multi(int cipher, - const unsigned char *key, unsigned long keylen, - unsigned char *out, unsigned long *outlen, - const unsigned char *in, unsigned long inlen, ...) -{ - int err; - pmac_state *pmac; - va_list args; - const unsigned char *curptr; - unsigned long curlen; - - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(in != NULL); - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); - - /* allocate ram for pmac state */ - pmac = XMALLOC(sizeof(pmac_state)); - if (pmac == NULL) { - return CRYPT_MEM; - } - - if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) { - goto LBL_ERR; - } - va_start(args, inlen); - curptr = in; - curlen = inlen; - for (;;) { - /* process buf */ - if ((err = pmac_process(pmac, curptr, curlen)) != CRYPT_OK) { - goto LBL_ERR; - } - /* step to next */ - curptr = va_arg(args, const unsigned char*); - if (curptr == NULL) { - break; - } - curlen = va_arg(args, unsigned long); - } - if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) { - goto LBL_ERR; - } -LBL_ERR: -#ifdef LTC_CLEAN_STACK - zeromem(pmac, sizeof(pmac_state)); -#endif - XFREE(pmac); - va_end(args); - return err; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_ntz.c b/libtomcrypt/src/mac/pmac/pmac_ntz.c deleted file mode 100644 index 2c7dec5..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_ntz.c +++ /dev/null @@ -1,37 +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 pmac_ntz.c - PMAC implementation, internal function, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -/** - Internal PMAC function -*/ -int pmac_ntz(unsigned long x) -{ - int c; - x &= 0xFFFFFFFFUL; - c = 0; - while ((x & 1) == 0) { - ++c; - x >>= 1; - } - return c; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_process.c b/libtomcrypt/src/mac/pmac/pmac_process.c deleted file mode 100644 index 018fa27..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_process.c +++ /dev/null @@ -1,98 +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 pmac_process.c - PMAC implementation, process data, by Tom St Denis -*/ - - -#ifdef LTC_PMAC - -/** - Process data in a PMAC stream - @param pmac The PMAC state - @param in The data to send through PMAC - @param inlen The length of the data to send through PMAC - @return CRYPT_OK if successful -*/ -int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen) -{ - int err, n; - unsigned long x; - unsigned char Z[MAXBLOCKSIZE]; - - LTC_ARGCHK(pmac != NULL); - LTC_ARGCHK(in != NULL); - if ((err = cipher_is_valid(pmac->cipher_idx)) != CRYPT_OK) { - return err; - } - - if ((pmac->buflen > (int)sizeof(pmac->block)) || (pmac->buflen < 0) || - (pmac->block_len > (int)sizeof(pmac->block)) || (pmac->buflen > pmac->block_len)) { - return CRYPT_INVALID_ARG; - } - -#ifdef LTC_FAST - if (pmac->buflen == 0 && inlen > 16) { - unsigned long y; - for (x = 0; x < (inlen - 16); x += 16) { - pmac_shift_xor(pmac); - for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(&Z[y])) = *(LTC_FAST_TYPE_PTR_CAST(&in[y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&pmac->Li[y])); - } - if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) { - return err; - } - for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST(&pmac->checksum[y])) ^= *(LTC_FAST_TYPE_PTR_CAST(&Z[y])); - } - in += 16; - } - inlen -= x; - } -#endif - - while (inlen != 0) { - /* ok if the block is full we xor in prev, encrypt and replace prev */ - if (pmac->buflen == pmac->block_len) { - pmac_shift_xor(pmac); - for (x = 0; x < (unsigned long)pmac->block_len; x++) { - Z[x] = pmac->Li[x] ^ pmac->block[x]; - } - if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key)) != CRYPT_OK) { - return err; - } - for (x = 0; x < (unsigned long)pmac->block_len; x++) { - pmac->checksum[x] ^= Z[x]; - } - pmac->buflen = 0; - } - - /* add bytes */ - n = MIN(inlen, (unsigned long)(pmac->block_len - pmac->buflen)); - XMEMCPY(pmac->block + pmac->buflen, in, n); - pmac->buflen += n; - inlen -= n; - in += n; - } - -#ifdef LTC_CLEAN_STACK - zeromem(Z, sizeof(Z)); -#endif - - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_shift_xor.c b/libtomcrypt/src/mac/pmac/pmac_shift_xor.c deleted file mode 100644 index 49d48f9..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_shift_xor.c +++ /dev/null @@ -1,42 +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 pmac_shift_xor.c - PMAC implementation, internal function, by Tom St Denis -*/ - -#ifdef LTC_PMAC - -/** - Internal function. Performs the state update (adding correct multiple) - @param pmac The PMAC state. -*/ -void pmac_shift_xor(pmac_state *pmac) -{ - int x, y; - y = pmac_ntz(pmac->block_index++); -#ifdef LTC_FAST - for (x = 0; x < pmac->block_len; x += sizeof(LTC_FAST_TYPE)) { - *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pmac->Li + x)) ^= - *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pmac->Ls[y] + x)); - } -#else - for (x = 0; x < pmac->block_len; x++) { - pmac->Li[x] ^= pmac->Ls[y][x]; - } -#endif -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/libtomcrypt/src/mac/pmac/pmac_test.c b/libtomcrypt/src/mac/pmac/pmac_test.c deleted file mode 100644 index 19329c6..0000000 --- a/libtomcrypt/src/mac/pmac/pmac_test.c +++ /dev/null @@ -1,154 +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 pmac_test.c - PMAC implementation, self-test, by Tom St Denis -*/ - - -#ifdef LTC_PMAC - -/** - Test the LTC_OMAC implementation - @return CRYPT_OK if successful, CRYPT_NOP if testing has been disabled -*/ -int pmac_test(void) -{ -#if !defined(LTC_TEST) - return CRYPT_NOP; -#else - static const struct { - int msglen; - unsigned char key[16], msg[34], tag[16]; - } tests[] = { - - /* PMAC-AES-128-0B */ -{ - 0, - /* key */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* msg */ - { 0x00 }, - /* tag */ - { 0x43, 0x99, 0x57, 0x2c, 0xd6, 0xea, 0x53, 0x41, - 0xb8, 0xd3, 0x58, 0x76, 0xa7, 0x09, 0x8a, 0xf7 } -}, - - /* PMAC-AES-128-3B */ -{ - 3, - /* key */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* msg */ - { 0x00, 0x01, 0x02 }, - /* tag */ - { 0x25, 0x6b, 0xa5, 0x19, 0x3c, 0x1b, 0x99, 0x1b, - 0x4d, 0xf0, 0xc5, 0x1f, 0x38, 0x8a, 0x9e, 0x27 } -}, - - /* PMAC-AES-128-16B */ -{ - 16, - /* key */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* msg */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* tag */ - { 0xeb, 0xbd, 0x82, 0x2f, 0xa4, 0x58, 0xda, 0xf6, - 0xdf, 0xda, 0xd7, 0xc2, 0x7d, 0xa7, 0x63, 0x38 } -}, - - /* PMAC-AES-128-20B */ -{ - 20, - /* key */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* msg */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13 }, - /* tag */ - { 0x04, 0x12, 0xca, 0x15, 0x0b, 0xbf, 0x79, 0x05, - 0x8d, 0x8c, 0x75, 0xa5, 0x8c, 0x99, 0x3f, 0x55 } -}, - - /* PMAC-AES-128-32B */ -{ - 32, - /* key */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* msg */ - { 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 }, - /* tag */ - { 0xe9, 0x7a, 0xc0, 0x4e, 0x9e, 0x5e, 0x33, 0x99, - 0xce, 0x53, 0x55, 0xcd, 0x74, 0x07, 0xbc, 0x75 } -}, - - /* PMAC-AES-128-34B */ -{ - 34, - /* key */ - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, - /* msg */ - { 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 }, - /* tag */ - { 0x5c, 0xba, 0x7d, 0x5e, 0xb2, 0x4f, 0x7c, 0x86, - 0xcc, 0xc5, 0x46, 0x04, 0xe5, 0x3d, 0x55, 0x12 } -} - -}; - int err, x, idx; - unsigned long len; - unsigned char outtag[MAXBLOCKSIZE]; - - /* 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 (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { - len = sizeof(outtag); - if ((err = pmac_memory(idx, tests[x].key, 16, tests[x].msg, tests[x].msglen, outtag, &len)) != CRYPT_OK) { - return err; - } - - if (compare_testvector(outtag, len, tests[x].tag, sizeof(tests[x].tag), "PMAC", x)) { - return CRYPT_FAIL_TESTVECTOR; - } - } - return CRYPT_OK; -#endif /* LTC_TEST */ -} - -#endif /* PMAC_MODE */ - - - - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */