1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
15
Pelican MAC, initialize state, by Tom St Denis
21
#include "../../ciphers/aes/aes_tab.c"
25
Initialize a Pelican state
26
@param pelmac The Pelican state to initialize
27
@param key The secret key
28
@param keylen The length of the secret key (octets)
29
@return CRYPT_OK if successful
31
int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen)
35
LTC_ARGCHK(pelmac != NULL);
36
LTC_ARGCHK(key != NULL);
39
if (16 % sizeof(LTC_FAST_TYPE)) {
40
return CRYPT_INVALID_ARG;
44
if ((err = aes_setup(key, keylen, 0, &pelmac->K)) != CRYPT_OK) {
48
zeromem(pelmac->state, 16);
49
aes_ecb_encrypt(pelmac->state, pelmac->state, &pelmac->K);
55
static void four_rounds(pelican_state *pelmac)
57
ulong32 s0, s1, s2, s3, t0, t1, t2, t3;
60
LOAD32H(s0, pelmac->state );
61
LOAD32H(s1, pelmac->state + 4);
62
LOAD32H(s2, pelmac->state + 8);
63
LOAD32H(s3, pelmac->state + 12);
64
for (r = 0; r < 4; r++) {
85
s0 = t0; s1 = t1; s2 = t2; s3 = t3;
87
STORE32H(s0, pelmac->state );
88
STORE32H(s1, pelmac->state + 4);
89
STORE32H(s2, pelmac->state + 8);
90
STORE32H(s3, pelmac->state + 12);
94
Process a block of text through Pelican
95
@param pelmac The Pelican MAC state
97
@param inlen The length input (octets)
98
@return CRYPT_OK on success
100
int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen)
103
LTC_ARGCHK(pelmac != NULL);
104
LTC_ARGCHK(in != NULL);
107
if (pelmac->buflen < 0 || pelmac->buflen > 15) {
108
return CRYPT_INVALID_ARG;
112
if (pelmac->buflen == 0) {
113
while (inlen & ~15) {
115
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
116
*((LTC_FAST_TYPE*)((unsigned char *)pelmac->state + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)in + x));
126
pelmac->state[pelmac->buflen++] ^= *in++;
127
if (pelmac->buflen == 16) {
136
Terminate Pelican MAC
137
@param pelmac The Pelican MAC state
138
@param out [out] The TAG
139
@return CRYPT_OK on sucess
141
int pelican_done(pelican_state *pelmac, unsigned char *out)
143
LTC_ARGCHK(pelmac != NULL);
144
LTC_ARGCHK(out != NULL);
147
if (pelmac->buflen < 0 || pelmac->buflen > 16) {
148
return CRYPT_INVALID_ARG;
151
if (pelmac->buflen == 16) {
155
pelmac->state[pelmac->buflen++] ^= 0x80;
156
aes_ecb_encrypt(pelmac->state, out, &pelmac->K);
157
aes_done(&pelmac->K);
163
/* $Source: /cvs/libtom/libtomcrypt/src/mac/pelican/pelican.c,v $ */
164
/* $Revision: 1.16 $ */
165
/* $Date: 2005/05/05 14:35:59 $ */