-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsiphash.h
More file actions
101 lines (84 loc) · 2.96 KB
/
siphash.h
File metadata and controls
101 lines (84 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* siphash.h
*
* Copyright (C) 2006-2025 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef WOLF_CRYPT_SIPHASH_H
#define WOLF_CRYPT_SIPHASH_H
#include <wolfssl/wolfcrypt/types.h>
#if defined(WOLFSSL_SIPHASH)
/* DESCRIPTION
*
* SipHash is a PseudoRandom Function (PRF) that can be used with small
* messages (less than 256 bytes).
* SipHash can be used for Message Authentication Codes (MACs) and as such must
* be passed a secret key.
* https://eprint.iacr.org/2012/351.pdf
*
* SipHash is commonly used in hash tables.
* Do not use this as a hash not as a general purpose MAC.
*
* WOLFSSL_SIPHASH_CROUNDS and WOLFSSL_SIPHASH_DROUNDS can be defined at build
* time to change the algorithm.
* Default is SipHash-2-4:
* WOLFSSL_SIPHASH_CROUNDS = 2
* WOLFSSL_SIPHASH_DROUNDS = 4
*/
#ifndef WOLFSSL_SIPHASH_CROUNDS
/* Number of rounds to perform in compression operation. */
#define WOLFSSL_SIPHASH_CROUNDS 2
#endif /* WOLFSSL_SIPHASH_CROUNDS */
#ifndef WOLFSSL_SIPHASH_DROUNDS
/* Number of rounds to perform in final operation. */
#define WOLFSSL_SIPHASH_DROUNDS 4
#endif /* WOLFSSL_SIPHASH_DROUNDS */
enum {
SIPHASH_KEY_SIZE = 16, /* Key size of SipHash. */
SIPHASH_BLOCK_SIZE = 8, /* Block size of SipHash. */
SIPHASH_MAC_SIZE_8 = 8, /* Output an 8 byte MAC. */
SIPHASH_MAC_SIZE_16 = 16 /* Output a 16 byte MAC. */
};
typedef struct SipHash SipHash;
struct SipHash {
/* Internal state. */
word64 v[4];
/* Cached message data. */
byte cache[SIPHASH_BLOCK_SIZE];
/* Number of bytes cached. */
byte cacheCnt;
/* Number of output bytes. */
byte outSz;
/* Number of input bytes processed. */
word32 inCnt;
};
#ifdef __cplusplus
extern "C" {
#endif
WOLFSSL_API int wc_InitSipHash(SipHash* sipHash, const unsigned char* key,
unsigned char outSz);
WOLFSSL_API int wc_SipHashUpdate(SipHash* sipHash, const unsigned char* in,
word32 inSz);
WOLFSSL_API int wc_SipHashFinal(SipHash* sipHash, unsigned char* out,
unsigned char outSz);
WOLFSSL_API int wc_SipHash(const unsigned char* key, const unsigned char* in,
word32 inSz, unsigned char* out, unsigned char outSz);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* NO_AES && WOLFSSL_SIPHASH */
#endif /* WOLF_CRYPT_SIPHASH_H */