veorq/siphash

repository·master·Indexed 20 days ago

https://github.com/veorq/siphash

A reference implementation of SipHash, a family of cryptographically secure pseudorandom functions (PRFs) optimized for short messages and designed to defend against hash-flooding DoS attacks. Supports variants including SipHash-2-4-64, SipHash-2-4-128, HalfSipHash-2-4-32, and HalfSipHash-2-4-64, with configurable compression and finalization rounds.

Tokens
574
Snippets
2
Records
3
Agent score
23%

What's inside veorq-siphash

  1. Understand SipHash variants and specifications

    master

    SipHash is a family of pseudorandom functions (PRFs) optimized for short messages. The default implementation is SipHash-2-4, which uses a 128-bit key, 2 compression rounds, 4 finalization rounds, and returns a 64-bit tag.

    Available Variants

    VariantKey SizeWord SizeTag SizeDescription
    SipHash-c-d128-bit64-bit64-bitThe standard version (e.g., SipHash-2-4).
    SipHash-c-d-128128-bit64-bit128-bitReturns a 128-bit tag instead of 64-bit.
    HalfSipHash-c-d-3264-bit32-bit32-bitOptimized for 32-bit words and 64-bit keys.
    HalfSipHash-c-d-6464-bit32-bit64-bitOptimized for 32-bit words and 64-bit keys.

    Security Considerations

    • Key Usage: SipHash is a keyed hash function. It must always be used with a secret key to remain secure. It is not a key-less hash function like BLAKE3 or SHA-3.
    • PRF Security: For maximum security, it is expected that $c \ge 2$ and $d \ge 4$.
    • Limits: Security is bounded by the key size (128 bits for standard SipHash) and the output tag size.
  2. Build and verify SipHash implementation

    master

    To build the SipHash reference implementation and its associated tests, use the make command. This builds tests for several variants including SipHash-2-4-64, SipHash-2-4-128, HalfSipHash-2-4-32, and HalfSipHash-2-4-64.

    After building, you can run the following commands:

    • ./test: Verifies 64 test vectors.
    • ./debug: Verifies the same test vectors but also prints intermediate values for debugging purposes.
    make
    ./test
  3. Configure SipHash rounds via compiler flags or Makefile

    master

    You can implement custom SipHash-c-d variants (where c is the number of compression rounds and d is the number of finalization rounds) by defining cROUNDS and dROUNDS during compilation.

    Using GCC: Pass the round counts using the -D flag.

    Using Make: Pass the round counts as parameters to the make command.

    Note: If you modify the number of rounds, the standard test vectors will no longer verify.

    # Using GCC
    gcc -Wall --std=c99 -DcROUNDS=2 -DdROUNDS=4 siphash.c halfsiphash.c test.c -o test
    
    # Using Make
    make cROUNDS=2 dROUNDS=4