1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimHMAC, 6e71b7053SJung-uk KimHMAC_CTX_new, 7e71b7053SJung-uk KimHMAC_CTX_reset, 8e71b7053SJung-uk KimHMAC_CTX_free, 9e71b7053SJung-uk KimHMAC_Init, 10e71b7053SJung-uk KimHMAC_Init_ex, 11e71b7053SJung-uk KimHMAC_Update, 12e71b7053SJung-uk KimHMAC_Final, 13e71b7053SJung-uk KimHMAC_CTX_copy, 14e71b7053SJung-uk KimHMAC_CTX_set_flags, 15e71b7053SJung-uk KimHMAC_CTX_get_md, 16e71b7053SJung-uk KimHMAC_size 17e71b7053SJung-uk Kim- HMAC message authentication code 18e71b7053SJung-uk Kim 19e71b7053SJung-uk Kim=head1 SYNOPSIS 20e71b7053SJung-uk Kim 21e71b7053SJung-uk Kim #include <openssl/hmac.h> 22e71b7053SJung-uk Kim 23e71b7053SJung-uk Kim unsigned char *HMAC(const EVP_MD *evp_md, const void *key, 24e71b7053SJung-uk Kim int key_len, const unsigned char *d, int n, 25e71b7053SJung-uk Kim unsigned char *md, unsigned int *md_len); 26e71b7053SJung-uk Kim 27e71b7053SJung-uk Kim HMAC_CTX *HMAC_CTX_new(void); 28e71b7053SJung-uk Kim int HMAC_CTX_reset(HMAC_CTX *ctx); 29e71b7053SJung-uk Kim 30e71b7053SJung-uk Kim int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, 31e71b7053SJung-uk Kim const EVP_MD *md, ENGINE *impl); 32e71b7053SJung-uk Kim int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len); 33e71b7053SJung-uk Kim int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 34e71b7053SJung-uk Kim 35e71b7053SJung-uk Kim void HMAC_CTX_free(HMAC_CTX *ctx); 36e71b7053SJung-uk Kim 37e71b7053SJung-uk Kim int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); 38e71b7053SJung-uk Kim void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); 39e71b7053SJung-uk Kim const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx); 40e71b7053SJung-uk Kim 41e71b7053SJung-uk Kim size_t HMAC_size(const HMAC_CTX *e); 42e71b7053SJung-uk Kim 43e71b7053SJung-uk KimDeprecated: 44e71b7053SJung-uk Kim 45e71b7053SJung-uk Kim #if OPENSSL_API_COMPAT < 0x10100000L 46e71b7053SJung-uk Kim int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len, 47e71b7053SJung-uk Kim const EVP_MD *md); 48e71b7053SJung-uk Kim #endif 49e71b7053SJung-uk Kim 50e71b7053SJung-uk Kim=head1 DESCRIPTION 51e71b7053SJung-uk Kim 52e71b7053SJung-uk KimHMAC is a MAC (message authentication code), i.e. a keyed hash 53e71b7053SJung-uk Kimfunction used for message authentication, which is based on a hash 54e71b7053SJung-uk Kimfunction. 55e71b7053SJung-uk Kim 56e71b7053SJung-uk KimHMAC() computes the message authentication code of the B<n> bytes at 57e71b7053SJung-uk KimB<d> using the hash function B<evp_md> and the key B<key> which is 58e71b7053SJung-uk KimB<key_len> bytes long. 59e71b7053SJung-uk Kim 60e71b7053SJung-uk KimIt places the result in B<md> (which must have space for the output of 61e71b7053SJung-uk Kimthe hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes). 62e71b7053SJung-uk KimIf B<md> is NULL, the digest is placed in a static array. The size of 63e71b7053SJung-uk Kimthe output is placed in B<md_len>, unless it is B<NULL>. Note: passing a NULL 64e71b7053SJung-uk Kimvalue for B<md> to use the static array is not thread safe. 65e71b7053SJung-uk Kim 66*610a21fdSJung-uk KimB<evp_md> is a message digest such as EVP_sha1(), EVP_ripemd160() etc. HMAC does 67*610a21fdSJung-uk Kimnot support variable output length digests such as EVP_shake128() and 68*610a21fdSJung-uk KimEVP_shake256(). 69e71b7053SJung-uk Kim 70e71b7053SJung-uk KimHMAC_CTX_new() creates a new HMAC_CTX in heap memory. 71e71b7053SJung-uk Kim 72e71b7053SJung-uk KimHMAC_CTX_reset() zeroes an existing B<HMAC_CTX> and associated 73e71b7053SJung-uk Kimresources, making it suitable for new computations as if it was newly 74e71b7053SJung-uk Kimcreated with HMAC_CTX_new(). 75e71b7053SJung-uk Kim 76e71b7053SJung-uk KimHMAC_CTX_free() erases the key and other data from the B<HMAC_CTX>, 77e71b7053SJung-uk Kimreleases any associated resources and finally frees the B<HMAC_CTX> 78e71b7053SJung-uk Kimitself. 79e71b7053SJung-uk Kim 80e71b7053SJung-uk KimThe following functions may be used if the message is not completely 81e71b7053SJung-uk Kimstored in memory: 82e71b7053SJung-uk Kim 83e71b7053SJung-uk KimHMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use the hash 84e71b7053SJung-uk Kimfunction B<evp_md> and key B<key>. If both are NULL, or if B<key> is NULL 85e71b7053SJung-uk Kimand B<evp_md> is the same as the previous call, then the 86e71b7053SJung-uk Kimexisting key is 87e71b7053SJung-uk Kimreused. B<ctx> must have been created with HMAC_CTX_new() before the first use 88e71b7053SJung-uk Kimof an B<HMAC_CTX> in this function. 89e71b7053SJung-uk Kim 90e71b7053SJung-uk KimIf HMAC_Init_ex() is called with B<key> NULL and B<evp_md> is not the 91e71b7053SJung-uk Kimsame as the previous digest used by B<ctx> then an error is returned 92e71b7053SJung-uk Kimbecause reuse of an existing key with a different digest is not supported. 93e71b7053SJung-uk Kim 94e71b7053SJung-uk KimHMAC_Init() initializes a B<HMAC_CTX> structure to use the hash 95e71b7053SJung-uk Kimfunction B<evp_md> and the key B<key> which is B<key_len> bytes 96e71b7053SJung-uk Kimlong. 97e71b7053SJung-uk Kim 98e71b7053SJung-uk KimHMAC_Update() can be called repeatedly with chunks of the message to 99e71b7053SJung-uk Kimbe authenticated (B<len> bytes at B<data>). 100e71b7053SJung-uk Kim 101e71b7053SJung-uk KimHMAC_Final() places the message authentication code in B<md>, which 102e71b7053SJung-uk Kimmust have space for the hash function output. 103e71b7053SJung-uk Kim 104e71b7053SJung-uk KimHMAC_CTX_copy() copies all of the internal state from B<sctx> into B<dctx>. 105e71b7053SJung-uk Kim 106e71b7053SJung-uk KimHMAC_CTX_set_flags() applies the specified flags to the internal EVP_MD_CTXs. 107e71b7053SJung-uk KimThese flags have the same meaning as for L<EVP_MD_CTX_set_flags(3)>. 108e71b7053SJung-uk Kim 109e71b7053SJung-uk KimHMAC_CTX_get_md() returns the EVP_MD that has previously been set for the 110e71b7053SJung-uk Kimsupplied HMAC_CTX. 111e71b7053SJung-uk Kim 112e71b7053SJung-uk KimHMAC_size() returns the length in bytes of the underlying hash function output. 113e71b7053SJung-uk Kim 114e71b7053SJung-uk Kim=head1 RETURN VALUES 115e71b7053SJung-uk Kim 116e71b7053SJung-uk KimHMAC() returns a pointer to the message authentication code or NULL if 117e71b7053SJung-uk Kiman error occurred. 118e71b7053SJung-uk Kim 119e71b7053SJung-uk KimHMAC_CTX_new() returns a pointer to a new B<HMAC_CTX> on success or 120e71b7053SJung-uk KimB<NULL> if an error occurred. 121e71b7053SJung-uk Kim 122e71b7053SJung-uk KimHMAC_CTX_reset(), HMAC_Init_ex(), HMAC_Update(), HMAC_Final() and 123e71b7053SJung-uk KimHMAC_CTX_copy() return 1 for success or 0 if an error occurred. 124e71b7053SJung-uk Kim 125e71b7053SJung-uk KimHMAC_CTX_get_md() return the EVP_MD previously set for the supplied HMAC_CTX or 126e71b7053SJung-uk KimNULL if no EVP_MD has been set. 127e71b7053SJung-uk Kim 128e71b7053SJung-uk KimHMAC_size() returns the length in bytes of the underlying hash function output 129e71b7053SJung-uk Kimor zero on error. 130e71b7053SJung-uk Kim 131e71b7053SJung-uk Kim=head1 CONFORMING TO 132e71b7053SJung-uk Kim 133e71b7053SJung-uk KimRFC 2104 134e71b7053SJung-uk Kim 135e71b7053SJung-uk Kim=head1 SEE ALSO 136e71b7053SJung-uk Kim 137e71b7053SJung-uk KimL<SHA1(3)>, L<evp(7)> 138e71b7053SJung-uk Kim 139e71b7053SJung-uk Kim=head1 HISTORY 140e71b7053SJung-uk Kim 141e71b7053SJung-uk KimHMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL 1.1.0. 142e71b7053SJung-uk Kim 143e71b7053SJung-uk KimHMAC_CTX_cleanup() existed in OpenSSL before version 1.1.0. 144e71b7053SJung-uk Kim 145e71b7053SJung-uk KimHMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in OpenSSL 1.1.0. 146e71b7053SJung-uk Kim 147e71b7053SJung-uk KimHMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in 148e71b7053SJung-uk KimOpenSSL before version 1.0.0. 149e71b7053SJung-uk Kim 150e71b7053SJung-uk Kim=head1 COPYRIGHT 151e71b7053SJung-uk Kim 1526935a639SJung-uk KimCopyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. 153e71b7053SJung-uk Kim 154e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 155e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 156e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 157e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 158e71b7053SJung-uk Kim 159e71b7053SJung-uk Kim=cut 160