HMAC.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?xml version="1.0" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>HMAC</title>
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7. <link rev="made" href="mailto:root@localhost" />
  8. </head>
  9. <body>
  10. <ul id="index">
  11. <li><a href="#NAME">NAME</a></li>
  12. <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  13. <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
  14. <li><a href="#RETURN-VALUES">RETURN VALUES</a></li>
  15. <li><a href="#CONFORMING-TO">CONFORMING TO</a></li>
  16. <li><a href="#SEE-ALSO">SEE ALSO</a></li>
  17. <li><a href="#HISTORY">HISTORY</a></li>
  18. <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
  19. </ul>
  20. <h1 id="NAME">NAME</h1>
  21. <p>HMAC, HMAC_CTX_new, HMAC_CTX_reset, HMAC_CTX_free, HMAC_Init, HMAC_Init_ex, HMAC_Update, HMAC_Final, HMAC_CTX_copy, HMAC_CTX_set_flags, HMAC_CTX_get_md, HMAC_size - HMAC message authentication code</p>
  22. <h1 id="SYNOPSIS">SYNOPSIS</h1>
  23. <pre><code>#include &lt;openssl/hmac.h&gt;
  24. unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
  25. const unsigned char *data, size_t data_len,
  26. unsigned char *md, unsigned int *md_len);</code></pre>
  27. <p>The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by defining <b>OPENSSL_API_COMPAT</b> with a suitable version value, see <a href="../man7/openssl_user_macros.html">openssl_user_macros(7)</a>:</p>
  28. <pre><code>HMAC_CTX *HMAC_CTX_new(void);
  29. int HMAC_CTX_reset(HMAC_CTX *ctx);
  30. int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
  31. const EVP_MD *md, ENGINE *impl);
  32. int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
  33. int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
  34. void HMAC_CTX_free(HMAC_CTX *ctx);
  35. int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
  36. void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
  37. const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
  38. size_t HMAC_size(const HMAC_CTX *e);</code></pre>
  39. <p>The following function has been deprecated since OpenSSL 1.1.0, and can be hidden entirely by defining <b>OPENSSL_API_COMPAT</b> with a suitable version value, see <a href="../man7/openssl_user_macros.html">openssl_user_macros(7)</a>:</p>
  40. <pre><code>int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
  41. const EVP_MD *md);</code></pre>
  42. <h1 id="DESCRIPTION">DESCRIPTION</h1>
  43. <p>HMAC is a MAC (message authentication code), i.e. a keyed hash function used for message authentication, which is based on a hash function.</p>
  44. <p>HMAC() computes the message authentication code of the <i>data_len</i> bytes at <i>data</i> using the hash function <i>evp_md</i> and the key <i>key</i> which is <i>key_len</i> bytes long. The <i>key</i> may also be NULL with <i>key_len</i> being 0.</p>
  45. <p>It places the result in <i>md</i> (which must have space for the output of the hash function, which is no more than <b>EVP_MAX_MD_SIZE</b> bytes). If <i>md</i> is NULL, the digest is placed in a static array. The size of the output is placed in <i>md_len</i>, unless it is NULL. Note: passing a NULL value for <i>md</i> to use the static array is not thread safe.</p>
  46. <p><i>evp_md</i> is a message digest such as EVP_sha1(), EVP_ripemd160() etc. HMAC does not support variable output length digests such as EVP_shake128() and EVP_shake256().</p>
  47. <p>HMAC() uses the default <b>OSSL_LIB_CTX</b>. Use <a href="../man3/EVP_Q_mac.html">EVP_Q_mac(3)</a> instead if a library context is required.</p>
  48. <p>All of the functions described below are deprecated. Applications should instead use <a href="../man3/EVP_MAC_CTX_new.html">EVP_MAC_CTX_new(3)</a>, <a href="../man3/EVP_MAC_CTX_free.html">EVP_MAC_CTX_free(3)</a>, <a href="../man3/EVP_MAC_init.html">EVP_MAC_init(3)</a>, <a href="../man3/EVP_MAC_update.html">EVP_MAC_update(3)</a> and <a href="../man3/EVP_MAC_final.html">EVP_MAC_final(3)</a> or the &#39;quick&#39; single-shot MAC function <a href="../man3/EVP_Q_mac.html">EVP_Q_mac(3)</a>.</p>
  49. <p>HMAC_CTX_new() creates a new HMAC_CTX in heap memory.</p>
  50. <p>HMAC_CTX_reset() clears an existing <b>HMAC_CTX</b> and associated resources, making it suitable for new computations as if it was newly created with HMAC_CTX_new().</p>
  51. <p>HMAC_CTX_free() erases the key and other data from the <b>HMAC_CTX</b>, releases any associated resources and finally frees the <b>HMAC_CTX</b> itself. If the argument is NULL, nothing is done.</p>
  52. <p>The following functions may be used if the message is not completely stored in memory:</p>
  53. <p>HMAC_Init_ex() initializes or reuses a <b>HMAC_CTX</b> structure to use the hash function <i>evp_md</i> and key <i>key</i>. If both are NULL, or if <i>key</i> is NULL and <i>evp_md</i> is the same as the previous call, then the existing key is reused. <i>ctx</i> must have been created with HMAC_CTX_new() before the first use of an <b>HMAC_CTX</b> in this function.</p>
  54. <p>If HMAC_Init_ex() is called with <i>key</i> NULL and <i>evp_md</i> is not the same as the previous digest used by <i>ctx</i> then an error is returned because reuse of an existing key with a different digest is not supported.</p>
  55. <p>HMAC_Init() initializes a <b>HMAC_CTX</b> structure to use the hash function <i>evp_md</i> and the key <i>key</i> which is <i>key_len</i> bytes long.</p>
  56. <p>HMAC_Update() can be called repeatedly with chunks of the message to be authenticated (<i>len</i> bytes at <i>data</i>).</p>
  57. <p>HMAC_Final() places the message authentication code in <i>md</i>, which must have space for the hash function output.</p>
  58. <p>HMAC_CTX_copy() copies all of the internal state from <i>sctx</i> into <i>dctx</i>.</p>
  59. <p>HMAC_CTX_set_flags() applies the specified flags to the internal EVP_MD_CTXs. These flags have the same meaning as for <a href="../man3/EVP_MD_CTX_set_flags.html">EVP_MD_CTX_set_flags(3)</a>.</p>
  60. <p>HMAC_CTX_get_md() returns the EVP_MD that has previously been set for the supplied HMAC_CTX.</p>
  61. <p>HMAC_size() returns the length in bytes of the underlying hash function output.</p>
  62. <h1 id="RETURN-VALUES">RETURN VALUES</h1>
  63. <p>HMAC() returns a pointer to the message authentication code or NULL if an error occurred.</p>
  64. <p>HMAC_CTX_new() returns a pointer to a new <b>HMAC_CTX</b> on success or NULL if an error occurred.</p>
  65. <p>HMAC_CTX_reset(), HMAC_Init_ex(), HMAC_Update(), HMAC_Final() and HMAC_CTX_copy() return 1 for success or 0 if an error occurred.</p>
  66. <p>HMAC_CTX_get_md() return the EVP_MD previously set for the supplied HMAC_CTX or NULL if no EVP_MD has been set.</p>
  67. <p>HMAC_size() returns the length in bytes of the underlying hash function output or zero on error.</p>
  68. <h1 id="CONFORMING-TO">CONFORMING TO</h1>
  69. <p>RFC 2104</p>
  70. <h1 id="SEE-ALSO">SEE ALSO</h1>
  71. <p><a href="../man3/SHA1.html">SHA1(3)</a>, EVP_Q_mac(3), <a href="../man7/evp.html">evp(7)</a></p>
  72. <h1 id="HISTORY">HISTORY</h1>
  73. <p>All functions except for HMAC() were deprecated in OpenSSL 3.0.</p>
  74. <p>HMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL 1.1.0.</p>
  75. <p>HMAC_CTX_cleanup() existed in OpenSSL before version 1.1.0.</p>
  76. <p>HMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in OpenSSL 1.1.0.</p>
  77. <p>HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in OpenSSL before version 1.0.0.</p>
  78. <h1 id="COPYRIGHT">COPYRIGHT</h1>
  79. <p>Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved.</p>
  80. <p>Licensed under the Apache License 2.0 (the &quot;License&quot;). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
  81. </body>
  82. </html>