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@iahu.ca, http://libtomcrypt.org
12
/* EAX Implementation by Tom St Denis */
17
int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
18
const unsigned char *nonce, unsigned long noncelen,
19
const unsigned char *header, unsigned long headerlen)
29
_ARGCHK(nonce != NULL);
31
_ARGCHK(header != NULL);
34
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
37
blklen = cipher_descriptor[cipher].block_length;
40
buf = XMALLOC(MAXBLOCKSIZE);
41
omac = XMALLOC(sizeof(omac_state));
43
if (buf == NULL || omac == NULL) {
53
/* N = OMAC_0K(nonce) */
54
zeromem(buf, MAXBLOCKSIZE);
55
if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
60
if ((err = omac_process(omac, buf, blklen)) != CRYPT_OK) {
64
if ((err = omac_process(omac, nonce, noncelen)) != CRYPT_OK) {
69
if ((err = omac_done(omac, eax->N, &len)) != CRYPT_OK) {
73
/* H = OMAC_1K(header) */
74
zeromem(buf, MAXBLOCKSIZE);
77
if ((err = omac_init(&eax->headeromac, cipher, key, keylen)) != CRYPT_OK) {
82
if ((err = omac_process(&eax->headeromac, buf, blklen)) != CRYPT_OK) {
87
if ((err = omac_process(&eax->headeromac, header, headerlen)) != CRYPT_OK) {
92
/* note we don't finish the headeromac, this allows us to add more header later */
94
/* setup the CTR mode */
95
if ((err = ctr_start(cipher, eax->N, key, keylen, 0, &eax->ctr)) != CRYPT_OK) {
98
/* use big-endian counter */
101
/* setup the OMAC for the ciphertext */
102
if ((err = omac_init(&eax->ctomac, cipher, key, keylen)) != CRYPT_OK) {
107
zeromem(buf, MAXBLOCKSIZE);
109
if ((err = omac_process(&eax->ctomac, buf, blklen)) != CRYPT_OK) {
116
zeromem(buf, MAXBLOCKSIZE);
117
zeromem(omac, sizeof(omac_state));