Commit 085b4e03 authored by Thomas Haller's avatar Thomas Haller

Squashed 'shared/c-siphash/' changes from 211cfc5abc..7c42c59258

7c42c59258 build: use c-stdaux
d81d68ff83 build: sync with c-util
e858efbc45 build: pull in c-stdaux

git-subtree-dir: shared/c-siphash
git-subtree-split: 7c42c592581906fef19458372b8db2b643278211
parent 4dd7869b
[submodule "subprojects/c-stdaux"]
path = subprojects/c-stdaux
url = https://github.com/c-util/c-stdaux.git
......@@ -30,8 +30,8 @@ AUTHORS-LGPL:
along with this program; If not, see <http://www.gnu.org/licenses/>.
COPYRIGHT: (ordered alphabetically)
Copyright (C) 2015-2018 Red Hat, Inc.
Copyright (C) 2015-2019 Red Hat, Inc.
AUTHORS: (ordered alphabetically)
David Herrmann <dh.herrmann@gmail.com>
David Rheinsberg <david.rheinsberg@gmail.com>
Tom Gundersen <teg@jklm.no>
This diff is collapsed.
This diff is collapsed.
AUTHORS-ASL
\ No newline at end of file
# c-siphash - Streaming-capable SipHash Implementation
## CHANGES WITH 1:
* Initial release of c-siphash.
* TBD
Contributions from: TBD
- TBD, YYYY-MM-DD
c-siphash - Streaming-capable SipHash Implementation
ABOUT:
The c-siphash project is a standalone implementation of SipHash in
Standard ISO-C11. It provides a streaming-capable API to compute data
hashes according to the SipHash algorithm.
For API documentation, see the c-siphash.h header file, as well as the
docbook comments for each function.
DETAILS:
https://c-util.github.io/c-siphash
BUG REPORTS:
https://github.com/c-util/c-siphash/issues
GIT:
git@github.com:c-util/c-siphash.git
https://github.com/c-util/c-siphash.git
GITWEB:
https://github.com/c-util/c-siphash
LICENSE:
Apache Software License 2.0
Lesser General Public License 2.1+
See AUTHORS for details.
REQUIREMENTS:
The requirements for c-siphash are:
libc (e.g., glibc >= 2.16)
At build-time, the following software is required:
meson >= 0.41
pkg-config >= 0.29
INSTALL:
The meson build-system is used for this project. Contact upstream
documentation for detailed help. In most situations the following
commands are sufficient to build and install from source:
$ mkdir build
$ cd build
$ meson setup ..
$ ninja
$ meson test
# ninja install
No custom configuration options are available.
c-siphash
=========
Streaming-capable SipHash Implementation
The c-siphash project is a standalone implementation of SipHash in Standard
ISO-C11. It provides a streaming-capable API to compute data hashes according
to the SipHash algorithm. For API documentation, see the c-siphash.h header
file, as well as the docbook comments for each function.
### Project
* **Website**: <https://c-util.github.io/c-siphash>
* **Bug Tracker**: <https://github.com/c-util/c-siphash/issues>
### Requirements
The requirements for this project are:
* `libc` (e.g., `glibc >= 2.16`)
At build-time, the following software is required:
* `meson >= 0.41`
* `pkg-config >= 0.29`
### Build
The meson build-system is used for this project. Contact upstream
documentation for detailed help. In most situations the following
commands are sufficient to build and install from source:
```sh
mkdir build
cd build
meson setup ..
ninja
meson test
ninja install
```
No custom configuration options are available.
### Repository:
- **web**: <https://github.com/c-util/c-siphash>
- **https**: `https://github.com/c-util/c-siphash.git`
- **ssh**: `git@github.com:c-util/c-siphash.git`
### License:
- **Apache-2.0** OR **LGPL-2.1-or-later**
- See AUTHORS file for details.
......@@ -12,4 +12,8 @@ project_description = 'Streaming-capable SipHash Implementation'
add_project_arguments('-D_GNU_SOURCE', language: 'c')
mod_pkgconfig = import('pkgconfig')
sub_cstdaux = subproject('c-stdaux')
dep_cstdaux = sub_cstdaux.get_variable('libcstdaux_dep')
subdir('src')
......@@ -11,12 +11,11 @@
* C_siphash_finalize_Y() can be easily provided, if required.
*/
#include <c-stdaux.h>
#include <stddef.h>
#include <stdint.h>
#include "c-siphash.h"
#define _public_ __attribute__((__visibility__("default")))
static inline uint64_t c_siphash_read_le64(const uint8_t bytes[8]) {
return ((uint64_t) bytes[0]) |
(((uint64_t) bytes[1]) << 8) |
......@@ -68,7 +67,7 @@ static inline void c_siphash_sipround(CSipHash *state) {
* Right now, only SipHash24 is supported. Other SipHash parameters can be
* easily added if required.
*/
_public_ void c_siphash_init(CSipHash *state, const uint8_t seed[16]) {
_c_public_ void c_siphash_init(CSipHash *state, const uint8_t seed[16]) {
uint64_t k0, k1;
k0 = c_siphash_read_le64(seed);
......@@ -105,7 +104,7 @@ _public_ void c_siphash_init(CSipHash *state, const uint8_t seed[16]) {
* Note that this implementation works best when used with chunk-sizes of
* multiples of 64bit (8-bytes). This is not a requirement, though.
*/
_public_ void c_siphash_append(CSipHash *state, const uint8_t *bytes, size_t n_bytes) {
_c_public_ void c_siphash_append(CSipHash *state, const uint8_t *bytes, size_t n_bytes) {
const uint8_t *end = bytes + n_bytes;
size_t left = state->n_bytes & 7;
uint64_t m;
......@@ -195,7 +194,7 @@ _public_ void c_siphash_append(CSipHash *state, const uint8_t *bytes, size_t n_b
*
* Return: 64bit hash value
*/
_public_ uint64_t c_siphash_finalize(CSipHash *state) {
_c_public_ uint64_t c_siphash_finalize(CSipHash *state) {
uint64_t b;
b = state->padding | (((uint64_t) state->n_bytes) << 56);
......@@ -236,7 +235,7 @@ _public_ uint64_t c_siphash_finalize(CSipHash *state) {
*
* Return: 64bit hash value
*/
_public_ uint64_t c_siphash_hash(const uint8_t seed[16], const uint8_t *bytes, size_t n_bytes) {
_c_public_ uint64_t c_siphash_hash(const uint8_t seed[16], const uint8_t *bytes, size_t n_bytes) {
CSipHash state;
c_siphash_init(&state, seed);
......
......@@ -4,6 +4,10 @@
libcsiphash_symfile = join_paths(meson.current_source_dir(), 'libcsiphash.sym')
libcsiphash_deps = [
dep_cstdaux,
]
libcsiphash_private = static_library(
'csiphash-private',
[
......@@ -13,12 +17,14 @@ libcsiphash_private = static_library(
'-fvisibility=hidden',
'-fno-common',
],
dependencies: libcsiphash_deps,
pic: true,
)
libcsiphash_shared = shared_library(
'csiphash',
objects: libcsiphash_private.extract_all_objects(),
dependencies: libcsiphash_deps,
install: not meson.is_subproject(),
soversion: 0,
link_depends: libcsiphash_symfile,
......@@ -31,6 +37,7 @@ libcsiphash_shared = shared_library(
libcsiphash_dep = declare_dependency(
include_directories: include_directories('.'),
link_with: libcsiphash_private,
dependencies: libcsiphash_deps,
version: meson.project_version(),
)
......
......@@ -9,7 +9,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "c-siphash.h"
static void test_api(void) {
......
......@@ -6,10 +6,10 @@
#undef NDEBUG
#include <assert.h>
#include <c-stdaux.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "c-siphash.h"
/* See https://131002.net/siphash/siphash.pdf, Appendix A. */
......@@ -20,21 +20,21 @@ static void do_reference_test(const uint8_t *in, size_t len, const uint8_t *key)
/* verify the internal state as given in the above paper */
c_siphash_init(&state, key);
assert(state.v0 == 0x7469686173716475);
assert(state.v1 == 0x6b617f6d656e6665);
assert(state.v2 == 0x6b7f62616d677361);
assert(state.v3 == 0x7b6b696e727e6c7b);
c_assert(state.v0 == 0x7469686173716475);
c_assert(state.v1 == 0x6b617f6d656e6665);
c_assert(state.v2 == 0x6b7f62616d677361);
c_assert(state.v3 == 0x7b6b696e727e6c7b);
c_siphash_append(&state, in, len);
assert(state.v0 == 0x4a017198de0a59e0);
assert(state.v1 == 0x0d52f6f62a4f59a4);
assert(state.v2 == 0x634cb3577b01fd3d);
assert(state.v3 == 0xa5224d6f55c7d9c8);
c_assert(state.v0 == 0x4a017198de0a59e0);
c_assert(state.v1 == 0x0d52f6f62a4f59a4);
c_assert(state.v2 == 0x634cb3577b01fd3d);
c_assert(state.v3 == 0xa5224d6f55c7d9c8);
out = c_siphash_finalize(&state);
assert(out == 0xa129ca6149be45e5);
assert(state.v0 == 0xf6bcd53893fecff1);
assert(state.v1 == 0x54b9964c7ea0d937);
assert(state.v2 == 0x1b38329c099bb55a);
assert(state.v3 == 0x1814bb89ad7be679);
c_assert(out == 0xa129ca6149be45e5);
c_assert(state.v0 == 0xf6bcd53893fecff1);
c_assert(state.v1 == 0x54b9964c7ea0d937);
c_assert(state.v2 == 0x1b38329c099bb55a);
c_assert(state.v3 == 0x1814bb89ad7be679);
/* verify that decomposing the input in three chunks gives the
same result */
......@@ -45,12 +45,12 @@ static void do_reference_test(const uint8_t *in, size_t len, const uint8_t *key)
c_siphash_append(&state, &in[i], j - i);
c_siphash_append(&state, &in[j], len - j);
out = c_siphash_finalize(&state);
assert(out == 0xa129ca6149be45e5);
c_assert(out == 0xa129ca6149be45e5);
}
}
/* verify c_siphash_hash() produces the same result */
assert(out == c_siphash_hash(key, in, len));
c_assert(out == c_siphash_hash(key, in, len));
}
static void test_reference(void) {
......@@ -92,7 +92,7 @@ static void test_short_hashes(void) {
two[i-1] = one[i-1];
c_siphash_append(&state2, two, i);
assert(memcmp(&state1, &state2, sizeof state1) == 0);
c_assert(memcmp(&state1, &state2, sizeof state1) == 0);
}
/* hashing n and 1, n and 2, n and 3, ..., n-1 and 1, n-2 and 2, ... */
......@@ -107,7 +107,7 @@ static void test_short_hashes(void) {
two[j-1] = one[j-1];
c_siphash_append(&state2, two, j);
assert(memcmp(&state1, &state2, sizeof state1) == 0);
c_assert(memcmp(&state1, &state2, sizeof state1) == 0);
}
}
}
......
Subproject commit 1bcec740f7ee1d2e71f84ac574f70fb4ec30539c
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment