blob: 6d99f92d8806a0cca9a644688c3fec437c37c2e2 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05002 Copyright (C) 2010 Werner Dittmann
Alexandre Lision51140e12013-12-02 10:54:09 -05003
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 *
Alexandre Lision51140e12013-12-02 10:54:09 -050035 * @author Werner Dittmann
36 */
37
38#ifndef HMAC_H
39#define HMAC_H
40
41/**
42 * @file hmac.h
43 * @brief Functions that provide SHA1 HMAC support
44 *
45 * @ingroup GNU_ZRTP
46 * @{
47 */
48
49#include <stdint.h>
50
51#ifndef SHA1_DIGEST_LENGTH
52#define SHA1_DIGEST_LENGTH 20
53#endif
54
55/**
56 * Compute SHA1 HMAC.
57 *
58 * This functions takes one data chunk and computes its SHA1 HMAC.
59 *
60 * @param key
61 * The MAC key.
62 * @param key_length
63 * Lneght of the MAC key in bytes
64 * @param data
65 * Points to the data chunk.
66 * @param data_length
67 * Length of the data in bytes
68 * @param mac
69 * Points to a buffer that receives the computed digest. This
70 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
71 * @param mac_length
72 * Point to an integer that receives the length of the computed HMAC.
73 */
74
75void hmac_sha1( uint8_t* key, int32_t key_length,
76 const uint8_t* data, uint32_t data_length,
77 uint8_t* mac, int32_t* mac_length );
78
79/**
80 * Compute SHA1 HMAC over several data cunks.
81 *
82 * This functions takes several data chunk and computes the SHA1 HAMAC.
83 *
84 * @param key
85 * The MAC key.
86 * @param key_length
87 * Lneght of the MAC key in bytes
88 * @param data
89 * Points to an array of pointers that point to the data chunks. A NULL
90 * pointer in an array element terminates the data chunks.
91 * @param data_length
92 * Points to an array of integers that hold the length of each data chunk.
93 * @param mac
94 * Points to a buffer that receives the computed digest. This
95 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
96 * @param mac_length
97 * Point to an integer that receives the length of the computed HMAC.
98 */
99void hmac_sha1( uint8_t* key, int32_t key_length,
100 const uint8_t* data[], uint32_t data_length[],
101 uint8_t* mac, int32_t* mac_length );
102
103/**
104 * Create and initialize a SHA1 HMAC context.
105 *
106 * An application uses this context to create several HMAC with the same key.
107 *
108 * @param key
109 * The MAC key.
110 * @param key_length
111 * Lenght of the MAC key in bytes
112 * @return Returns a pointer to the initialized context
113 */
114void* createSha1HmacContext(uint8_t* key, int32_t key_length);
115
116/**
117 * Compute SHA1 HMAC.
118 *
119 * This functions takes one data chunk and computes its SHA1 HMAC. On return
120 * the SHA1 MAC context is ready to compute a HMAC for another data chunk.
121 *
122 * @param ctx
123 * Pointer to initialized SHA1 HMAC context
124 * @param data
125 * Points to the data chunk.
126 * @param data_length
127 * Length of the data in bytes
128 * @param mac
129 * Points to a buffer that receives the computed digest. This
130 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
131 * @param mac_length
132 * Point to an integer that receives the length of the computed HMAC.
133 */
134void hmacSha1Ctx(void* ctx, const uint8_t* data, uint32_t data_length,
135 uint8_t* mac, int32_t* mac_length );
136
137/**
138 * Compute SHA1 HMAC over several data cunks.
139 *
140 * This functions takes several data chunks and computes the SHA1 HAMAC. On return
141 * the SHA1 MAC context is ready to compute a HMAC for another data chunk.
142 *
143 * @param ctx
144 * Pointer to initialized SHA1 HMAC context
145 * @param data
146 * Points to an array of pointers that point to the data chunks. A NULL
147 * pointer in an array element terminates the data chunks.
148 * @param data_length
149 * Points to an array of integers that hold the length of each data chunk.
150 * @param mac
151 * Points to a buffer that receives the computed digest. This
152 * buffer must have a size of at least 20 bytes (SHA1_DIGEST_LENGTH).
153 * @param mac_length
154 * Point to an integer that receives the length of the computed HMAC.
155 */
156void hmacSha1Ctx(void* ctx, const uint8_t* data[], uint32_t data_length[],
157 uint8_t* mac, int32_t* mac_length );
158
159/**
160 * Free SHA1 HMAC context.
161 *
162 * @param ctx a pointer to SHA1 HMAC context
163 */
164void freeSha1HmacContext(void* ctx);
165
166
167/**
168 * @}
169 */
170#endif