Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 2 | Copyright (C) 2005, 2004, 2010 Erik Eliasson, Johan Bilien, Werner Dittmann |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 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 | * |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 35 | * @author Erik Eliasson <eliasson@it.kth.se> |
| 36 | * @author Johan Bilien <jobi@via.ecp.fr> |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 37 | * @author Werner Dittmann |
| 38 | */ |
| 39 | |
| 40 | #ifndef HMAC_H |
| 41 | #define HMAC_H |
| 42 | |
| 43 | /** |
| 44 | * @file hmac.h |
| 45 | * @brief Functions that provide SHA1 HMAC support |
| 46 | * |
| 47 | * @ingroup GNU_ZRTP |
| 48 | * @{ |
| 49 | */ |
| 50 | |
| 51 | #include <stdint.h> |
| 52 | |
| 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 | |
| 77 | void 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 ); |
| 80 | |
| 81 | /** |
| 82 | * Compute SHA1 HMAC over several data cunks. |
| 83 | * |
| 84 | * This functions takes several data chunk and computes the SHA1 HAMAC. |
| 85 | * |
| 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 | */ |
| 101 | void 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 ); |
| 104 | |
| 105 | /** |
| 106 | * Create and initialize a SHA1 HMAC context. |
| 107 | * |
| 108 | * An application uses this context to create several HMAC with the same key. |
| 109 | * |
| 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 | */ |
| 116 | void* createSha1HmacContext(uint8_t* key, int32_t key_length); |
| 117 | |
| 118 | /** |
| 119 | * Compute SHA1 HMAC. |
| 120 | * |
| 121 | * 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. |
| 123 | * |
| 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 | */ |
| 136 | void hmacSha1Ctx(void* ctx, const uint8_t* data, uint32_t data_length, |
| 137 | uint8_t* mac, int32_t* mac_length ); |
| 138 | |
| 139 | /** |
| 140 | * Compute SHA1 HMAC over several data cunks. |
| 141 | * |
| 142 | * 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. |
| 144 | * |
| 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 | */ |
| 158 | void hmacSha1Ctx(void* ctx, const uint8_t* data[], uint32_t data_length[], |
| 159 | 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 | */ |
| 166 | void freeSha1HmacContext(void* ctx); |
| 167 | |
| 168 | |
| 169 | /** |
| 170 | * @} |
| 171 | */ |
| 172 | #endif |