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

« back to all changes in this revision

Viewing changes to libtomcrypt/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@iahu.ca, http://libtomcrypt.org
10
 
 */
11
 
#include "mycrypt.h"
12
 
 
13
 
#ifdef CTR
14
 
 
15
 
int ctr_start(int cipher, const unsigned char *count, const unsigned char *key, int keylen, 
16
 
              int num_rounds, symmetric_CTR *ctr)
17
 
{
18
 
   int x, err;
19
 
 
20
 
   _ARGCHK(count != NULL);
21
 
   _ARGCHK(key != NULL);
22
 
   _ARGCHK(ctr != NULL);
23
 
 
24
 
   /* bad param? */
25
 
   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
26
 
      return err;
27
 
   }
28
 
 
29
 
   /* setup cipher */
30
 
   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
31
 
      return err;
32
 
   }
33
 
 
34
 
   /* copy ctr */
35
 
   ctr->blocklen = cipher_descriptor[cipher].block_length;
36
 
   ctr->cipher   = cipher;
37
 
   ctr->padlen   = 0;
38
 
   ctr->mode     = 0;
39
 
   for (x = 0; x < ctr->blocklen; x++) {
40
 
       ctr->ctr[x] = count[x];
41
 
   }
42
 
   cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
43
 
   return CRYPT_OK;
44
 
}
45
 
 
46
 
#endif