blob: 4abfa8f0a02b8d65afc7a399faf8ce97423734a3 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001/*
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002 Copyright (C) 2005, 2004, 2010 Erik Eliasson, Johan Bilien, Werner Dittmann
Emeric Vigier2f625822012-08-06 11:09:52 -04003
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>
Alexandre Lisionddd731e2014-01-31 11:50:08 -050037 * @author Werner Dittmann
Emeric Vigier2f625822012-08-06 11:09:52 -040038 */
39
40#ifndef HMAC_H
41#define HMAC_H
42
Alexandre Lisionddd731e2014-01-31 11:50:08 -050043/**
44 * @file hmac.h
45 * @brief Functions that provide SHA1 HMAC support
46 *
47 * @ingroup GNU_ZRTP
48 * @{
49 */
50
51#include <stdint.h>
Emeric Vigier2f625822012-08-06 11:09:52 -040052
53#ifndef SHA1_DIGEST_LENGTH
54#define SHA1_DIGEST_LENGTH 20
55#endif
56
57/**
58 * Compute SHA1 HMAC.
59 *
60 * This functions takes one data chunk and computes its SHA1 HMAC.
61 *
62 * @param key
63 * The MAC key.
64 * @param key_length
65 * Lneght of the MAC key in bytes
66 * @param data
67 * Points to the data chunk.
68 * @param data_length
69 * Length of the data in bytes
70 * @param mac
71 * Points to a buffer that receives the computed digest. This
72 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
73 * @param mac_length
74 * Point to an integer that receives the length of the computed HMAC.
75 */
76
Alexandre Lisionddd731e2014-01-31 11:50:08 -050077void hmac_sha1( uint8_t* key, int32_t key_length,
78 const uint8_t* data, uint32_t data_length,
79 uint8_t* mac, int32_t* mac_length );
Emeric Vigier2f625822012-08-06 11:09:52 -040080
81/**
82 * Compute SHA1 HMAC over several data cunks.
83 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -050084 * This functions takes several data chunk and computes the SHA1 HAMAC.
Emeric Vigier2f625822012-08-06 11:09:52 -040085 *
86 * @param key
87 * The MAC key.
88 * @param key_length
89 * Lneght of the MAC key in bytes
90 * @param data
91 * Points to an array of pointers that point to the data chunks. A NULL
92 * pointer in an array element terminates the data chunks.
93 * @param data_length
94 * Points to an array of integers that hold the length of each data chunk.
95 * @param mac
96 * Points to a buffer that receives the computed digest. This
97 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
98 * @param mac_length
99 * Point to an integer that receives the length of the computed HMAC.
100 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500101void hmac_sha1( uint8_t* key, int32_t key_length,
102 const uint8_t* data[], uint32_t data_length[],
103 uint8_t* mac, int32_t* mac_length );
Emeric Vigier2f625822012-08-06 11:09:52 -0400104
105/**
106 * Create and initialize a SHA1 HMAC context.
107 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500108 * An application uses this context to create several HMAC with the same key.
Emeric Vigier2f625822012-08-06 11:09:52 -0400109 *
110 * @param key
111 * The MAC key.
112 * @param key_length
113 * Lenght of the MAC key in bytes
114 * @return Returns a pointer to the initialized context
115 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500116void* createSha1HmacContext(uint8_t* key, int32_t key_length);
Emeric Vigier2f625822012-08-06 11:09:52 -0400117
118/**
119 * Compute SHA1 HMAC.
120 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500121 * This functions takes one data chunk and computes its SHA1 HMAC. On return
122 * the SHA1 MAC context is ready to compute a HMAC for another data chunk.
Emeric Vigier2f625822012-08-06 11:09:52 -0400123 *
124 * @param ctx
125 * Pointer to initialized SHA1 HMAC context
126 * @param data
127 * Points to the data chunk.
128 * @param data_length
129 * Length of the data in bytes
130 * @param mac
131 * Points to a buffer that receives the computed digest. This
132 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
133 * @param mac_length
134 * Point to an integer that receives the length of the computed HMAC.
135 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500136void hmacSha1Ctx(void* ctx, const uint8_t* data, uint32_t data_length,
Emeric Vigier2f625822012-08-06 11:09:52 -0400137 uint8_t* mac, int32_t* mac_length );
138
139/**
140 * Compute SHA1 HMAC over several data cunks.
141 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500142 * This functions takes several data chunks and computes the SHA1 HAMAC. On return
143 * the SHA1 MAC context is ready to compute a HMAC for another data chunk.
Emeric Vigier2f625822012-08-06 11:09:52 -0400144 *
145 * @param ctx
146 * Pointer to initialized SHA1 HMAC context
147 * @param data
148 * Points to an array of pointers that point to the data chunks. A NULL
149 * pointer in an array element terminates the data chunks.
150 * @param data_length
151 * Points to an array of integers that hold the length of each data chunk.
152 * @param mac
153 * Points to a buffer that receives the computed digest. This
154 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
155 * @param mac_length
156 * Point to an integer that receives the length of the computed HMAC.
157 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500158void hmacSha1Ctx(void* ctx, const uint8_t* data[], uint32_t data_length[],
Emeric Vigier2f625822012-08-06 11:09:52 -0400159 uint8_t* mac, int32_t* mac_length );
160
161/**
162 * Free SHA1 HMAC context.
163 *
164 * @param ctx a pointer to SHA1 HMAC context
165 */
166void freeSha1HmacContext(void* ctx);
167
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500168
169/**
170 * @}
171 */
Emeric Vigier2f625822012-08-06 11:09:52 -0400172#endif