1 /* 2 * HMAC-SHA-224/256/384/512 implementation 3 * Last update: 06/15/2005 4 * Issue date: 06/15/2005 5 * 6 * Since this code has been incorporated into a GPLv2 project, it is 7 * distributed under GPLv2 inside mmc-utils. The original BSD license 8 * that the code was released under is included below for clarity. 9 * 10 * Copyright (C) 2005 Olivier Gay <olivier.gay@a3.epfl.ch> 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. Neither the name of the project nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 38 #ifndef HMAC_SHA2_H 39 #define HMAC_SHA2_H 40 41 #include "sha2.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 typedef struct { 48 sha224_ctx ctx_inside; 49 sha224_ctx ctx_outside; 50 51 /* for hmac_reinit */ 52 sha224_ctx ctx_inside_reinit; 53 sha224_ctx ctx_outside_reinit; 54 55 unsigned char block_ipad[SHA224_BLOCK_SIZE]; 56 unsigned char block_opad[SHA224_BLOCK_SIZE]; 57 } hmac_sha224_ctx; 58 59 typedef struct { 60 sha256_ctx ctx_inside; 61 sha256_ctx ctx_outside; 62 63 /* for hmac_reinit */ 64 sha256_ctx ctx_inside_reinit; 65 sha256_ctx ctx_outside_reinit; 66 67 unsigned char block_ipad[SHA256_BLOCK_SIZE]; 68 unsigned char block_opad[SHA256_BLOCK_SIZE]; 69 } hmac_sha256_ctx; 70 71 typedef struct { 72 sha384_ctx ctx_inside; 73 sha384_ctx ctx_outside; 74 75 /* for hmac_reinit */ 76 sha384_ctx ctx_inside_reinit; 77 sha384_ctx ctx_outside_reinit; 78 79 unsigned char block_ipad[SHA384_BLOCK_SIZE]; 80 unsigned char block_opad[SHA384_BLOCK_SIZE]; 81 } hmac_sha384_ctx; 82 83 typedef struct { 84 sha512_ctx ctx_inside; 85 sha512_ctx ctx_outside; 86 87 /* for hmac_reinit */ 88 sha512_ctx ctx_inside_reinit; 89 sha512_ctx ctx_outside_reinit; 90 91 unsigned char block_ipad[SHA512_BLOCK_SIZE]; 92 unsigned char block_opad[SHA512_BLOCK_SIZE]; 93 } hmac_sha512_ctx; 94 95 void hmac_sha224_init(hmac_sha224_ctx *ctx, const unsigned char *key, 96 unsigned int key_size); 97 void hmac_sha224_reinit(hmac_sha224_ctx *ctx); 98 void hmac_sha224_update(hmac_sha224_ctx *ctx, const unsigned char *message, 99 unsigned int message_len); 100 void hmac_sha224_final(hmac_sha224_ctx *ctx, unsigned char *mac, 101 unsigned int mac_size); 102 void hmac_sha224(const unsigned char *key, unsigned int key_size, 103 const unsigned char *message, unsigned int message_len, 104 unsigned char *mac, unsigned mac_size); 105 106 void hmac_sha256_init(hmac_sha256_ctx *ctx, const unsigned char *key, 107 unsigned int key_size); 108 void hmac_sha256_reinit(hmac_sha256_ctx *ctx); 109 void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message, 110 unsigned int message_len); 111 void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac, 112 unsigned int mac_size); 113 void hmac_sha256(const unsigned char *key, unsigned int key_size, 114 const unsigned char *message, unsigned int message_len, 115 unsigned char *mac, unsigned mac_size); 116 117 void hmac_sha384_init(hmac_sha384_ctx *ctx, const unsigned char *key, 118 unsigned int key_size); 119 void hmac_sha384_reinit(hmac_sha384_ctx *ctx); 120 void hmac_sha384_update(hmac_sha384_ctx *ctx, const unsigned char *message, 121 unsigned int message_len); 122 void hmac_sha384_final(hmac_sha384_ctx *ctx, unsigned char *mac, 123 unsigned int mac_size); 124 void hmac_sha384(const unsigned char *key, unsigned int key_size, 125 const unsigned char *message, unsigned int message_len, 126 unsigned char *mac, unsigned mac_size); 127 128 void hmac_sha512_init(hmac_sha512_ctx *ctx, const unsigned char *key, 129 unsigned int key_size); 130 void hmac_sha512_reinit(hmac_sha512_ctx *ctx); 131 void hmac_sha512_update(hmac_sha512_ctx *ctx, const unsigned char *message, 132 unsigned int message_len); 133 void hmac_sha512_final(hmac_sha512_ctx *ctx, unsigned char *mac, 134 unsigned int mac_size); 135 void hmac_sha512(const unsigned char *key, unsigned int key_size, 136 const unsigned char *message, unsigned int message_len, 137 unsigned char *mac, unsigned mac_size); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* !HMAC_SHA2_H */ 144 145