HMAC.pod revision 1.1.1.5 1 1.1 christos =pod
2 1.1 christos
3 1.1 christos =head1 NAME
4 1.1 christos
5 1.1 christos HMAC,
6 1.1 christos HMAC_CTX_new,
7 1.1 christos HMAC_CTX_reset,
8 1.1 christos HMAC_CTX_free,
9 1.1 christos HMAC_Init,
10 1.1 christos HMAC_Init_ex,
11 1.1 christos HMAC_Update,
12 1.1 christos HMAC_Final,
13 1.1 christos HMAC_CTX_copy,
14 1.1 christos HMAC_CTX_set_flags,
15 1.1 christos HMAC_CTX_get_md,
16 1.1 christos HMAC_size
17 1.1 christos - HMAC message authentication code
18 1.1 christos
19 1.1 christos =head1 SYNOPSIS
20 1.1 christos
21 1.1 christos #include <openssl/hmac.h>
22 1.1 christos
23 1.1.1.5 christos unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
24 1.1.1.5 christos const unsigned char *data, size_t data_len,
25 1.1 christos unsigned char *md, unsigned int *md_len);
26 1.1 christos
27 1.1.1.5 christos The following functions have been deprecated since OpenSSL 3.0, and can be
28 1.1.1.5 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
29 1.1.1.5 christos see L<openssl_user_macros(7)>:
30 1.1.1.5 christos
31 1.1 christos HMAC_CTX *HMAC_CTX_new(void);
32 1.1 christos int HMAC_CTX_reset(HMAC_CTX *ctx);
33 1.1 christos
34 1.1 christos int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
35 1.1 christos const EVP_MD *md, ENGINE *impl);
36 1.1.1.4 christos int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
37 1.1 christos int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
38 1.1 christos
39 1.1 christos void HMAC_CTX_free(HMAC_CTX *ctx);
40 1.1 christos
41 1.1 christos int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
42 1.1 christos void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
43 1.1 christos const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
44 1.1 christos
45 1.1 christos size_t HMAC_size(const HMAC_CTX *e);
46 1.1 christos
47 1.1.1.5 christos The following function has been deprecated since OpenSSL 1.1.0, and can be
48 1.1.1.5 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
49 1.1.1.5 christos see L<openssl_user_macros(7)>:
50 1.1 christos
51 1.1 christos int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
52 1.1 christos const EVP_MD *md);
53 1.1 christos
54 1.1 christos =head1 DESCRIPTION
55 1.1 christos
56 1.1 christos HMAC is a MAC (message authentication code), i.e. a keyed hash
57 1.1 christos function used for message authentication, which is based on a hash
58 1.1 christos function.
59 1.1 christos
60 1.1.1.5 christos HMAC() computes the message authentication code of the I<data_len> bytes at
61 1.1.1.5 christos I<data> using the hash function I<evp_md> and the key I<key> which is
62 1.1.1.5 christos I<key_len> bytes long. The I<key> may also be NULL with I<key_len> being 0.
63 1.1 christos
64 1.1.1.5 christos It places the result in I<md> (which must have space for the output of
65 1.1 christos the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
66 1.1.1.5 christos If I<md> is NULL, the digest is placed in a static array. The size of
67 1.1.1.5 christos the output is placed in I<md_len>, unless it is NULL. Note: passing a NULL
68 1.1.1.5 christos value for I<md> to use the static array is not thread safe.
69 1.1 christos
70 1.1.1.5 christos I<evp_md> is a message digest such as EVP_sha1(), EVP_ripemd160() etc.
71 1.1.1.5 christos HMAC does not support variable output length digests such as EVP_shake128() and
72 1.1.1.3 christos EVP_shake256().
73 1.1 christos
74 1.1.1.5 christos HMAC() uses the default B<OSSL_LIB_CTX>.
75 1.1.1.5 christos Use L<EVP_Q_mac(3)> instead if a library context is required.
76 1.1.1.5 christos
77 1.1.1.5 christos All of the functions described below are deprecated.
78 1.1.1.5 christos Applications should instead use L<EVP_MAC_CTX_new(3)>, L<EVP_MAC_CTX_free(3)>,
79 1.1.1.5 christos L<EVP_MAC_init(3)>, L<EVP_MAC_update(3)> and L<EVP_MAC_final(3)>
80 1.1.1.5 christos or the 'quick' single-shot MAC function L<EVP_Q_mac(3)>.
81 1.1.1.5 christos
82 1.1 christos HMAC_CTX_new() creates a new HMAC_CTX in heap memory.
83 1.1 christos
84 1.1.1.5 christos HMAC_CTX_reset() clears an existing B<HMAC_CTX> and associated
85 1.1 christos resources, making it suitable for new computations as if it was newly
86 1.1 christos created with HMAC_CTX_new().
87 1.1 christos
88 1.1 christos HMAC_CTX_free() erases the key and other data from the B<HMAC_CTX>,
89 1.1 christos releases any associated resources and finally frees the B<HMAC_CTX>
90 1.1 christos itself.
91 1.1 christos
92 1.1 christos The following functions may be used if the message is not completely
93 1.1 christos stored in memory:
94 1.1 christos
95 1.1 christos HMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use the hash
96 1.1.1.5 christos function I<evp_md> and key I<key>. If both are NULL, or if I<key> is NULL
97 1.1.1.5 christos and I<evp_md> is the same as the previous call, then the
98 1.1 christos existing key is
99 1.1.1.5 christos reused. I<ctx> must have been created with HMAC_CTX_new() before the first use
100 1.1 christos of an B<HMAC_CTX> in this function.
101 1.1 christos
102 1.1.1.5 christos If HMAC_Init_ex() is called with I<key> NULL and I<evp_md> is not the
103 1.1.1.5 christos same as the previous digest used by I<ctx> then an error is returned
104 1.1 christos because reuse of an existing key with a different digest is not supported.
105 1.1 christos
106 1.1 christos HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
107 1.1.1.5 christos function I<evp_md> and the key I<key> which is I<key_len> bytes
108 1.1.1.2 christos long.
109 1.1 christos
110 1.1 christos HMAC_Update() can be called repeatedly with chunks of the message to
111 1.1.1.5 christos be authenticated (I<len> bytes at I<data>).
112 1.1 christos
113 1.1.1.5 christos HMAC_Final() places the message authentication code in I<md>, which
114 1.1 christos must have space for the hash function output.
115 1.1 christos
116 1.1.1.5 christos HMAC_CTX_copy() copies all of the internal state from I<sctx> into I<dctx>.
117 1.1 christos
118 1.1 christos HMAC_CTX_set_flags() applies the specified flags to the internal EVP_MD_CTXs.
119 1.1 christos These flags have the same meaning as for L<EVP_MD_CTX_set_flags(3)>.
120 1.1 christos
121 1.1 christos HMAC_CTX_get_md() returns the EVP_MD that has previously been set for the
122 1.1 christos supplied HMAC_CTX.
123 1.1 christos
124 1.1 christos HMAC_size() returns the length in bytes of the underlying hash function output.
125 1.1 christos
126 1.1 christos =head1 RETURN VALUES
127 1.1 christos
128 1.1 christos HMAC() returns a pointer to the message authentication code or NULL if
129 1.1 christos an error occurred.
130 1.1 christos
131 1.1 christos HMAC_CTX_new() returns a pointer to a new B<HMAC_CTX> on success or
132 1.1.1.5 christos NULL if an error occurred.
133 1.1 christos
134 1.1 christos HMAC_CTX_reset(), HMAC_Init_ex(), HMAC_Update(), HMAC_Final() and
135 1.1 christos HMAC_CTX_copy() return 1 for success or 0 if an error occurred.
136 1.1 christos
137 1.1 christos HMAC_CTX_get_md() return the EVP_MD previously set for the supplied HMAC_CTX or
138 1.1 christos NULL if no EVP_MD has been set.
139 1.1 christos
140 1.1 christos HMAC_size() returns the length in bytes of the underlying hash function output
141 1.1 christos or zero on error.
142 1.1 christos
143 1.1 christos =head1 CONFORMING TO
144 1.1 christos
145 1.1 christos RFC 2104
146 1.1 christos
147 1.1 christos =head1 SEE ALSO
148 1.1 christos
149 1.1.1.5 christos L<SHA1(3)>, EVP_Q_mac(3), L<evp(7)>
150 1.1 christos
151 1.1 christos =head1 HISTORY
152 1.1 christos
153 1.1.1.5 christos All functions except for HMAC() were deprecated in OpenSSL 3.0.
154 1.1.1.5 christos
155 1.1 christos HMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL 1.1.0.
156 1.1 christos
157 1.1 christos HMAC_CTX_cleanup() existed in OpenSSL before version 1.1.0.
158 1.1 christos
159 1.1 christos HMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in OpenSSL 1.1.0.
160 1.1 christos
161 1.1 christos HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
162 1.1 christos OpenSSL before version 1.0.0.
163 1.1 christos
164 1.1 christos =head1 COPYRIGHT
165 1.1 christos
166 1.1.1.5 christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
167 1.1 christos
168 1.1.1.5 christos Licensed under the Apache License 2.0 (the "License"). You may not use
169 1.1 christos this file except in compliance with the License. You can obtain a copy
170 1.1 christos in the file LICENSE in the source distribution or at
171 1.1 christos L<https://www.openssl.org/source/license.html>.
172 1.1 christos
173 1.1 christos =cut
174