5 HMAC, HMAC_CTX_init, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final, HMAC_CTX_cleanup - HMAC message authentication code
9 #include <openssl/hmac.h>
11 unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
12 int key_len, const unsigned char *d, int n,
13 unsigned char *md, unsigned int *md_len);
15 void HMAC_CTX_init(HMAC_CTX *ctx);
17 int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
19 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
20 const EVP_MD *md, ENGINE *impl);
21 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
22 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
24 void HMAC_CTX_cleanup(HMAC_CTX *ctx);
28 HMAC is a MAC (message authentication code), i.e. a keyed hash
29 function used for message authentication, which is based on a hash
32 HMAC() computes the message authentication code of the B<n> bytes at
33 B<d> using the hash function B<evp_md> and the key B<key> which is
34 B<key_len> bytes long.
36 It places the result in B<md> (which must have space for the output of
37 the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
38 If B<md> is NULL, the digest is placed in a static array. The size of
39 the output is placed in B<md_len>, unless it is B<NULL>.
41 B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
43 HMAC_CTX_init() initialises a B<HMAC_CTX> before first use. It must be
46 HMAC_CTX_cleanup() erases the key and other data from the B<HMAC_CTX>
47 and releases any associated resources. It must be called when an
48 B<HMAC_CTX> is no longer required.
50 The following functions may be used if the message is not completely
53 HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
54 function B<evp_md> and the key B<key> which is B<key_len> bytes
55 long. It is deprecated and only included for backward compatibility
58 HMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use
59 the function B<evp_md> and key B<key>. Either can be NULL, in which
60 case the existing one will be reused. HMAC_CTX_init() must have been
61 called before the first use of an B<HMAC_CTX> in this
62 function. B<N.B. HMAC_Init() had this undocumented behaviour in
63 previous versions of OpenSSL - failure to switch to HMAC_Init_ex() in
64 programs that expect it will cause them to stop working>.
66 HMAC_Update() can be called repeatedly with chunks of the message to
67 be authenticated (B<len> bytes at B<data>).
69 HMAC_Final() places the message authentication code in B<md>, which
70 must have space for the hash function output.
74 HMAC() returns a pointer to the message authentication code or NULL if
77 HMAC_Init_ex(), HMAC_Update() and HMAC_Final() return 1 for success or 0 if
80 HMAC_CTX_init() and HMAC_CTX_cleanup() do not return values.
92 HMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup()
93 are available since SSLeay 0.9.0.
95 HMAC_CTX_init(), HMAC_Init_ex() and HMAC_CTX_cleanup() are available
98 HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
99 versions of OpenSSL before 1.0.0.