2 * Copyright (c) 2014 Michihiro NAKAJIMA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef __LIBARCHIVE_BUILD
27 #error This header is only to be used internally to libarchive.
30 #ifndef ARCHIVE_HMAC_PRIVATE_H_INCLUDED
31 #define ARCHIVE_HMAC_PRIVATE_H_INCLUDED
34 * On systems that do not support any recognized crypto libraries,
35 * the archive_hmac.c file is expected to define no usable symbols.
37 * But some compilers and linkers choke on empty object files, so
38 * define a public symbol that will always exist. This could
39 * be removed someday if this file gains another always-present
42 int __libarchive_hmac_build_hack(void);
45 # include <AvailabilityMacros.h>
46 # if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
47 # define ARCHIVE_HMAC_USE_Apple_CommonCrypto
51 #ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
52 #include <CommonCrypto/CommonHMAC.h>
54 typedef CCHmacContext archive_hmac_sha1_ctx;
56 #elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
60 BCRYPT_ALG_HANDLE hAlg;
61 BCRYPT_HASH_HANDLE hHash;
65 } archive_hmac_sha1_ctx;
67 #elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H)
68 #include <nettle/hmac.h>
70 typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx;
72 #elif defined(HAVE_LIBCRYPTO)
73 #include <openssl/hmac.h>
75 typedef HMAC_CTX archive_hmac_sha1_ctx;
79 typedef int archive_hmac_sha1_ctx;
85 #define archive_hmac_sha1_init(ctx, key, key_len)\
86 __archive_hmac.__hmac_sha1_init(ctx, key, key_len)
87 #define archive_hmac_sha1_update(ctx, data, data_len)\
88 __archive_hmac.__hmac_sha1_update(ctx, data, data_len)
89 #define archive_hmac_sha1_final(ctx, out, out_len)\
90 __archive_hmac.__hmac_sha1_final(ctx, out, out_len)
91 #define archive_hmac_sha1_cleanup(ctx)\
92 __archive_hmac.__hmac_sha1_cleanup(ctx)
97 int (*__hmac_sha1_init)(archive_hmac_sha1_ctx *, const uint8_t *,
99 void (*__hmac_sha1_update)(archive_hmac_sha1_ctx *, const uint8_t *,
101 void (*__hmac_sha1_final)(archive_hmac_sha1_ctx *, uint8_t *, size_t *);
102 void (*__hmac_sha1_cleanup)(archive_hmac_sha1_ctx *);
105 extern const struct archive_hmac __archive_hmac;
106 #endif /* ARCHIVE_HMAC_PRIVATE_H_INCLUDED */