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.com
15
XCBC Support, start an XCBC state
20
/** Initialize XCBC-MAC state
21
@param xcbc [out] XCBC state to initialize
22
@param cipher Index of cipher to use
23
@param key [in] Secret key
24
@param keylen Length of secret key in octets
25
Return CRYPT_OK on success
27
int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen)
32
LTC_ARGCHK(xcbc != NULL);
33
LTC_ARGCHK(key != NULL);
35
/* schedule the key */
36
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
41
if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
42
return CRYPT_INVALID_ARG;
46
/* schedule the user key */
47
skey = XCALLOC(1, sizeof(*skey));
52
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) {
56
/* make the three keys */
57
for (y = 0; y < 3; y++) {
58
for (x = 0; x < cipher_descriptor[cipher].block_length; x++) {
59
xcbc->K[y][x] = y + 1;
61
cipher_descriptor[cipher].ecb_encrypt(xcbc->K[y], xcbc->K[y], skey);
65
err = cipher_descriptor[cipher].setup(xcbc->K[0], cipher_descriptor[cipher].block_length, 0, &xcbc->key);
68
zeromem(xcbc->IV, cipher_descriptor[cipher].block_length);
69
xcbc->blocksize = cipher_descriptor[cipher].block_length;
70
xcbc->cipher = cipher;
73
cipher_descriptor[cipher].done(skey);
74
#ifdef LTC_CLEAN_STACK
75
zeromem(skey, sizeof(*skey));
83
/* $Source: /cvs/libtom/libtomcrypt/src/mac/xcbc/xcbc_init.c,v $ */
84
/* $Revision: 1.4 $ */
85
/* $Date: 2006/11/07 03:23:46 $ */