blob: 10d6fbca7fc5fbe9e96925703f00cf0ca921fd8a [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
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/*
34 * Authors: Erik Eliasson <eliasson@it.kth.se>
35 * Johan Bilien <jobi@via.ecp.fr>
36 */
37
38#include <openssl/hmac.h>
Alexandre Lisione24852d2014-02-04 13:13:02 -050039#include <libzrtpcpp/crypto/hmac256.h>
Alexandre Lision51140e12013-12-02 10:54:09 -050040
Alexandre Lisione24852d2014-02-04 13:13:02 -050041void hmac_sha384(uint8_t* key, uint32_t key_length,
42 uint8_t* data, int32_t data_length,
43 uint8_t* mac, uint32_t* mac_length)
Alexandre Lision51140e12013-12-02 10:54:09 -050044{
45 unsigned int tmp;
46 HMAC( EVP_sha384(), key, key_length, data, data_length, mac, &tmp );
47 *mac_length = tmp;
48}
49
50void hmac_sha384(uint8_t* key, uint32_t key_length,
51 uint8_t* data_chunks[],
52 uint32_t data_chunck_length[],
53 uint8_t* mac, uint32_t* mac_length )
54{
55 unsigned int tmp;
56 HMAC_CTX ctx;
57 HMAC_CTX_init( &ctx );
58 HMAC_Init_ex( &ctx, key, key_length, EVP_sha384(), NULL );
59 while( *data_chunks ){
60 HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
61 data_chunks ++;
62 data_chunck_length ++;
63 }
64 HMAC_Final( &ctx, mac, &tmp);
65 *mac_length = tmp;
66 HMAC_CTX_cleanup( &ctx );
67}