comparison src/modes/ctr/ctr_start.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05

Import of libtomcrypt 1.05
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 03:53:40 +0000
parents 1c15b283127b
children
comparison
equal deleted inserted replaced
191:1c15b283127b 209:39d5d58461d6
19 #ifdef CTR 19 #ifdef CTR
20 20
21 /** 21 /**
22 Initialize a CTR context 22 Initialize a CTR context
23 @param cipher The index of the cipher desired 23 @param cipher The index of the cipher desired
24 @param count The initial vector 24 @param IV The initial vector
25 @param key The secret key 25 @param key The secret key
26 @param keylen The length of the secret key (octets) 26 @param keylen The length of the secret key (octets)
27 @param num_rounds Number of rounds in the cipher desired (0 for default) 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)
28 @param ctr The CTR state to initialize 29 @param ctr The CTR state to initialize
29 @return CRYPT_OK if successful 30 @return CRYPT_OK if successful
30 */ 31 */
31 int ctr_start(int cipher, const unsigned char *count, const unsigned char *key, int keylen, 32 int ctr_start( int cipher,
32 int num_rounds, symmetric_CTR *ctr) 33 const unsigned char *IV,
34 const unsigned char *key, int keylen,
35 int num_rounds, int ctr_mode,
36 symmetric_CTR *ctr)
33 { 37 {
34 int x, err; 38 int x, err;
35 39
36 LTC_ARGCHK(count != NULL); 40 LTC_ARGCHK(IV != NULL);
37 LTC_ARGCHK(key != NULL); 41 LTC_ARGCHK(key != NULL);
38 LTC_ARGCHK(ctr != NULL); 42 LTC_ARGCHK(ctr != NULL);
39 43
40 /* bad param? */ 44 /* bad param? */
41 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) { 45 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
49 53
50 /* copy ctr */ 54 /* copy ctr */
51 ctr->blocklen = cipher_descriptor[cipher].block_length; 55 ctr->blocklen = cipher_descriptor[cipher].block_length;
52 ctr->cipher = cipher; 56 ctr->cipher = cipher;
53 ctr->padlen = 0; 57 ctr->padlen = 0;
54 ctr->mode = 0; 58 ctr->mode = ctr_mode;
55 for (x = 0; x < ctr->blocklen; x++) { 59 for (x = 0; x < ctr->blocklen; x++) {
56 ctr->ctr[x] = count[x]; 60 ctr->ctr[x] = IV[x];
57 } 61 }
58 cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key); 62 cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
59 return CRYPT_OK; 63 return CRYPT_OK;
60 } 64 }
61 65
62 #endif 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 $ */