]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/CyaSSL/cyassl/ctaocrypt/hmac.h
ee11669d0216b6870f5d1cf12f4b9fb4aa52a994
[freertos] / FreeRTOS-Plus / CyaSSL / cyassl / ctaocrypt / hmac.h
1 /* hmac.h
2  *
3  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * CyaSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  */
21
22
23 #ifndef NO_HMAC
24
25 #ifndef CTAO_CRYPT_HMAC_H
26 #define CTAO_CRYPT_HMAC_H
27
28 #include <cyassl/ctaocrypt/md5.h>
29 #include <cyassl/ctaocrypt/sha.h>
30
31 #ifndef NO_SHA256
32     #include <cyassl/ctaocrypt/sha256.h>
33 #endif
34
35 #ifdef CYASSL_SHA384
36     #include <cyassl/ctaocrypt/sha512.h>
37 #endif
38
39 #ifdef __cplusplus
40     extern "C" {
41 #endif
42
43
44 enum {
45     IPAD    = 0x36,
46     OPAD    = 0x5C,
47 #if defined(CYASSL_SHA384)
48     INNER_HASH_SIZE = SHA384_DIGEST_SIZE,
49     HMAC_BLOCK_SIZE = SHA384_BLOCK_SIZE
50 #elif !defined(NO_SHA256)
51     INNER_HASH_SIZE = SHA256_DIGEST_SIZE,
52     HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE,
53     SHA384          = 5
54 #else
55     INNER_HASH_SIZE = SHA_DIGEST_SIZE,
56     HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE,
57     SHA256          = 2,                     /* hash type unique */
58     SHA384          = 5
59 #endif
60 };
61
62
63 /* hash union */
64 typedef union {
65     Md5 md5;
66     Sha sha;
67     #ifndef NO_SHA256
68         Sha256 sha256;
69     #endif
70     #ifdef CYASSL_SHA384
71         Sha384 sha384;
72     #endif
73 } Hash;
74
75 /* Hmac digest */
76 typedef struct Hmac {
77     Hash    hash;
78     word32  ipad[HMAC_BLOCK_SIZE  / sizeof(word32)];  /* same block size all*/
79     word32  opad[HMAC_BLOCK_SIZE  / sizeof(word32)];
80     word32  innerHash[INNER_HASH_SIZE / sizeof(word32)]; /* max size */
81     byte    macType;                                     /* md5 sha or sha256 */
82     byte    innerHashKeyed;                              /* keyed flag */
83 } Hmac;
84
85
86 /* does init */
87 CYASSL_API void HmacSetKey(Hmac*, int type, const byte* key, word32 keySz);
88 CYASSL_API void HmacUpdate(Hmac*, const byte*, word32);
89 CYASSL_API void HmacFinal(Hmac*, byte*);
90
91
92 #ifdef __cplusplus
93     } /* extern "C" */
94 #endif
95
96 #endif /* CTAO_CRYPT_HMAC_H */
97
98 #endif /* NO_HMAC */
99