1HMAC(3)                             OpenSSL                            HMAC(3)
2
3
4

NAME

6       HMAC, HMAC_CTX_new, HMAC_CTX_reset, HMAC_CTX_free, HMAC_Init,
7       HMAC_Init_ex, HMAC_Update, HMAC_Final, HMAC_CTX_copy,
8       HMAC_CTX_set_flags, HMAC_CTX_get_md, HMAC_size - HMAC message
9       authentication code
10

SYNOPSIS

12        #include <openssl/hmac.h>
13
14        unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
15                            int key_len, const unsigned char *d, int n,
16                            unsigned char *md, unsigned int *md_len);
17
18        HMAC_CTX *HMAC_CTX_new(void);
19        int HMAC_CTX_reset(HMAC_CTX *ctx);
20
21        int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
22                         const EVP_MD *md, ENGINE *impl);
23        int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
24        int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
25
26        void HMAC_CTX_free(HMAC_CTX *ctx);
27
28        int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
29        void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
30        const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
31
32        size_t HMAC_size(const HMAC_CTX *e);
33
34       Deprecated:
35
36        #if OPENSSL_API_COMPAT < 0x10100000L
37        int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
38                      const EVP_MD *md);
39        #endif
40

DESCRIPTION

42       HMAC is a MAC (message authentication code), i.e. a keyed hash function
43       used for message authentication, which is based on a hash function.
44
45       HMAC() computes the message authentication code of the n bytes at d
46       using the hash function evp_md and the key key which is key_len bytes
47       long.
48
49       It places the result in md (which must have space for the output of the
50       hash function, which is no more than EVP_MAX_MD_SIZE bytes).  If md is
51       NULL, the digest is placed in a static array.  The size of the output
52       is placed in md_len, unless it is NULL. Note: passing a NULL value for
53       md  to use the static array is not thread safe.
54
55       evp_md is a message digest such as EVP_sha1(), EVP_ripemd160() etc.
56       HMAC does not support variable output length digests such as
57       EVP_shake128() and EVP_shake256().
58
59       HMAC_CTX_new() creates a new HMAC_CTX in heap memory.
60
61       HMAC_CTX_reset() zeroes an existing HMAC_CTX and associated resources,
62       making it suitable for new computations as if it was newly created with
63       HMAC_CTX_new().
64
65       HMAC_CTX_free() erases the key and other data from the HMAC_CTX,
66       releases any associated resources and finally frees the HMAC_CTX
67       itself.
68
69       The following functions may be used if the message is not completely
70       stored in memory:
71
72       HMAC_Init_ex() initializes or reuses a HMAC_CTX structure to use the
73       hash function evp_md and key key. If both are NULL, or if key is NULL
74       and evp_md is the same as the previous call, then the existing key is
75       reused. ctx must have been created with HMAC_CTX_new() before the first
76       use of an HMAC_CTX in this function.
77
78       If HMAC_Init_ex() is called with key NULL and evp_md is not the same as
79       the previous digest used by ctx then an error is returned because reuse
80       of an existing key with a different digest is not supported.
81
82       HMAC_Init() initializes a HMAC_CTX structure to use the hash function
83       evp_md and the key key which is key_len bytes long.
84
85       HMAC_Update() can be called repeatedly with chunks of the message to be
86       authenticated (len bytes at data).
87
88       HMAC_Final() places the message authentication code in md, which must
89       have space for the hash function output.
90
91       HMAC_CTX_copy() copies all of the internal state from sctx into dctx.
92
93       HMAC_CTX_set_flags() applies the specified flags to the internal
94       EVP_MD_CTXs.  These flags have the same meaning as for
95       EVP_MD_CTX_set_flags(3).
96
97       HMAC_CTX_get_md() returns the EVP_MD that has previously been set for
98       the supplied HMAC_CTX.
99
100       HMAC_size() returns the length in bytes of the underlying hash function
101       output.
102

RETURN VALUES

104       HMAC() returns a pointer to the message authentication code or NULL if
105       an error occurred.
106
107       HMAC_CTX_new() returns a pointer to a new HMAC_CTX on success or NULL
108       if an error occurred.
109
110       HMAC_CTX_reset(), HMAC_Init_ex(), HMAC_Update(), HMAC_Final() and
111       HMAC_CTX_copy() return 1 for success or 0 if an error occurred.
112
113       HMAC_CTX_get_md() return the EVP_MD previously set for the supplied
114       HMAC_CTX or NULL if no EVP_MD has been set.
115
116       HMAC_size() returns the length in bytes of the underlying hash function
117       output or zero on error.
118

CONFORMING TO

120       RFC 2104
121

SEE ALSO

123       SHA1(3), evp(7)
124

HISTORY

126       HMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL 1.1.0.
127
128       HMAC_CTX_cleanup() existed in OpenSSL before version 1.1.0.
129
130       HMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in
131       OpenSSL 1.1.0.
132
133       HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
134       OpenSSL before version 1.0.0.
135
137       Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
138
139       Licensed under the OpenSSL license (the "License").  You may not use
140       this file except in compliance with the License.  You can obtain a copy
141       in the file LICENSE in the source distribution or at
142       <https://www.openssl.org/source/license.html>.
143
144
145
1461.1.1d                            2019-10-03                           HMAC(3)
Impressum