HMAC.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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,
  25. int key_len, const unsigned char *d, size_t n,
  26. unsigned char *md, unsigned int *md_len);
  27. HMAC_CTX *HMAC_CTX_new(void);
  28. int HMAC_CTX_reset(HMAC_CTX *ctx);
  29. int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
  30. const EVP_MD *md, ENGINE *impl);
  31. int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
  32. int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
  33. void HMAC_CTX_free(HMAC_CTX *ctx);
  34. int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
  35. void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
  36. const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
  37. size_t HMAC_size(const HMAC_CTX *e);</code></pre>
  38. <p>Deprecated:</p>
  39. <pre><code> #if OPENSSL_API_COMPAT &lt; 0x10100000L
  40. int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
  41. const EVP_MD *md);
  42. #endif</code></pre>
  43. <h1 id="DESCRIPTION">DESCRIPTION</h1>
  44. <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>
  45. <p>HMAC() computes the message authentication code of the <b>n</b> bytes at <b>d</b> using the hash function <b>evp_md</b> and the key <b>key</b> which is <b>key_len</b> bytes long.</p>
  46. <p>It places the result in <b>md</b> (which must have space for the output of the hash function, which is no more than <b>EVP_MAX_MD_SIZE</b> bytes). If <b>md</b> is NULL, the digest is placed in a static array. The size of the output is placed in <b>md_len</b>, unless it is <b>NULL</b>. Note: passing a NULL value for <b>md</b> to use the static array is not thread safe.</p>
  47. <p><b>evp_md</b> 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>
  48. <p>HMAC_CTX_new() creates a new HMAC_CTX in heap memory.</p>
  49. <p>HMAC_CTX_reset() zeros 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>
  50. <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.</p>
  51. <p>The following functions may be used if the message is not completely stored in memory:</p>
  52. <p>HMAC_Init_ex() initializes or reuses a <b>HMAC_CTX</b> structure to use the hash function <b>evp_md</b> and key <b>key</b>. If both are NULL, or if <b>key</b> is NULL and <b>evp_md</b> is the same as the previous call, then the existing key is reused. <b>ctx</b> must have been created with HMAC_CTX_new() before the first use of an <b>HMAC_CTX</b> in this function.</p>
  53. <p>If HMAC_Init_ex() is called with <b>key</b> NULL and <b>evp_md</b> is not the same as the previous digest used by <b>ctx</b> then an error is returned because reuse of an existing key with a different digest is not supported.</p>
  54. <p>HMAC_Init() initializes a <b>HMAC_CTX</b> structure to use the hash function <b>evp_md</b> and the key <b>key</b> which is <b>key_len</b> bytes long.</p>
  55. <p>HMAC_Update() can be called repeatedly with chunks of the message to be authenticated (<b>len</b> bytes at <b>data</b>).</p>
  56. <p>HMAC_Final() places the message authentication code in <b>md</b>, which must have space for the hash function output.</p>
  57. <p>HMAC_CTX_copy() copies all of the internal state from <b>sctx</b> into <b>dctx</b>.</p>
  58. <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>
  59. <p>HMAC_CTX_get_md() returns the EVP_MD that has previously been set for the supplied HMAC_CTX.</p>
  60. <p>HMAC_size() returns the length in bytes of the underlying hash function output.</p>
  61. <h1 id="RETURN-VALUES">RETURN VALUES</h1>
  62. <p>HMAC() returns a pointer to the message authentication code or NULL if an error occurred.</p>
  63. <p>HMAC_CTX_new() returns a pointer to a new <b>HMAC_CTX</b> on success or <b>NULL</b> if an error occurred.</p>
  64. <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>
  65. <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>
  66. <p>HMAC_size() returns the length in bytes of the underlying hash function output or zero on error.</p>
  67. <h1 id="CONFORMING-TO">CONFORMING TO</h1>
  68. <p>RFC 2104</p>
  69. <h1 id="SEE-ALSO">SEE ALSO</h1>
  70. <p><a href="../man3/SHA1.html">SHA1(3)</a>, <a href="../man7/evp.html">evp(7)</a></p>
  71. <h1 id="HISTORY">HISTORY</h1>
  72. <p>HMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL 1.1.0.</p>
  73. <p>HMAC_CTX_cleanup() existed in OpenSSL before version 1.1.0.</p>
  74. <p>HMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in OpenSSL 1.1.0.</p>
  75. <p>HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in OpenSSL before version 1.0.0.</p>
  76. <h1 id="COPYRIGHT">COPYRIGHT</h1>
  77. <p>Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.</p>
  78. <p>Licensed under the OpenSSL license (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>
  79. </body>
  80. </html>