1 /* 2 * HMAC-SHA-224/256/384/512 implementation 3 * Last update: 06/15/2005 4 * Issue date: 06/15/2005 5 * 6 * Copyright (C) 2005 Olivier Gay <olivier.gay@a3.epfl.ch> 7 * All rights reserved. 8 * 9 * Copyright (c) 2016, Linaro Limited 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the project nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37 #ifndef HMAC_SHA2_H 38 #define HMAC_SHA2_H 39 40 #include "sha2.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 typedef struct { 47 sha256_ctx ctx_inside; 48 sha256_ctx ctx_outside; 49 50 /* for hmac_reinit */ 51 sha256_ctx ctx_inside_reinit; 52 sha256_ctx ctx_outside_reinit; 53 54 unsigned char block_ipad[SHA256_BLOCK_SIZE]; 55 unsigned char block_opad[SHA256_BLOCK_SIZE]; 56 } hmac_sha256_ctx; 57 58 void hmac_sha256_init(hmac_sha256_ctx *ctx, const unsigned char *key, 59 unsigned int key_size); 60 void hmac_sha256_reinit(hmac_sha256_ctx *ctx); 61 void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message, 62 unsigned int message_len); 63 void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac, 64 unsigned int mac_size); 65 void hmac_sha256(const unsigned char *key, unsigned int key_size, 66 const unsigned char *message, unsigned int message_len, 67 unsigned char *mac, unsigned mac_size); 68 69 #ifdef __cplusplus 70 } 71 #endif 72 73 #endif /* !HMAC_SHA2_H */ 74 75