]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/HMAC.pod
Updates CHANGES and NEWS for new release
[thirdparty/openssl.git] / doc / man3 / HMAC.pod
CommitLineData
9dbc41d7
UM
1=pod
2
3=head1 NAME
4
827d17f0
MC
5HMAC,
6HMAC_CTX_new,
7HMAC_CTX_reset,
8HMAC_CTX_free,
9HMAC_Init,
10HMAC_Init_ex,
11HMAC_Update,
12HMAC_Final,
13HMAC_CTX_copy,
14HMAC_CTX_set_flags,
8d2b1819
MC
15HMAC_CTX_get_md,
16HMAC_size
827d17f0 17- HMAC message authentication code
9dbc41d7
UM
18
19=head1 SYNOPSIS
20
21 #include <openssl/hmac.h>
22
23 unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
24 int key_len, const unsigned char *d, int n,
25 unsigned char *md, unsigned int *md_len);
26
716854d7
RL
27 HMAC_CTX *HMAC_CTX_new(void);
28 int HMAC_CTX_reset(HMAC_CTX *ctx);
ff3fa48f 29
87d52468 30 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
1bc74519 31 const EVP_MD *md, ENGINE *impl);
87d52468
DSH
32 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
33 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
9dbc41d7 34
716854d7 35 void HMAC_CTX_free(HMAC_CTX *ctx);
9dbc41d7 36
827d17f0
MC
37 int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
38 void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
39 const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
40
8d2b1819
MC
41 size_t HMAC_size(const HMAC_CTX *e);
42
98186eb4
VD
43Deprecated:
44
45 #if OPENSSL_API_COMPAT < 0x10100000L
46 int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
47 const EVP_MD *md);
48 #endif
49
9dbc41d7
UM
50=head1 DESCRIPTION
51
52HMAC is a MAC (message authentication code), i.e. a keyed hash
53function used for message authentication, which is based on a hash
54function.
55
56HMAC() computes the message authentication code of the B<n> bytes at
57B<d> using the hash function B<evp_md> and the key B<key> which is
58B<key_len> bytes long.
59
60It places the result in B<md> (which must have space for the output of
61the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
62If B<md> is NULL, the digest is placed in a static array. The size of
63the output is placed in B<md_len>, unless it is B<NULL>.
64
65B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
9dbc41d7 66
716854d7 67HMAC_CTX_new() creates a new HMAC_CTX in heap memory.
ff3fa48f 68
716854d7
RL
69HMAC_CTX_reset() zeroes an existing B<HMAC_CTX> and associated
70resources, making it suitable for new computations as if it was newly
71created with HMAC_CTX_new().
72
73HMAC_CTX_free() erases the key and other data from the B<HMAC_CTX>,
74releases any associated resources and finally frees the B<HMAC_CTX>
75itself.
ff3fa48f 76
9dbc41d7
UM
77The following functions may be used if the message is not completely
78stored in memory:
79
80HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
ff3fa48f
BL
81function B<evp_md> and the key B<key> which is B<key_len> bytes
82long. It is deprecated and only included for backward compatibility
83with OpenSSL 0.9.6b.
84
bd19d1aa
DSH
85HMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use the hash
86function B<evp_md> and key B<key>. If both are NULL (or B<evp_md> is the same
87as the previous digest used by B<ctx> and B<key> is NULL) the existing key is
88reused. B<ctx> must have been created with HMAC_CTX_new() before the first use
89of an B<HMAC_CTX> in this function. B<N.B. HMAC_Init() had this undocumented
90behaviour in previous versions of OpenSSL - failure to switch to HMAC_Init_ex()
91in programs that expect it will cause them to stop working>.
92
1a627771 93B<NOTE:> If HMAC_Init_ex() is called with B<key> NULL and B<evp_md> is not the
bd19d1aa 94same as the previous digest used by B<ctx> then an error is returned
1a627771 95because reuse of an existing key with a different digest is not supported.
9dbc41d7
UM
96
97HMAC_Update() can be called repeatedly with chunks of the message to
98be authenticated (B<len> bytes at B<data>).
99
100HMAC_Final() places the message authentication code in B<md>, which
101must have space for the hash function output.
102
827d17f0
MC
103HMAC_CTX_copy() copies all of the internal state from B<sctx> into B<dctx>.
104
105HMAC_CTX_set_flags() applies the specified flags to the internal EVP_MD_CTXs.
106These flags have the same meaning as for L<EVP_MD_CTX_set_flags(3)>.
107
108HMAC_CTX_get_md() returns the EVP_MD that has previously been set for the
109supplied HMAC_CTX.
110
8d2b1819
MC
111HMAC_size() returns the length in bytes of the underlying hash function output.
112
9dbc41d7
UM
113=head1 RETURN VALUES
114
87d52468
DSH
115HMAC() returns a pointer to the message authentication code or NULL if
116an error occurred.
9dbc41d7 117
716854d7
RL
118HMAC_CTX_new() returns a pointer to a new B<HMAC_CTX> on success or
119B<NULL> if an error occurred.
120
827d17f0
MC
121HMAC_CTX_reset(), HMAC_Init_ex(), HMAC_Update(), HMAC_Final() and
122HMAC_CTX_copy() return 1 for success or 0 if an error occurred.
87d52468 123
827d17f0
MC
124HMAC_CTX_get_md() return the EVP_MD previously set for the supplied HMAC_CTX or
125NULL if no EVP_MD has been set.
9dbc41d7 126
8d2b1819
MC
127HMAC_size() returns the length in bytes of the underlying hash function output
128or zero on error.
129
9dbc41d7
UM
130=head1 CONFORMING TO
131
132RFC 2104
133
134=head1 SEE ALSO
135
b97fdb57 136L<SHA1(3)>, L<evp(7)>
9dbc41d7
UM
137
138=head1 HISTORY
139
827d17f0 140HMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL versions 1.1.0.
716854d7 141
827d17f0 142HMAC_CTX_cleanup() existed in OpenSSL versions before 1.1.0.
716854d7 143
827d17f0
MC
144HMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in OpenSSL version
1451.1.0.
9b6c0070 146
87d52468 147HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
fb552ac6 148versions of OpenSSL before 1.0.0.
87d52468 149
e2f92610
RS
150=head1 COPYRIGHT
151
152Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
153
154Licensed under the OpenSSL license (the "License"). You may not use
155this file except in compliance with the License. You can obtain a copy
156in the file LICENSE in the source distribution or at
157L<https://www.openssl.org/source/license.html>.
158
159=cut