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 can be EVP_sha1(), EVP_ripemd160() etc.
56
57       HMAC_CTX_new() creates a new HMAC_CTX in heap memory.
58
59       HMAC_CTX_reset() zeroes an existing HMAC_CTX and associated resources,
60       making it suitable for new computations as if it was newly created with
61       HMAC_CTX_new().
62
63       HMAC_CTX_free() erases the key and other data from the HMAC_CTX,
64       releases any associated resources and finally frees the HMAC_CTX
65       itself.
66
67       The following functions may be used if the message is not completely
68       stored in memory:
69
70       HMAC_Init_ex() initializes or reuses a HMAC_CTX structure to use the
71       hash function evp_md and key key. If both are NULL, or if key is NULL
72       and evp_md is the same as the previous call, then the existing key is
73       reused. ctx must have been created with HMAC_CTX_new() before the first
74       use of an HMAC_CTX in this function.
75
76       If HMAC_Init_ex() is called with key NULL and evp_md is not the same as
77       the previous digest used by ctx then an error is returned because reuse
78       of an existing key with a different digest is not supported.
79
80       HMAC_Init() initializes a HMAC_CTX structure to use the hash function
81       evp_md and the key key which is key_len bytes long.
82
83       HMAC_Update() can be called repeatedly with chunks of the message to be
84       authenticated (len bytes at data).
85
86       HMAC_Final() places the message authentication code in md, which must
87       have space for the hash function output.
88
89       HMAC_CTX_copy() copies all of the internal state from sctx into dctx.
90
91       HMAC_CTX_set_flags() applies the specified flags to the internal
92       EVP_MD_CTXs.  These flags have the same meaning as for
93       EVP_MD_CTX_set_flags(3).
94
95       HMAC_CTX_get_md() returns the EVP_MD that has previously been set for
96       the supplied HMAC_CTX.
97
98       HMAC_size() returns the length in bytes of the underlying hash function
99       output.
100

RETURN VALUES

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

CONFORMING TO

118       RFC 2104
119

SEE ALSO

121       SHA1(3), evp(7)
122

HISTORY

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