1299425Smm/*- 2299425Smm* Copyright (c) 2014 Michihiro NAKAJIMA 3299425Smm* All rights reserved. 4299425Smm* 5299425Smm* Redistribution and use in source and binary forms, with or without 6299425Smm* modification, are permitted provided that the following conditions 7299425Smm* are met: 8299425Smm* 1. Redistributions of source code must retain the above copyright 9299425Smm* notice, this list of conditions and the following disclaimer. 10299425Smm* 2. Redistributions in binary form must reproduce the above copyright 11299425Smm* notice, this list of conditions and the following disclaimer in the 12299425Smm* documentation and/or other materials provided with the distribution. 13299425Smm* 14299425Smm* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15299425Smm* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16299425Smm* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17299425Smm* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18299425Smm* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19299425Smm* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20299425Smm* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21299425Smm* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22299425Smm* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23299425Smm* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24299425Smm*/ 25299425Smm 26358090Smm#ifndef ARCHIVE_HMAC_PRIVATE_H_INCLUDED 27358090Smm#define ARCHIVE_HMAC_PRIVATE_H_INCLUDED 28358090Smm 29299425Smm#ifndef __LIBARCHIVE_BUILD 30299425Smm#error This header is only to be used internally to libarchive. 31299425Smm#endif 32299425Smm/* 33299425Smm * On systems that do not support any recognized crypto libraries, 34299425Smm * the archive_hmac.c file is expected to define no usable symbols. 35299425Smm * 36299425Smm * But some compilers and linkers choke on empty object files, so 37299425Smm * define a public symbol that will always exist. This could 38299425Smm * be removed someday if this file gains another always-present 39299425Smm * symbol definition. 40299425Smm */ 41299425Smmint __libarchive_hmac_build_hack(void); 42299425Smm 43299425Smm#ifdef __APPLE__ 44299425Smm# include <AvailabilityMacros.h> 45299425Smm# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 46299425Smm# define ARCHIVE_HMAC_USE_Apple_CommonCrypto 47299425Smm# endif 48299425Smm#endif 49299425Smm 50299425Smm#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto 51299425Smm#include <CommonCrypto/CommonHMAC.h> 52299425Smm 53299425Smmtypedef CCHmacContext archive_hmac_sha1_ctx; 54299425Smm 55299425Smm#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) 56299425Smm#include <bcrypt.h> 57299425Smm 58299425Smmtypedef struct { 59299425Smm BCRYPT_ALG_HANDLE hAlg; 60299425Smm BCRYPT_HASH_HANDLE hHash; 61299425Smm DWORD hash_len; 62299425Smm PBYTE hash; 63299425Smm 64299425Smm} archive_hmac_sha1_ctx; 65299425Smm 66358090Smm#elif defined(HAVE_LIBMBEDCRYPTO) && defined(HAVE_MBEDTLS_MD_H) 67358090Smm#include <mbedtls/md.h> 68358090Smm 69358090Smmtypedef mbedtls_md_context_t archive_hmac_sha1_ctx; 70358090Smm 71299425Smm#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H) 72299425Smm#include <nettle/hmac.h> 73299425Smm 74299425Smmtypedef struct hmac_sha1_ctx archive_hmac_sha1_ctx; 75299425Smm 76299425Smm#elif defined(HAVE_LIBCRYPTO) 77311042Smm#include "archive_openssl_hmac_private.h" 78299425Smm 79311042Smmtypedef HMAC_CTX* archive_hmac_sha1_ctx; 80299425Smm 81299425Smm#else 82299425Smm 83299425Smmtypedef int archive_hmac_sha1_ctx; 84299425Smm 85299425Smm#endif 86299425Smm 87299425Smm 88299425Smm/* HMAC */ 89299425Smm#define archive_hmac_sha1_init(ctx, key, key_len)\ 90299425Smm __archive_hmac.__hmac_sha1_init(ctx, key, key_len) 91299425Smm#define archive_hmac_sha1_update(ctx, data, data_len)\ 92299425Smm __archive_hmac.__hmac_sha1_update(ctx, data, data_len) 93299425Smm#define archive_hmac_sha1_final(ctx, out, out_len)\ 94299425Smm __archive_hmac.__hmac_sha1_final(ctx, out, out_len) 95299425Smm#define archive_hmac_sha1_cleanup(ctx)\ 96299425Smm __archive_hmac.__hmac_sha1_cleanup(ctx) 97299425Smm 98299425Smm 99299425Smmstruct archive_hmac { 100299425Smm /* HMAC */ 101299425Smm int (*__hmac_sha1_init)(archive_hmac_sha1_ctx *, const uint8_t *, 102299425Smm size_t); 103299425Smm void (*__hmac_sha1_update)(archive_hmac_sha1_ctx *, const uint8_t *, 104299425Smm size_t); 105299425Smm void (*__hmac_sha1_final)(archive_hmac_sha1_ctx *, uint8_t *, size_t *); 106299425Smm void (*__hmac_sha1_cleanup)(archive_hmac_sha1_ctx *); 107299425Smm}; 108299425Smm 109299425Smmextern const struct archive_hmac __archive_hmac; 110299425Smm#endif /* ARCHIVE_HMAC_PRIVATE_H_INCLUDED */ 111