]> pd.if.org Git - zpackage/blob - libtomcrypt/src/mac/f9/f9_init.c
remove md2 md4 md5 hashes
[zpackage] / libtomcrypt / src / mac / f9 / f9_init.c
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2  *
3  * LibTomCrypt is a library that provides various cryptographic
4  * algorithms in a highly modular and flexible manner.
5  *
6  * The library is free for all purposes without any express
7  * guarantee it works.
8  */
9 #include "tomcrypt.h"
10
11 /**
12   @file f9_init.c
13   F9 Support, start an F9 state
14 */
15
16 #ifdef LTC_F9_MODE
17
18 /** Initialize F9-MAC state
19   @param f9    [out] f9 state to initialize
20   @param cipher  Index of cipher to use
21   @param key     [in]  Secret key
22   @param keylen  Length of secret key in octets
23   Return CRYPT_OK on success
24 */
25 int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen)
26 {
27    int            x, err;
28
29    LTC_ARGCHK(f9   != NULL);
30    LTC_ARGCHK(key  != NULL);
31
32    /* schedule the key */
33    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
34       return err;
35    }
36
37 #ifdef LTC_FAST
38    if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
39        return CRYPT_INVALID_ARG;
40    }
41 #endif
42
43    if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &f9->key)) != CRYPT_OK) {
44       goto done;
45    }
46
47    /* make the second key */
48    for (x = 0; (unsigned)x < keylen; x++) {
49       f9->akey[x] = key[x] ^ 0xAA;
50    }
51
52    /* setup struct */
53    zeromem(f9->IV,  cipher_descriptor[cipher].block_length);
54    zeromem(f9->ACC, cipher_descriptor[cipher].block_length);
55    f9->blocksize = cipher_descriptor[cipher].block_length;
56    f9->cipher    = cipher;
57    f9->buflen    = 0;
58    f9->keylen    = keylen;
59 done:
60    return err;
61 }
62
63 #endif
64
65 /* ref:         $Format:%D$ */
66 /* git commit:  $Format:%H$ */
67 /* commit time: $Format:%ai$ */
68