comparison libtomcrypt/src/mac/hmac/hmac_done.c @ 1435:f849a5ca2efc

update to libtomcrypt 1.17 (with Dropbear changes)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 17:50:50 +0800
parents a2bfd4374878
children 6dba84798cd5
comparison
equal deleted inserted replaced
1434:27b9ddb06b09 1435:f849a5ca2efc
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.com 9 * Tom St Denis, [email protected], http://libtom.org
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file hmac_done.c 14 @file hmac_done.c
15 HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer 15 LTC_HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
16 */ 16 */
17 17
18 #ifdef LTC_HMAC 18 #ifdef LTC_HMAC
19 19
20 #define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize 20 #define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
21 21
22 /** 22 /**
23 Terminate an HMAC session 23 Terminate an LTC_HMAC session
24 @param hmac The HMAC state 24 @param hmac The LTC_HMAC state
25 @param out [out] The destination of the HMAC authentication tag 25 @param out [out] The destination of the LTC_HMAC authentication tag
26 @param outlen [in/out] The max size and resulting size of the HMAC authentication tag 26 @param outlen [in/out] The max size and resulting size of the LTC_HMAC authentication tag
27 @return CRYPT_OK if successful 27 @return CRYPT_OK if successful
28 */ 28 */
29 int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen) 29 int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
30 { 30 {
31 unsigned char buf[MAXBLOCKSIZE], isha[MAXBLOCKSIZE]; 31 unsigned char buf[MAXBLOCKSIZE], isha[MAXBLOCKSIZE];
42 } 42 }
43 43
44 /* get the hash message digest size */ 44 /* get the hash message digest size */
45 hashsize = hash_descriptor[hash].hashsize; 45 hashsize = hash_descriptor[hash].hashsize;
46 46
47 /* Get the hash of the first HMAC vector plus the data */
48 if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) { 47 if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
49 goto LBL_ERR; 48 goto LBL_ERR;
50 } 49 }
51 50
52 /* Create the second HMAC vector vector for step (3) */ 51 /* Create the second LTC_HMAC vector vector for step (3) */
53 for(i=0; i < HMAC_BLOCKSIZE; i++) { 52 for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) {
54 buf[i] = hmac->key[i] ^ 0x5C; 53 buf[i] = hmac->key[i] ^ 0x5C;
55 } 54 }
56 55
57 /* Now calculate the "outer" hash for step (5), (6), and (7) */ 56 /* Now calculate the "outer" hash for step (5), (6), and (7) */
58 if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) { 57 if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
59 goto LBL_ERR; 58 goto LBL_ERR;
60 } 59 }
61 if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) { 60 if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
62 goto LBL_ERR; 61 goto LBL_ERR;
63 } 62 }
64 if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) { 63 if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) {
65 goto LBL_ERR; 64 goto LBL_ERR;
66 } 65 }
86 return err; 85 return err;
87 } 86 }
88 87
89 #endif 88 #endif
90 89
91 /* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_done.c,v $ */ 90 /* $Source$ */
92 /* $Revision: 1.5 $ */ 91 /* $Revision$ */
93 /* $Date: 2006/11/03 00:39:49 $ */ 92 /* $Date$ */