Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2006, 2005, 2004 Erik Eliasson, Johan Bilien, Werner Dittmann |
| 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 | */ |
| 19 | |
| 20 | /** |
| 21 | * Methods to compute a SHA256 HMAC. |
| 22 | * |
| 23 | * @author Erik Eliasson <eliasson@it.kth.se> |
| 24 | * @author Johan Bilien <jobi@via.ecp.fr> |
| 25 | * @author Werner Dittmann <Werner.Dittmann@t-online.de> |
| 26 | */ |
| 27 | |
| 28 | #ifndef HMAC_SHA256_H |
| 29 | #define HMAC_SHA256_H |
| 30 | |
| 31 | /** |
| 32 | * @file hmac256.h |
| 33 | * @brief Function that provide SHA256 HMAC support |
| 34 | * |
| 35 | * @ingroup GNU_ZRTP |
| 36 | * @{ |
| 37 | */ |
| 38 | |
| 39 | #include <stdint.h> |
| 40 | |
| 41 | #ifndef SHA256_DIGEST_LENGTH |
| 42 | #define SHA256_DIGEST_LENGTH 32 |
| 43 | #endif |
| 44 | |
| 45 | /** |
| 46 | * Compute SHA256 HMAC. |
| 47 | * |
| 48 | * This functions takes one data chunk and computes its SHA256 HMAC. |
| 49 | * |
| 50 | * @param key |
| 51 | * The MAC key. |
| 52 | * @param key_length |
| 53 | * Lneght of the MAC key in bytes |
| 54 | * @param data |
| 55 | * Points to the data chunk. |
| 56 | * @param data_length |
| 57 | * Length of the data in bytes |
| 58 | * @param mac |
| 59 | * Points to a buffer that receives the computed digest. This |
| 60 | * buffer must have a size of at least 32 bytes (SHA256_DIGEST_LENGTH). |
| 61 | * @param mac_length |
| 62 | * Point to an integer that receives the length of the computed HMAC. |
| 63 | */ |
| 64 | void hmac_sha256( uint8_t* key, uint32_t key_length, |
| 65 | uint8_t* data, int32_t data_length, |
| 66 | uint8_t* mac, uint32_t* mac_length ); |
| 67 | |
| 68 | /** |
| 69 | * Compute SHA256 HMAC over several data cunks. |
| 70 | * |
| 71 | * This functions takes several data chunk and computes the SHA256 HAMAC. It |
| 72 | * uses the openSSL HAMAC SHA256 implementation. |
| 73 | * |
| 74 | * @param key |
| 75 | * The MAC key. |
| 76 | * @param key_length |
| 77 | * Lneght of the MAC key in bytes |
| 78 | * @param data |
| 79 | * Points to an array of pointers that point to the data chunks. A NULL |
| 80 | * pointer in an array element terminates the data chunks. |
| 81 | * @param data_length |
| 82 | * Points to an array of integers that hold the length of each data chunk. |
| 83 | * @param mac |
| 84 | * Points to a buffer that receives the computed digest. This |
| 85 | * buffer must have a size of at least 32 bytes (SHA256_DIGEST_LENGTH). |
| 86 | * @param mac_length |
| 87 | * Point to an integer that receives the length of the computed HMAC. |
| 88 | */ |
| 89 | |
| 90 | void hmac_sha256( uint8_t* key, uint32_t key_length, |
| 91 | uint8_t* data[], uint32_t data_length[], |
| 92 | uint8_t* mac, uint32_t* mac_length ); |
| 93 | /** |
| 94 | * @} |
| 95 | */ |
| 96 | #endif |