Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
hmac.html501 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="hmac — Keyed-Hashing for Message Authentication" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/hmac.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/hmac.py This module implements the HMAC algorithm as described by RFC 2104. The interface allows to use any hash function with a fixed digest size. In particular, extendable output..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_hmac_db2bcfbf.png" />15<meta property="og:image:alt" content="Source code: Lib/hmac.py This module implements the HMAC algorithm as described by RFC 2104. The interface allows to use any hash function with a fixed digest size. In particular, extendable output..." />16<meta name="description" content="Source code: Lib/hmac.py This module implements the HMAC algorithm as described by RFC 2104. The interface allows to use any hash function with a fixed digest size. In particular, extendable output..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>hmac — Keyed-Hashing for Message Authentication &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="secrets — Generate secure random numbers for managing secrets" href="secrets.html" />43    <link rel="prev" title="hashlib — Secure hashes and message digests" href="hashlib.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/hmac.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h4>Previous topic</h4>106    <p class="topless"><a href="hashlib.html"107                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code> — Secure hashes and message digests</a></p>108  </div>109  <div>110    <h4>Next topic</h4>111    <p class="topless"><a href="secrets.html"112                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code> — Generate secure random numbers for managing secrets</a></p>113  </div>114  <script>115    document.addEventListener('DOMContentLoaded', () => {116        const title = document.querySelector('meta[property="og:title"]').content;117        const elements = document.querySelectorAll('.improvepage');118        const pageurl = window.location.href.split('?')[0];119        elements.forEach(element => {120            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));121            url.searchParams.set('pagetitle', title);122            url.searchParams.set('pageurl', pageurl);123            url.searchParams.set('pagesource', "library/hmac.rst");124            element.href = url.toString();125        });126    });127  </script>128  <div role="note" aria-label="source link">129    <h3>This page</h3>130    <ul class="this-page-menu">131      <li><a href="../bugs.html">Report a bug</a></li>132      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>133      <li>134        <a href="https://github.com/python/cpython/blob/main/Doc/library/hmac.rst?plain=1"135            rel="nofollow">Show source136        </a>137      </li>138      139    </ul>140  </div>141        </nav>142    </div>143</div>144 145  146    <div class="related" role="navigation" aria-label="Related">147      <h3>Navigation</h3>148      <ul>149        <li class="right" style="margin-right: 10px">150          <a href="../genindex.html" title="General Index"151             accesskey="I">index</a></li>152        <li class="right" >153          <a href="../py-modindex.html" title="Python Module Index"154             >modules</a> |</li>155        <li class="right" >156          <a href="secrets.html" title="secrets — Generate secure random numbers for managing secrets"157             accesskey="N">next</a> |</li>158        <li class="right" >159          <a href="hashlib.html" title="hashlib — Secure hashes and message digests"160             accesskey="P">previous</a> |</li>161 162          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>163          <li><a href="https://www.python.org/">Python</a> &#187;</li>164          <li class="switchers">165            <div class="language_switcher_placeholder"></div>166            <div class="version_switcher_placeholder"></div>167          </li>168          <li>169              170          </li>171    <li id="cpython-language-and-version">172      <a href="../index.html">3.15.0a6 Documentation</a> &#187;173    </li>174 175          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>176          <li class="nav-item nav-item-2"><a href="crypto.html" accesskey="U">Cryptographic Services</a> &#187;</li>177        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code> — Keyed-Hashing for Message Authentication</a></li>178                <li class="right">179                    180 181    <div class="inline-search" role="search">182        <form class="inline-search" action="../search.html" method="get">183          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">184          <input type="submit" value="Go">185        </form>186    </div>187                     |188                </li>189            <li class="right">190<label class="theme-selector-label">191    Theme192    <select class="theme-selector" oninput="activateTheme(this.value)">193        <option value="auto" selected>Auto</option>194        <option value="light">Light</option>195        <option value="dark">Dark</option>196    </select>197</label> |</li>198            199      </ul>200    </div>    201 202    <div class="document">203      <div class="documentwrapper">204        <div class="bodywrapper">205          <div class="body" role="main">206            207  <section id="module-hmac">208<span id="hmac-keyed-hashing-for-message-authentication"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code> — Keyed-Hashing for Message Authentication<a class="headerlink" href="#module-hmac" title="Link to this heading">¶</a></h1>209<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/hmac.py">Lib/hmac.py</a></p>210<hr class="docutils" />211<p>This module implements the HMAC algorithm as described by <span class="target" id="index-0"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2104.html"><strong>RFC 2104</strong></a>.212The interface allows to use any hash function with a <em>fixed</em> digest size.213In particular, extendable output functions such as SHAKE-128 or SHAKE-256214cannot be used with HMAC.</p>215<dl class="py function">216<dt class="sig sig-object py" id="hmac.new">217<span class="sig-prename descclassname"><span class="pre">hmac.</span></span><span class="sig-name descname"><span class="pre">new</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">digestmod</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hmac.new" title="Link to this definition">¶</a></dt>218<dd><p>Return a new hmac object.  <em>key</em> is a bytes or bytearray object giving the219secret key.  If <em>msg</em> is present, the method call <code class="docutils literal notranslate"><span class="pre">update(msg)</span></code> is made.220<em>digestmod</em> is the digest name, digest constructor or module for the HMAC221object to use.  It may be any name suitable to <a class="reference internal" href="hashlib.html#hashlib.new" title="hashlib.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.new()</span></code></a>.222Despite its argument position, it is required.</p>223<div class="versionchanged">224<p><span class="versionmodified changed">Changed in version 3.4: </span>Parameter <em>key</em> can be a bytes or bytearray object.225Parameter <em>msg</em> can be of any type supported by <a class="reference internal" href="hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a>.226Parameter <em>digestmod</em> can be the name of a hash algorithm.</p>227</div>228<div class="versionchanged">229<p><span class="versionmodified changed">Changed in version 3.8: </span>The <em>digestmod</em> argument is now required.  Pass it as a keyword230argument to avoid awkwardness when you do not have an initial <em>msg</em>.</p>231</div>232</dd></dl>233 234<dl class="py function">235<dt class="sig sig-object py" id="hmac.digest">236<span class="sig-prename descclassname"><span class="pre">hmac.</span></span><span class="sig-name descname"><span class="pre">digest</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">digest</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hmac.digest" title="Link to this definition">¶</a></dt>237<dd><p>Return digest of <em>msg</em> for given secret <em>key</em> and <em>digest</em>. The238function is equivalent to <code class="docutils literal notranslate"><span class="pre">HMAC(key,</span> <span class="pre">msg,</span> <span class="pre">digest).digest()</span></code>, but239uses an optimized C or inline implementation, which is faster for messages240that fit into memory. The parameters <em>key</em>, <em>msg</em>, and <em>digest</em> have241the same meaning as in <a class="reference internal" href="#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">new()</span></code></a>.</p>242<p>CPython implementation detail, the optimized C implementation is only used243when <em>digest</em> is a string and name of a digest algorithm, which is244supported by OpenSSL.</p>245<div class="versionadded">246<p><span class="versionmodified added">Added in version 3.7.</span></p>247</div>248</dd></dl>249 250<dl class="py class">251<dt class="sig sig-object py" id="hmac.HMAC">252<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">hmac.</span></span><span class="sig-name descname"><span class="pre">HMAC</span></span><a class="headerlink" href="#hmac.HMAC" title="Link to this definition">¶</a></dt>253<dd><p>An HMAC object has the following methods:</p>254</dd></dl>255 256<dl class="py method">257<dt class="sig sig-object py" id="hmac.HMAC.update">258<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hmac.HMAC.update" title="Link to this definition">¶</a></dt>259<dd><p>Update the hmac object with <em>msg</em>.  Repeated calls are equivalent to a260single call with the concatenation of all the arguments:261<code class="docutils literal notranslate"><span class="pre">m.update(a);</span> <span class="pre">m.update(b)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">m.update(a</span> <span class="pre">+</span> <span class="pre">b)</span></code>.</p>262<div class="versionchanged">263<p><span class="versionmodified changed">Changed in version 3.4: </span>Parameter <em>msg</em> can be of any type supported by <a class="reference internal" href="hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a>.</p>264</div>265</dd></dl>266 267<dl class="py method">268<dt class="sig sig-object py" id="hmac.HMAC.digest">269<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">digest</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hmac.HMAC.digest" title="Link to this definition">¶</a></dt>270<dd><p>Return the digest of the bytes passed to the <a class="reference internal" href="#hmac.HMAC.update" title="hmac.HMAC.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method so far.271This bytes object will be the same length as the <em>digest_size</em> of the digest272given to the constructor.  It may contain non-ASCII bytes, including NUL273bytes.</p>274<div class="admonition warning">275<p class="admonition-title">Warning</p>276<p>When comparing the output of <code class="xref py py-meth docutils literal notranslate"><span class="pre">digest()</span></code> to an externally supplied277digest during a verification routine, it is recommended to use the278<a class="reference internal" href="#hmac.compare_digest" title="hmac.compare_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">compare_digest()</span></code></a> function instead of the <code class="docutils literal notranslate"><span class="pre">==</span></code> operator279to reduce the vulnerability to timing attacks.</p>280</div>281</dd></dl>282 283<dl class="py method">284<dt class="sig sig-object py" id="hmac.HMAC.hexdigest">285<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">hexdigest</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hmac.HMAC.hexdigest" title="Link to this definition">¶</a></dt>286<dd><p>Like <a class="reference internal" href="#hmac.digest" title="hmac.digest"><code class="xref py py-meth docutils literal notranslate"><span class="pre">digest()</span></code></a> except the digest is returned as a string twice the287length containing only hexadecimal digits.  This may be used to exchange the288value safely in email or other non-binary environments.</p>289<div class="admonition warning">290<p class="admonition-title">Warning</p>291<p>When comparing the output of <code class="xref py py-meth docutils literal notranslate"><span class="pre">hexdigest()</span></code> to an externally supplied292digest during a verification routine, it is recommended to use the293<a class="reference internal" href="#hmac.compare_digest" title="hmac.compare_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">compare_digest()</span></code></a> function instead of the <code class="docutils literal notranslate"><span class="pre">==</span></code> operator294to reduce the vulnerability to timing attacks.</p>295</div>296</dd></dl>297 298<dl class="py method">299<dt class="sig sig-object py" id="hmac.HMAC.copy">300<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">copy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hmac.HMAC.copy" title="Link to this definition">¶</a></dt>301<dd><p>Return a copy (“clone”) of the hmac object.  This can be used to efficiently302compute the digests of strings that share a common initial substring.</p>303</dd></dl>304 305<p>A hash object has the following attributes:</p>306<dl class="py attribute">307<dt class="sig sig-object py" id="hmac.HMAC.digest_size">308<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">digest_size</span></span><a class="headerlink" href="#hmac.HMAC.digest_size" title="Link to this definition">¶</a></dt>309<dd><p>The size of the resulting HMAC digest in bytes.</p>310</dd></dl>311 312<dl class="py attribute">313<dt class="sig sig-object py" id="hmac.HMAC.block_size">314<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">block_size</span></span><a class="headerlink" href="#hmac.HMAC.block_size" title="Link to this definition">¶</a></dt>315<dd><p>The internal block size of the hash algorithm in bytes.</p>316<div class="versionadded">317<p><span class="versionmodified added">Added in version 3.4.</span></p>318</div>319</dd></dl>320 321<dl class="py attribute">322<dt class="sig sig-object py" id="hmac.HMAC.name">323<span class="sig-prename descclassname"><span class="pre">HMAC.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#hmac.HMAC.name" title="Link to this definition">¶</a></dt>324<dd><p>The canonical name of this HMAC, always lowercase, e.g. <code class="docutils literal notranslate"><span class="pre">hmac-md5</span></code>.</p>325<div class="versionadded">326<p><span class="versionmodified added">Added in version 3.4.</span></p>327</div>328</dd></dl>329 330<div class="versionchanged">331<p><span class="versionmodified changed">Changed in version 3.10: </span>Removed the undocumented attributes <code class="docutils literal notranslate"><span class="pre">HMAC.digest_cons</span></code>, <code class="docutils literal notranslate"><span class="pre">HMAC.inner</span></code>,332and <code class="docutils literal notranslate"><span class="pre">HMAC.outer</span></code>.</p>333</div>334<p>This module also provides the following helper function:</p>335<dl class="py function">336<dt class="sig sig-object py" id="hmac.compare_digest">337<span class="sig-prename descclassname"><span class="pre">hmac.</span></span><span class="sig-name descname"><span class="pre">compare_digest</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#hmac.compare_digest" title="Link to this definition">¶</a></dt>338<dd><p>Return <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">==</span> <span class="pre">b</span></code>.  This function uses an approach designed to prevent339timing analysis by avoiding content-based short circuiting behaviour,340making it appropriate for cryptography.  <em>a</em> and <em>b</em> must both be of the341same type: either <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> (ASCII only, as e.g. returned by342<a class="reference internal" href="#hmac.HMAC.hexdigest" title="hmac.HMAC.hexdigest"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HMAC.hexdigest()</span></code></a>), or a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>.</p>343<div class="admonition note">344<p class="admonition-title">Note</p>345<p>If <em>a</em> and <em>b</em> are of different lengths, or if an error occurs,346a timing attack could theoretically reveal information about the347types and lengths of <em>a</em> and <em>b</em>—but not their values.</p>348</div>349<div class="versionadded">350<p><span class="versionmodified added">Added in version 3.3.</span></p>351</div>352<div class="versionchanged">353<p><span class="versionmodified changed">Changed in version 3.10: </span>The function uses OpenSSL’s <code class="docutils literal notranslate"><span class="pre">CRYPTO_memcmp()</span></code> internally when354available.</p>355</div>356</dd></dl>357 358<div class="admonition seealso">359<p class="admonition-title">See also</p>360<dl class="simple">361<dt>Module <a class="reference internal" href="hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a></dt><dd><p>The Python module providing secure hash functions.</p>362</dd>363</dl>364</div>365</section>366 367 368            <div class="clearer"></div>369          </div>370        </div>371      </div>372      <div class="sphinxsidebar" role="navigation" aria-label="Main">373        <div class="sphinxsidebarwrapper">374  <div>375    <h4>Previous topic</h4>376    <p class="topless"><a href="hashlib.html"377                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code> — Secure hashes and message digests</a></p>378  </div>379  <div>380    <h4>Next topic</h4>381    <p class="topless"><a href="secrets.html"382                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code> — Generate secure random numbers for managing secrets</a></p>383  </div>384  <script>385    document.addEventListener('DOMContentLoaded', () => {386        const title = document.querySelector('meta[property="og:title"]').content;387        const elements = document.querySelectorAll('.improvepage');388        const pageurl = window.location.href.split('?')[0];389        elements.forEach(element => {390            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));391            url.searchParams.set('pagetitle', title);392            url.searchParams.set('pageurl', pageurl);393            url.searchParams.set('pagesource', "library/hmac.rst");394            element.href = url.toString();395        });396    });397  </script>398  <div role="note" aria-label="source link">399    <h3>This page</h3>400    <ul class="this-page-menu">401      <li><a href="../bugs.html">Report a bug</a></li>402      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>403      <li>404        <a href="https://github.com/python/cpython/blob/main/Doc/library/hmac.rst?plain=1"405            rel="nofollow">Show source406        </a>407      </li>408      409    </ul>410  </div>411        </div>412<div id="sidebarbutton" title="Collapse sidebar">413<span>«</span>414</div>415 416      </div>417      <div class="clearer"></div>418    </div>  419    <div class="related" role="navigation" aria-label="Related">420      <h3>Navigation</h3>421      <ul>422        <li class="right" style="margin-right: 10px">423          <a href="../genindex.html" title="General Index"424             >index</a></li>425        <li class="right" >426          <a href="../py-modindex.html" title="Python Module Index"427             >modules</a> |</li>428        <li class="right" >429          <a href="secrets.html" title="secrets — Generate secure random numbers for managing secrets"430             >next</a> |</li>431        <li class="right" >432          <a href="hashlib.html" title="hashlib — Secure hashes and message digests"433             >previous</a> |</li>434 435          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>436          <li><a href="https://www.python.org/">Python</a> &#187;</li>437          <li class="switchers">438            <div class="language_switcher_placeholder"></div>439            <div class="version_switcher_placeholder"></div>440          </li>441          <li>442              443          </li>444    <li id="cpython-language-and-version">445      <a href="../index.html">3.15.0a6 Documentation</a> &#187;446    </li>447 448          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>449          <li class="nav-item nav-item-2"><a href="crypto.html" >Cryptographic Services</a> &#187;</li>450        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code> — Keyed-Hashing for Message Authentication</a></li>451                <li class="right">452                    453 454    <div class="inline-search" role="search">455        <form class="inline-search" action="../search.html" method="get">456          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">457          <input type="submit" value="Go">458        </form>459    </div>460                     |461                </li>462            <li class="right">463<label class="theme-selector-label">464    Theme465    <select class="theme-selector" oninput="activateTheme(this.value)">466        <option value="auto" selected>Auto</option>467        <option value="light">Light</option>468        <option value="dark">Dark</option>469    </select>470</label> |</li>471            472      </ul>473    </div>  474    <div class="footer">475    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.476    <br>477    This page is licensed under the Python Software Foundation License Version 2.478    <br>479    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.480    <br>481    482      See <a href="/license.html">History and License</a> for more information.<br>483    484    485    <br>486 487    The Python Software Foundation is a non-profit corporation.488<a href="https://www.python.org/psf/donations/">Please donate.</a>489<br>490    <br>491      Last updated on Mar 10, 2026 (08:58 UTC).492    493      <a href="/bugs.html">Found a bug</a>?494    495    <br>496 497    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.498    </div>499 500  </body>501</html>