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

« back to all changes in this revision

Viewing changes to libtomcrypt/hmac_memory.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
 
/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
12
 
 
13
 
#include "mycrypt.h"
14
 
 
15
 
#ifdef HMAC
16
 
 
17
 
int hmac_memory(int hash, const unsigned char *key, unsigned long keylen,
18
 
                const unsigned char *data, unsigned long len, 
19
 
                unsigned char *dst, unsigned long *dstlen)
20
 
{
21
 
    hmac_state *hmac;
22
 
    int err;
23
 
 
24
 
    _ARGCHK(key    != NULL);
25
 
    _ARGCHK(data   != NULL);
26
 
    _ARGCHK(dst    != NULL); 
27
 
    _ARGCHK(dstlen != NULL);
28
 
 
29
 
    /* allocate ram for hmac state */
30
 
    hmac = XMALLOC(sizeof(hmac_state));
31
 
    if (hmac == NULL) {
32
 
       return CRYPT_MEM;
33
 
    }
34
 
 
35
 
    if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) {
36
 
       goto __ERR;
37
 
    }
38
 
 
39
 
    if ((err = hmac_process(hmac, data, len)) != CRYPT_OK) {
40
 
       goto __ERR;
41
 
    }
42
 
 
43
 
    if ((err = hmac_done(hmac, dst, dstlen)) != CRYPT_OK) {
44
 
       goto __ERR;
45
 
    }
46
 
 
47
 
   err = CRYPT_OK;
48
 
__ERR:
49
 
#ifdef CLEAN_STACK
50
 
   zeromem(hmac, sizeof(hmac_state));
51
 
#endif
52
 
 
53
 
   XFREE(hmac);
54
 
   return err;   
55
 
}
56
 
 
57
 
#endif
58