Sha256: e1ff4c0616de7654b896cdba0e5ba1b2b79cbb42492f50c245c2711748aece3d

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

#include "crypto_shorthash_siphash24.h"
#include "private/common.h"
#include "shorthash_siphash_ref.h"

int
crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in,
                            unsigned long long inlen, const unsigned char *k)
{
    uint64_t       v0 = 0x736f6d6570736575ULL;
    uint64_t       v1 = 0x646f72616e646f83ULL;
    uint64_t       v2 = 0x6c7967656e657261ULL;
    uint64_t       v3 = 0x7465646279746573ULL;
    uint64_t       b;
    uint64_t       k0 = LOAD64_LE(k);
    uint64_t       k1 = LOAD64_LE(k + 8);
    uint64_t       m;
    const uint8_t *end  = in + inlen - (inlen % sizeof(uint64_t));
    const int      left = inlen & 7;

    b = ((uint64_t) inlen) << 56;
    v3 ^= k1;
    v2 ^= k0;
    v1 ^= k1;
    v0 ^= k0;
    for (; in != end; in += 8) {
        m = LOAD64_LE(in);
        v3 ^= m;
        SIPROUND;
        SIPROUND;
        v0 ^= m;
    }
    switch (left) {
    case 7:
        b |= ((uint64_t) in[6]) << 48;
    case 6:
        b |= ((uint64_t) in[5]) << 40;
    case 5:
        b |= ((uint64_t) in[4]) << 32;
    case 4:
        b |= ((uint64_t) in[3]) << 24;
    case 3:
        b |= ((uint64_t) in[2]) << 16;
    case 2:
        b |= ((uint64_t) in[1]) << 8;
    case 1:
        b |= ((uint64_t) in[0]);
        break;
    case 0:
        break;
    }
    v3 ^= b;
    SIPROUND;
    SIPROUND;
    v0 ^= b;
    v2 ^= 0xee;
    SIPROUND;
    SIPROUND;
    SIPROUND;
    SIPROUND;
    b = v0 ^ v1 ^ v2 ^ v3;
    STORE64_LE(out, b);
    v1 ^= 0xdd;
    SIPROUND;
    SIPROUND;
    SIPROUND;
    SIPROUND;
    b = v0 ^ v1 ^ v2 ^ v3;
    STORE64_LE(out + 8, b);

    return 0;
}

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
laag-libsodium-1.0.16.2 vendor/github.com/jedisct1/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c
laag-libsodium-1.0.16.0 vendor/github.com/jedisct1/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c
rbnacl-libsodium-1.0.16 vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c
rbnacl-libsodium-1.0.15.1 vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c
rbnacl-libsodium-1.0.15 vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c
rbnacl-libsodium-1.0.13 vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c