Path: blob/master/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
3153 views
/*-1* Copyright (c) 2014 Michihiro NAKAJIMA2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,17* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT18* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,19* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY20* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF22* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425#ifndef ARCHIVE_HMAC_PRIVATE_H_INCLUDED26#define ARCHIVE_HMAC_PRIVATE_H_INCLUDED2728#ifndef __LIBARCHIVE_BUILD29#error This header is only to be used internally to libarchive.30#endif31/*32* On systems that do not support any recognized crypto libraries,33* the archive_hmac.c file is expected to define no usable symbols.34*35* But some compilers and linkers choke on empty object files, so36* define a public symbol that will always exist. This could37* be removed someday if this file gains another always-present38* symbol definition.39*/40int __libarchive_hmac_build_hack(void);4142#ifdef __APPLE__43# include <AvailabilityMacros.h>44# if MAC_OS_X_VERSION_MAX_ALLOWED >= 106045# define ARCHIVE_HMAC_USE_Apple_CommonCrypto46# endif47#endif4849#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto50#include <CommonCrypto/CommonHMAC.h>5152typedef CCHmacContext archive_hmac_sha1_ctx;5354#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) && _WIN32_WINNT >= _WIN32_WINNT_VISTA55#include <bcrypt.h>5657typedef struct {58BCRYPT_ALG_HANDLE hAlg;59BCRYPT_HASH_HANDLE hHash;60DWORD hash_len;61PBYTE hash;6263} archive_hmac_sha1_ctx;6465#elif defined(HAVE_LIBMBEDCRYPTO) && defined(HAVE_MBEDTLS_MD_H)66#include <mbedtls/md.h>6768typedef mbedtls_md_context_t archive_hmac_sha1_ctx;6970#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H)71#include <nettle/hmac.h>7273typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx;7475#elif defined(HAVE_LIBCRYPTO)76#include <openssl/opensslv.h>77#include <openssl/hmac.h>78#if OPENSSL_VERSION_NUMBER >= 0x30000000L79#include <openssl/params.h>8081typedef EVP_MAC_CTX *archive_hmac_sha1_ctx;8283#else84#include "archive_openssl_hmac_private.h"8586typedef HMAC_CTX* archive_hmac_sha1_ctx;87#endif8889#else9091typedef int archive_hmac_sha1_ctx;9293#endif949596/* HMAC */97#define archive_hmac_sha1_init(ctx, key, key_len)\98__archive_hmac.__hmac_sha1_init(ctx, key, key_len)99#define archive_hmac_sha1_update(ctx, data, data_len)\100__archive_hmac.__hmac_sha1_update(ctx, data, data_len)101#define archive_hmac_sha1_final(ctx, out, out_len)\102__archive_hmac.__hmac_sha1_final(ctx, out, out_len)103#define archive_hmac_sha1_cleanup(ctx)\104__archive_hmac.__hmac_sha1_cleanup(ctx)105106107struct archive_hmac {108/* HMAC */109int (*__hmac_sha1_init)(archive_hmac_sha1_ctx *, const uint8_t *,110size_t);111void (*__hmac_sha1_update)(archive_hmac_sha1_ctx *, const uint8_t *,112size_t);113void (*__hmac_sha1_final)(archive_hmac_sha1_ctx *, uint8_t *, size_t *);114void (*__hmac_sha1_cleanup)(archive_hmac_sha1_ctx *);115};116117extern const struct archive_hmac __archive_hmac;118#endif /* ARCHIVE_HMAC_PRIVATE_H_INCLUDED */119120121