blob: 02a5b8c1fc13e1646f9e8f2fa1c203ec2743e96f [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001/*
2 Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 * In addition, as a special exception, the copyright holders give
19 * permission to link the code of portions of this program with the
20 * OpenSSL library under certain conditions as described in each
21 * individual source file, and distribute linked combinations
22 * including the two.
23 * You must obey the GNU General Public License in all respects
24 * for all of the code used other than OpenSSL. If you modify
25 * file(s) with this exception, you may extend this exception to your
26 * version of the file(s), but you are not obligated to do so. If you
27 * do not wish to do so, delete this exception statement from your
28 * version. If you delete this exception statement from all source
29 * files in the program, then also delete it here.
30 */
31
32/**
33 * Functions to compute SHA1 HAMAC.
34 *
35 * @author Erik Eliasson <eliasson@it.kth.se>
36 * @author Johan Bilien <jobi@via.ecp.fr>
37 */
38
39#ifndef HMAC_H
40#define HMAC_H
41
42#include <cc++/config.h>
43
44#ifndef SHA1_DIGEST_LENGTH
45#define SHA1_DIGEST_LENGTH 20
46#endif
47
48/**
49 * Compute SHA1 HMAC.
50 *
51 * This functions takes one data chunk and computes its SHA1 HMAC.
52 *
53 * @param key
54 * The MAC key.
55 * @param key_length
56 * Lneght of the MAC key in bytes
57 * @param data
58 * Points to the data chunk.
59 * @param data_length
60 * Length of the data in bytes
61 * @param mac
62 * Points to a buffer that receives the computed digest. This
63 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
64 * @param mac_length
65 * Point to an integer that receives the length of the computed HMAC.
66 */
67
68__EXPORT void hmac_sha1( uint8* key, int32 key_length,
69 const uint8* data, uint32 data_length,
70 uint8* mac, int32* mac_length );
71
72/**
73 * Compute SHA1 HMAC over several data cunks.
74 *
75 * This functions takes several data chunk and computes the SHA1 HAMAC. It
76 * uses the openSSL HAMAC SHA1 implementation.
77 *
78 * @param key
79 * The MAC key.
80 * @param key_length
81 * Lneght of the MAC key in bytes
82 * @param data
83 * Points to an array of pointers that point to the data chunks. A NULL
84 * pointer in an array element terminates the data chunks.
85 * @param data_length
86 * Points to an array of integers that hold the length of each data chunk.
87 * @param mac
88 * Points to a buffer that receives the computed digest. This
89 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
90 * @param mac_length
91 * Point to an integer that receives the length of the computed HMAC.
92 */
93__EXPORT void hmac_sha1( uint8* key, int32 key_length,
94 const uint8* data[], uint32 data_length[],
95 uint8* mac, int32* mac_length );
96
97/**
98 * Create and initialize a SHA1 HMAC context.
99 *
100 * An application uses this context to hash several data into one SHA1
101 * digest.
102 *
103 * @param key
104 * The MAC key.
105 * @param key_length
106 * Lenght of the MAC key in bytes
107 * @return Returns a pointer to the initialized context
108 */
109__EXPORT void* createSha1HmacContext(uint8_t* key, int32_t key_length);
110
111/**
112 * Compute SHA1 HMAC.
113 *
114 * This functions takes one data chunk and computes its SHA1 HMAC.
115 *
116 * @param ctx
117 * Pointer to initialized SHA1 HMAC context
118 * @param data
119 * Points to the data chunk.
120 * @param data_length
121 * Length of the data in bytes
122 * @param mac
123 * Points to a buffer that receives the computed digest. This
124 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
125 * @param mac_length
126 * Point to an integer that receives the length of the computed HMAC.
127 */
128
129__EXPORT void hmacSha1Ctx(void* ctx, const uint8_t* data, uint32_t data_length,
130 uint8_t* mac, int32_t* mac_length );
131
132/**
133 * Compute SHA1 HMAC over several data cunks.
134 *
135 * This functions takes several data chunk and computes the SHA1 HAMAC.
136 *
137 * @param ctx
138 * Pointer to initialized SHA1 HMAC context
139 * @param data
140 * Points to an array of pointers that point to the data chunks. A NULL
141 * pointer in an array element terminates the data chunks.
142 * @param data_length
143 * Points to an array of integers that hold the length of each data chunk.
144 * @param mac
145 * Points to a buffer that receives the computed digest. This
146 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
147 * @param mac_length
148 * Point to an integer that receives the length of the computed HMAC.
149 */
150__EXPORT void hmacSha1Ctx(void* ctx, const uint8_t* data[], uint32_t data_length[],
151 uint8_t* mac, int32_t* mac_length );
152
153/**
154 * Free SHA1 HMAC context.
155 *
156 * @param ctx a pointer to SHA1 HMAC context
157 */
158void freeSha1HmacContext(void* ctx);
159
160#endif