Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmlibarchive/libarchive/archive_hmac_private.h
3153 views
1
/*-
2
* Copyright (c) 2014 Michihiro NAKAJIMA
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
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.
13
*
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.
24
*/
25
26
#ifndef ARCHIVE_HMAC_PRIVATE_H_INCLUDED
27
#define ARCHIVE_HMAC_PRIVATE_H_INCLUDED
28
29
#ifndef __LIBARCHIVE_BUILD
30
#error This header is only to be used internally to libarchive.
31
#endif
32
/*
33
* On systems that do not support any recognized crypto libraries,
34
* the archive_hmac.c file is expected to define no usable symbols.
35
*
36
* But some compilers and linkers choke on empty object files, so
37
* define a public symbol that will always exist. This could
38
* be removed someday if this file gains another always-present
39
* symbol definition.
40
*/
41
int __libarchive_hmac_build_hack(void);
42
43
#ifdef __APPLE__
44
# include <AvailabilityMacros.h>
45
# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
46
# define ARCHIVE_HMAC_USE_Apple_CommonCrypto
47
# endif
48
#endif
49
50
#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
51
#include <CommonCrypto/CommonHMAC.h>
52
53
typedef CCHmacContext archive_hmac_sha1_ctx;
54
55
#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
56
#include <bcrypt.h>
57
58
typedef struct {
59
BCRYPT_ALG_HANDLE hAlg;
60
BCRYPT_HASH_HANDLE hHash;
61
DWORD hash_len;
62
PBYTE hash;
63
64
} archive_hmac_sha1_ctx;
65
66
#elif defined(HAVE_LIBMBEDCRYPTO) && defined(HAVE_MBEDTLS_MD_H)
67
#include <mbedtls/md.h>
68
69
typedef mbedtls_md_context_t archive_hmac_sha1_ctx;
70
71
#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H)
72
#include <nettle/hmac.h>
73
74
typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx;
75
76
#elif defined(HAVE_LIBCRYPTO)
77
#include <openssl/opensslv.h>
78
#include <openssl/hmac.h>
79
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
80
#include <openssl/params.h>
81
82
typedef EVP_MAC_CTX *archive_hmac_sha1_ctx;
83
84
#else
85
#include "archive_openssl_hmac_private.h"
86
87
typedef HMAC_CTX* archive_hmac_sha1_ctx;
88
#endif
89
90
#else
91
92
typedef int archive_hmac_sha1_ctx;
93
94
#endif
95
96
97
/* HMAC */
98
#define archive_hmac_sha1_init(ctx, key, key_len)\
99
__archive_hmac.__hmac_sha1_init(ctx, key, key_len)
100
#define archive_hmac_sha1_update(ctx, data, data_len)\
101
__archive_hmac.__hmac_sha1_update(ctx, data, data_len)
102
#define archive_hmac_sha1_final(ctx, out, out_len)\
103
__archive_hmac.__hmac_sha1_final(ctx, out, out_len)
104
#define archive_hmac_sha1_cleanup(ctx)\
105
__archive_hmac.__hmac_sha1_cleanup(ctx)
106
107
108
struct archive_hmac {
109
/* HMAC */
110
int (*__hmac_sha1_init)(archive_hmac_sha1_ctx *, const uint8_t *,
111
size_t);
112
void (*__hmac_sha1_update)(archive_hmac_sha1_ctx *, const uint8_t *,
113
size_t);
114
void (*__hmac_sha1_final)(archive_hmac_sha1_ctx *, uint8_t *, size_t *);
115
void (*__hmac_sha1_cleanup)(archive_hmac_sha1_ctx *);
116
};
117
118
extern const struct archive_hmac __archive_hmac;
119
#endif /* ARCHIVE_HMAC_PRIVATE_H_INCLUDED */
120
121