comparison src/modes/ctr/ctr_start.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05

Re-import libtomcrypt 1.05 for cleaner propagating. From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 12:58:00 +0000
parents
children d5faf4814ddb
comparison
equal deleted inserted replaced
-1:000000000000 280:59400faa4b44
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 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11 #include "tomcrypt.h"
12
13 /**
14 @file ctr_start.c
15 CTR implementation, start chain, Tom St Denis
16 */
17
18
19 #ifdef CTR
20
21 /**
22 Initialize a CTR context
23 @param cipher The index of the cipher desired
24 @param IV The initial vector
25 @param key The secret key
26 @param keylen The length of the secret key (octets)
27 @param num_rounds Number of rounds in the cipher desired (0 for default)
28 @param ctr_mode The counter mode (CTR_COUNTER_LITTLE_ENDIAN or CTR_COUNTER_BIG_ENDIAN)
29 @param ctr The CTR state to initialize
30 @return CRYPT_OK if successful
31 */
32 int ctr_start( int cipher,
33 const unsigned char *IV,
34 const unsigned char *key, int keylen,
35 int num_rounds, int ctr_mode,
36 symmetric_CTR *ctr)
37 {
38 int x, err;
39
40 LTC_ARGCHK(IV != NULL);
41 LTC_ARGCHK(key != NULL);
42 LTC_ARGCHK(ctr != NULL);
43
44 /* bad param? */
45 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
46 return err;
47 }
48
49 /* setup cipher */
50 if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
51 return err;
52 }
53
54 /* copy ctr */
55 ctr->blocklen = cipher_descriptor[cipher].block_length;
56 ctr->cipher = cipher;
57 ctr->padlen = 0;
58 ctr->mode = ctr_mode;
59 for (x = 0; x < ctr->blocklen; x++) {
60 ctr->ctr[x] = IV[x];
61 }
62 cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
63 return CRYPT_OK;
64 }
65
66 #endif
67
68 /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_start.c,v $ */
69 /* $Revision: 1.6 $ */
70 /* $Date: 2005/05/05 14:35:59 $ */