1/* 2 * Copyright (c) 2011-12 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * Copyright (c) 2005 Kungliga Tekniska Högskolan 26 * (Royal Institute of Technology, Stockholm, Sweden). 27 * All rights reserved. 28 * 29 * Redistribution and use in source and binary forms, with or without 30 * modification, are permitted provided that the following conditions 31 * are met: 32 * 33 * 1. Redistributions of source code must retain the above copyright 34 * notice, this list of conditions and the following disclaimer. 35 * 36 * 2. Redistributions in binary form must reproduce the above copyright 37 * notice, this list of conditions and the following disclaimer in the 38 * documentation and/or other materials provided with the distribution. 39 * 40 * 3. Neither the name of the Institute nor the names of its contributors 41 * may be used to endorse or promote products derived from this software 42 * without specific prior written permission. 43 * 44 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * SUCH DAMAGE. 55 */ 56 57#ifndef _OSSL_HMAC_H_ 58#define _OSSL_HMAC_H_ 1 59 60#include "ossl-evp.h" 61 62/* symbol renaming */ 63#define HMAC_CTX_init ossl_HMAC_CTX_init 64#define HMAC_CTX_cleanup ossl_HMAC_CTX_cleanup 65#define HMAC_cleanup ossl_HMAC_CTX_cleanup 66#define HMAC_size ossl_HMAC_size 67#define HMAC_Init ossl_HMAC_Init 68#define HMAC_Init_ex ossl_HMAC_Init_ex 69#define HMAC_Update ossl_HMAC_Update 70#define HMAC_Final ossl_HMAC_Final 71#define HMAC ossl_HMAC 72 73/* 74 * 75 */ 76 77#define HMAC_MAX_MD_CBLOCK 128 /* assumes SHA512 is the largest */ 78 79typedef struct ossl_HMAC_CTX HMAC_CTX; 80 81struct ossl_HMAC_CTX { 82 const EVP_MD * md; 83 EVP_MD_CTX md_ctx; 84 EVP_MD_CTX i_ctx; 85 EVP_MD_CTX o_ctx; 86 unsigned int key_length; 87 unsigned char key[HMAC_MAX_MD_CBLOCK]; 88}; 89 90 91void HMAC_CTX_init(HMAC_CTX *); 92void HMAC_CTX_cleanup(HMAC_CTX *ctx); 93 94size_t HMAC_size(const HMAC_CTX *ctx); 95 96void HMAC_Init(HMAC_CTX *, const void *, size_t, const EVP_MD *); 97void HMAC_Init_ex(HMAC_CTX *, const void *, size_t, const EVP_MD *, ENGINE *); 98void HMAC_Update(HMAC_CTX *ctx, const void *data, size_t len); 99void HMAC_Final(HMAC_CTX *ctx, void *md, unsigned int *len); 100 101void *HMAC(const EVP_MD *evp_md, const void *key, size_t key_len, 102 const void *data, size_t n, void *md, unsigned int *md_len); 103 104#endif /* _OSSL_HMAC_H_ */ 105