Apache Portable Runtime
apr_siphash.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /*
17  SipHash reference C implementation
18  Copyright (c) 2012-2014 Jean-Philippe Aumasson
19  <jeanphilippe.aumasson@gmail.com>
20  Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
21  To the extent possible under law, the author(s) have dedicated all copyright
22  and related and neighboring rights to this software to the public domain
23  worldwide. This software is distributed without any warranty.
24  You should have received a copy of the CC0 Public Domain Dedication along
25  with this software. If not, see
26  <http://creativecommons.org/publicdomain/zero/1.0/>.
27  */
28 
29 #ifndef APR_SIPHASH_H
30 #define APR_SIPHASH_H
31 
32 #include "apr.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * @file apr_siphash.h
40  * @brief APR-UTIL siphash library
41  * "SipHash-c-d is a family of pseudorandom functions (a.k.a. keyed
42  * hash functions) optimized for speed on short messages", designed by
43  * Jean-Philippe Aumasson and Daniel J. Bernstein. It generates a 64bit
44  * hash (or MAC) from the message and a 128bit key.
45  * See http://cr.yp.to/siphash/siphash-20120620.pdf for the details,
46  * c is the number of compression rounds, d the number of finalization
47  * rounds; we also define fast implementations for c = 2 with d = 4 (aka
48  * siphash-2-4), and c = 4 with d = 8 (aka siphash-4-8), as recommended
49  * parameters per the authors.
50  */
51 
52 /** size of the siphash digest */
53 #define APR_SIPHASH_DSIZE 8
54 
55 /** size of the siphash key */
56 #define APR_SIPHASH_KSIZE 16
57 
58 
59 /**
60  * @brief Computes SipHash-c-d, producing a 64bit (APR_SIPHASH_DSIZE) hash
61  * from a message and a 128bit (APR_SIPHASH_KSIZE) secret key.
62  * @param src The message
63  * @param len The length of the message
64  * @param key The secret key
65  * @param c The number of compression rounds
66  * @param d The number of finalization rounds
67  * @return The hash value as a 64bit unsigned integer
68  */
69 APR_DECLARE(apr_uint64_t) apr_siphash(const void *src, apr_size_t len,
70  const unsigned char key[APR_SIPHASH_KSIZE],
71  unsigned int c, unsigned int d);
72 
73 /**
74  * @brief Computes SipHash-c-d, producing a 64bit (APR_SIPHASH_DSIZE) hash
75  * from a message and a 128bit (APR_SIPHASH_KSIZE) secret key, into a possibly
76  * unaligned buffer (using the little endian representation as defined by the
77  * authors for interoperabilty) usable as a MAC.
78  * @param out The output buffer (or MAC)
79  * @param src The message
80  * @param len The length of the message
81  * @param key The secret key
82  * @param c The number of compression rounds
83  * @param d The number of finalization rounds
84  * @return The hash value as a 64bit unsigned integer
85  */
87  const void *src, apr_size_t len,
88  const unsigned char key[APR_SIPHASH_KSIZE],
89  unsigned int c, unsigned int d);
90 
91 /**
92  * @brief Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash
93  * from a message and a 128bit (APR_SIPHASH_KSIZE) secret key.
94  * @param src The message to hash
95  * @param len The length of the message
96  * @param key The secret key
97  * @return The hash value as a 64bit unsigned integer
98  */
99 APR_DECLARE(apr_uint64_t) apr_siphash24(const void *src, apr_size_t len,
100  const unsigned char key[APR_SIPHASH_KSIZE]);
101 
102 /**
103  * @brief Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash
104  * from a message and a 128bit (APR_SIPHASH_KSIZE) secret key, into a possibly
105  * unaligned buffer (using the little endian representation as defined by the
106  * authors for interoperabilty) usable as a MAC.
107  * @param out The output buffer (or MAC)
108  * @param src The message
109  * @param len The length of the message
110  * @param key The secret key
111  * @return The hash value as a 64bit unsigned integer
112  */
114  const void *src, apr_size_t len,
115  const unsigned char key[APR_SIPHASH_KSIZE]);
116 
117 /**
118  * @brief Computes SipHash-4-8, producing a 64bit (APR_SIPHASH_DSIZE) hash
119  * from a message and a 128bit (APR_SIPHASH_KSIZE) secret key.
120  * @param src The message
121  * @param len The length of the message
122  * @param key The secret key
123  * @return The hash value as a 64bit unsigned integer
124  */
125 APR_DECLARE(apr_uint64_t) apr_siphash48(const void *src, apr_size_t len,
126  const unsigned char key[APR_SIPHASH_KSIZE]);
127 
128 /**
129  * @brief Computes SipHash-4-8, producing a 64bit (APR_SIPHASH_DSIZE) hash
130  * from a message and a 128bit (APR_SIPHASH_KSIZE) secret key, into a possibly
131  * unaligned buffer (using the little endian representation as defined by the
132  * authors for interoperabilty) usable as a MAC.
133  * @param out The output buffer (or MAC)
134  * @param src The message
135  * @param len The length of the message
136  * @param key The secret key
137  * @return The hash value as a 64bit unsigned integer
138  */
140  const void *src, apr_size_t len,
141  const unsigned char key[APR_SIPHASH_KSIZE]);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* APR_SIPHASH_H */
APR Platform Definitions.
void apr_siphash24_auth(unsigned char out[APR_SIPHASH_DSIZE], const void *src, apr_size_t len, const unsigned char key[APR_SIPHASH_KSIZE])
Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
#define APR_SIPHASH_DSIZE
Definition: apr_siphash.h:53
apr_uint64_t apr_siphash(const void *src, apr_size_t len, const unsigned char key[APR_SIPHASH_KSIZE], unsigned int c, unsigned int d)
Computes SipHash-c-d, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
void apr_siphash48_auth(unsigned char out[APR_SIPHASH_DSIZE], const void *src, apr_size_t len, const unsigned char key[APR_SIPHASH_KSIZE])
Computes SipHash-4-8, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
apr_uint64_t apr_siphash48(const void *src, apr_size_t len, const unsigned char key[APR_SIPHASH_KSIZE])
Computes SipHash-4-8, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
#define APR_SIPHASH_KSIZE
Definition: apr_siphash.h:56
apr_uint64_t apr_siphash24(const void *src, apr_size_t len, const unsigned char key[APR_SIPHASH_KSIZE])
Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
void apr_siphash_auth(unsigned char out[APR_SIPHASH_DSIZE], const void *src, apr_size_t len, const unsigned char key[APR_SIPHASH_KSIZE], unsigned int c, unsigned int d)
Computes SipHash-c-d, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
#define APR_DECLARE(type)
Definition: apr.h:516