~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtomcrypt/src/modes/ctr/ctr_start.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, tomstdenis@gmail.com, 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 $ */