mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:17:35 +00:00
AK: Implement SipHash as the default hash algorithm for most use cases
SipHash is highly HashDoS-resistent, initialized with a random seed at startup (i.e. non-deterministic) and usable for security-critical use cases with large enough parameters. We just use it because it's reasonably secure with parameters 1-3 while having excellent properties and not being significantly slower than before.
This commit is contained in:
parent
5e15c29e22
commit
9a026fc8d5
9 changed files with 282 additions and 11 deletions
29
AK/SipHash.h
Normal file
29
AK/SipHash.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
// Ported from the SipHash reference implementation, released to the public domain:
|
||||
// https://github.com/veorq/SipHash/blob/eee7d0d84dc7731df2359b243aa5e75d85f6eaef/siphash.c
|
||||
// The standard is SipHash-2-4, but we use 1-3 for a little more speed.
|
||||
// Cryptography should use 4-8 for (relative) conservative security,
|
||||
// though SipHash itself is NOT a cryptographically secure hash algorithm.
|
||||
template<size_t message_block_rounds, size_t finalization_rounds>
|
||||
u64 sip_hash_bytes(ReadonlyBytes input);
|
||||
unsigned standard_sip_hash(u64 input);
|
||||
unsigned secure_sip_hash(u64 input);
|
||||
|
||||
}
|
||||
|
||||
#ifdef USING_AK_GLOBALLY
|
||||
using AK::secure_sip_hash;
|
||||
using AK::sip_hash_bytes;
|
||||
using AK::standard_sip_hash;
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue