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
13 F8 implementation, start chain, Tom St Denis
20 Initialize an F8 context
21 @param cipher The index of the cipher desired
22 @param IV The initialization vector
23 @param key The secret key
24 @param keylen The length of the secret key (octets)
25 @param salt_key The salting key for the IV
26 @param skeylen The length of the salting key (octets)
27 @param num_rounds Number of rounds in the cipher desired (0 for default)
28 @param f8 The F8 state to initialize
29 @return CRYPT_OK if successful
31 int f8_start( int cipher, const unsigned char *IV,
32 const unsigned char *key, int keylen,
33 const unsigned char *salt_key, int skeylen,
34 int num_rounds, symmetric_F8 *f8)
37 unsigned char tkey[MAXBLOCKSIZE];
39 LTC_ARGCHK(IV != NULL);
40 LTC_ARGCHK(key != NULL);
41 LTC_ARGCHK(salt_key != NULL);
42 LTC_ARGCHK(f8 != NULL);
44 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
49 if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
50 return CRYPT_INVALID_ARG;
57 f8->blocklen = cipher_descriptor[cipher].block_length;
58 f8->padlen = f8->blocklen;
60 /* now get key ^ salt_key [extend salt_ket with 0x55 as required to match length] */
61 zeromem(tkey, sizeof(tkey));
62 for (x = 0; x < keylen && x < (int)sizeof(tkey); x++) {
65 for (x = 0; x < skeylen && x < (int)sizeof(tkey); x++) {
66 tkey[x] ^= salt_key[x];
68 for (; x < keylen && x < (int)sizeof(tkey); x++) {
72 /* now encrypt with tkey[0..keylen-1] the IV and use that as the IV */
73 if ((err = cipher_descriptor[cipher].setup(tkey, keylen, num_rounds, &f8->key)) != CRYPT_OK) {
78 if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->MIV, &f8->key)) != CRYPT_OK) {
79 cipher_descriptor[f8->cipher].done(&f8->key);
82 zeromem(tkey, sizeof(tkey));
83 zeromem(f8->IV, sizeof(f8->IV));
85 /* terminate this cipher */
86 cipher_descriptor[f8->cipher].done(&f8->key);
89 return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &f8->key);
94 /* ref: $Format:%D$ */
95 /* git commit: $Format:%H$ */
96 /* commit time: $Format:%ai$ */