1hmac(3)                             OpenSSL                            hmac(3)
2
3
4

NAME

6       HMAC, HMAC_CTX_init, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final,
7       HMAC_CTX_cleanup, HMAC_cleanup - HMAC message authentication code
8

SYNOPSIS

10        #include <openssl/hmac.h>
11
12        unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
13                      int key_len, const unsigned char *d, int n,
14                      unsigned char *md, unsigned int *md_len);
15
16        void HMAC_CTX_init(HMAC_CTX *ctx);
17
18        int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
19                      const EVP_MD *md);
20        int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
21                          const EVP_MD *md, ENGINE *impl);
22        int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
23        int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
24
25        void HMAC_CTX_cleanup(HMAC_CTX *ctx);
26        void HMAC_cleanup(HMAC_CTX *ctx);
27

DESCRIPTION

29       HMAC is a MAC (message authentication code), i.e. a keyed hash function
30       used for message authentication, which is based on a hash function.
31
32       HMAC() computes the message authentication code of the n bytes at d
33       using the hash function evp_md and the key key which is key_len bytes
34       long.
35
36       It places the result in md (which must have space for the output of the
37       hash function, which is no more than EVP_MAX_MD_SIZE bytes).  If md is
38       NULL, the digest is placed in a static array.  The size of the output
39       is placed in md_len, unless it is NULL.
40
41       evp_md can be EVP_sha1(), EVP_ripemd160() etc.
42
43       HMAC_CTX_init() initialises a HMAC_CTX before first use. It must be
44       called.
45
46       HMAC_CTX_cleanup() erases the key and other data from the HMAC_CTX and
47       releases any associated resources. It must be called when an HMAC_CTX
48       is no longer required.
49
50       HMAC_cleanup() is an alias for HMAC_CTX_cleanup() included for back
51       compatibility with 0.9.6b, it is deprecated.
52
53       The following functions may be used if the message is not completely
54       stored in memory:
55
56       HMAC_Init() initializes a HMAC_CTX structure to use the hash function
57       evp_md and the key key which is key_len bytes long. It is deprecated
58       and only included for backward compatibility with OpenSSL 0.9.6b.
59
60       HMAC_Init_ex() initializes or reuses a HMAC_CTX structure to use the
61       hash function evp_md and key key. If both are NULL (or evp_md is the
62       same as the previous digest used by ctx and key is NULL) the existing
63       key is reused. ctx must have been created with HMAC_CTX_new() before
64       the first use of an HMAC_CTX in this function. N.B. HMAC_Init() had
65       this undocumented behaviour in previous versions of OpenSSL - failure
66       to switch to HMAC_Init_ex() in programs that expect it will cause them
67       to stop working.
68
69       NB: if HMAC_Init_ex() is called with key NULL and evp_md is not the
70       same as the previous digest used by ctx then an error is returned
71       because reuse of an existing key with a different digest is not
72       supported.
73
74       HMAC_Update() can be called repeatedly with chunks of the message to be
75       authenticated (len bytes at data).
76
77       HMAC_Final() places the message authentication code in md, which must
78       have space for the hash function output.
79

RETURN VALUES

81       HMAC() returns a pointer to the message authentication code or NULL if
82       an error occurred.
83
84       HMAC_Init_ex(), HMAC_Update() and HMAC_Final() return 1 for success or
85       0 if an error occurred.
86
87       HMAC_CTX_init() and HMAC_CTX_cleanup() do not return values.
88

CONFORMING TO

90       RFC 2104
91

SEE ALSO

93       sha(3), evp(3)
94

HISTORY

96       HMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup() are
97       available since SSLeay 0.9.0.
98
99       HMAC_CTX_init(), HMAC_Init_ex() and HMAC_CTX_cleanup() are available
100       since OpenSSL 0.9.7.
101
102       HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
103       versions of OpenSSL before 1.0.0.
104
105
106
1071.0.2k                            2017-01-26                           hmac(3)
Impressum