159191Skris=pod 259191Skris 359191Skris=head1 NAME 459191Skris 5290207SjkimHMAC, HMAC_CTX_init, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final, HMAC_CTX_cleanup, 6290207SjkimHMAC_cleanup - HMAC message authentication code 759191Skris 859191Skris=head1 SYNOPSIS 959191Skris 1059191Skris #include <openssl/hmac.h> 1159191Skris 1259191Skris unsigned char *HMAC(const EVP_MD *evp_md, const void *key, 1359191Skris int key_len, const unsigned char *d, int n, 1459191Skris unsigned char *md, unsigned int *md_len); 1559191Skris 16109998Smarkm void HMAC_CTX_init(HMAC_CTX *ctx); 17109998Smarkm 18238405Sjkim int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len, 1959191Skris const EVP_MD *md); 20238405Sjkim int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, 21160814Ssimon const EVP_MD *md, ENGINE *impl); 22238405Sjkim int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len); 23238405Sjkim int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 2459191Skris 25109998Smarkm void HMAC_CTX_cleanup(HMAC_CTX *ctx); 2659191Skris void HMAC_cleanup(HMAC_CTX *ctx); 2759191Skris 2859191Skris=head1 DESCRIPTION 2959191Skris 3059191SkrisHMAC is a MAC (message authentication code), i.e. a keyed hash 3159191Skrisfunction used for message authentication, which is based on a hash 3259191Skrisfunction. 3359191Skris 3459191SkrisHMAC() computes the message authentication code of the B<n> bytes at 3559191SkrisB<d> using the hash function B<evp_md> and the key B<key> which is 3659191SkrisB<key_len> bytes long. 3759191Skris 3859191SkrisIt places the result in B<md> (which must have space for the output of 3959191Skristhe hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes). 4059191SkrisIf B<md> is NULL, the digest is placed in a static array. The size of 41325337Sjkimthe output is placed in B<md_len>, unless it is B<NULL>. Note: passing a NULL 42325337Sjkimvalue for B<md> to use the static array is not thread safe. 4359191Skris 4459191SkrisB<evp_md> can be EVP_sha1(), EVP_ripemd160() etc. 4559191Skris 46109998SmarkmHMAC_CTX_init() initialises a B<HMAC_CTX> before first use. It must be 47109998Smarkmcalled. 4859191Skris 49109998SmarkmHMAC_CTX_cleanup() erases the key and other data from the B<HMAC_CTX> 50109998Smarkmand releases any associated resources. It must be called when an 51109998SmarkmB<HMAC_CTX> is no longer required. 52109998Smarkm 53109998SmarkmHMAC_cleanup() is an alias for HMAC_CTX_cleanup() included for back 54109998Smarkmcompatibility with 0.9.6b, it is deprecated. 55109998Smarkm 5659191SkrisThe following functions may be used if the message is not completely 5759191Skrisstored in memory: 5859191Skris 5959191SkrisHMAC_Init() initializes a B<HMAC_CTX> structure to use the hash 60109998Smarkmfunction B<evp_md> and the key B<key> which is B<key_len> bytes 61109998Smarkmlong. It is deprecated and only included for backward compatibility 62109998Smarkmwith OpenSSL 0.9.6b. 6359191Skris 64306195SjkimHMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use the hash 65306195Sjkimfunction B<evp_md> and key B<key>. If both are NULL (or B<evp_md> is the same 66306195Sjkimas the previous digest used by B<ctx> and B<key> is NULL) the existing key is 67306195Sjkimreused. B<ctx> must have been created with HMAC_CTX_new() before the first use 68306195Sjkimof an B<HMAC_CTX> in this function. B<N.B. HMAC_Init() had this undocumented 69306195Sjkimbehaviour in previous versions of OpenSSL - failure to switch to HMAC_Init_ex() 70306195Sjkimin programs that expect it will cause them to stop working>. 71109998Smarkm 72306195SjkimB<NB: if HMAC_Init_ex() is called with B<key> NULL and B<evp_md> is not the 73306195Sjkimsame as the previous digest used by B<ctx> then an error is returned 74306195Sjkimbecause reuse of an existing key with a different digest is not supported.> 75306195Sjkim 7659191SkrisHMAC_Update() can be called repeatedly with chunks of the message to 7759191Skrisbe authenticated (B<len> bytes at B<data>). 7859191Skris 7959191SkrisHMAC_Final() places the message authentication code in B<md>, which 8059191Skrismust have space for the hash function output. 8159191Skris 8259191Skris=head1 RETURN VALUES 8359191Skris 84238405SjkimHMAC() returns a pointer to the message authentication code or NULL if 85238405Sjkiman error occurred. 8659191Skris 87238405SjkimHMAC_Init_ex(), HMAC_Update() and HMAC_Final() return 1 for success or 0 if 88238405Sjkiman error occurred. 8959191Skris 90238405SjkimHMAC_CTX_init() and HMAC_CTX_cleanup() do not return values. 91238405Sjkim 9259191Skris=head1 CONFORMING TO 9359191Skris 9459191SkrisRFC 2104 9559191Skris 9659191Skris=head1 SEE ALSO 9759191Skris 9859191SkrisL<sha(3)|sha(3)>, L<evp(3)|evp(3)> 9959191Skris 10059191Skris=head1 HISTORY 10159191Skris 10259191SkrisHMAC(), HMAC_Init(), HMAC_Update(), HMAC_Final() and HMAC_cleanup() 10359191Skrisare available since SSLeay 0.9.0. 10459191Skris 105109998SmarkmHMAC_CTX_init(), HMAC_Init_ex() and HMAC_CTX_cleanup() are available 106109998Smarkmsince OpenSSL 0.9.7. 107109998Smarkm 108238405SjkimHMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in 109238405Sjkimversions of OpenSSL before 1.0.0. 110238405Sjkim 11159191Skris=cut 112