aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Altendorf <sda@fstab.net>2019-09-10 08:43:15 -0400
committerKyle Altendorf <sda@fstab.net>2019-09-10 08:43:23 -0400
commite802f9cc563abdb6f3ee4c4137edc6f293fdd8d2 (patch)
tree341fa5f8d011756778a1932c0325b958ada0041f
parentMerge pull request #13 from altendky/use_UINTxx_C_macros (diff)
downloadsiphash-e802f9cc563abdb6f3ee4c4137edc6f293fdd8d2.tar.gz
siphash-e802f9cc563abdb6f3ee4c4137edc6f293fdd8d2.tar.xz
Make *c* and *d* rounds less intrusively configurable
-rw-r--r--README.md17
-rw-r--r--halfsiphash.c8
-rw-r--r--makefile8
-rw-r--r--siphash.c8
4 files changed, 32 insertions, 9 deletions
diff --git a/README.md b/README.md
index 7af7657..1b4157b 100644
--- a/README.md
+++ b/README.md
@@ -42,13 +42,20 @@ verifies 64 test vectors, and
does the same and prints intermediate values.
The code can be adapted to implement SipHash-*c*-*d*, the version of SipHash
-with *c* compression rounds and *d* finalization rounds, by tweaking the
-lines
-```C
-#define cROUNDS 2
-#define dROUNDS 4
+with *c* compression rounds and *d* finalization rounds, by defining `cROUNDS`
+or `dROUNDS` when compiling. This can be done with `-D` command line arguments
+to many compilers such as below.
+
+```sh
+gcc -Wall --std=c99 -DcROUNDS=2 -DdROUNDS=4 siphash.c halfsiphash.c test.c -o test
```
+The `makefile` also takes *c* and *d* rounds values as parameters.
+
+```sh
+make cROUNDS=2 dROUNDS=4
+```
+
Obviously, if the number of rounds is modified then the test vectors
won't verify.
diff --git a/halfsiphash.c b/halfsiphash.c
index 689e125..862de9d 100644
--- a/halfsiphash.c
+++ b/halfsiphash.c
@@ -19,8 +19,12 @@
#include <string.h>
/* default: SipHash-2-4 */
-#define cROUNDS 2
-#define dROUNDS 4
+#ifndef cROUNDS
+ #define cROUNDS 2
+#endif
+#ifndef dROUNDS
+ #define dROUNDS 4
+#endif
#define ROTL(x, b) (uint32_t)(((x) << (b)) | ((x) >> (32 - (b))))
diff --git a/makefile b/makefile
index 8cf194a..eebe3e9 100644
--- a/makefile
+++ b/makefile
@@ -3,6 +3,14 @@ CFLAGS=-Wall --std=c99
SRC=siphash.c halfsiphash.c test.c
BIN=test debug vectors
+ifneq ($(cROUNDS),)
+CFLAGS:=$(CFLAGS) -DcROUNDS=$(cROUNDS)
+endif
+
+ifneq ($(dROUNDS),)
+CFLAGS:=$(CFLAGS) -DdROUNDS=$(dROUNDS)
+endif
+
all: $(BIN)
test: $(SRC)
diff --git a/siphash.c b/siphash.c
index 41c6f50..78bdf9f 100644
--- a/siphash.c
+++ b/siphash.c
@@ -20,8 +20,12 @@
#include <string.h>
/* default: SipHash-2-4 */
-#define cROUNDS 2
-#define dROUNDS 4
+#ifndef cROUNDS
+ #define cROUNDS 2
+#endif
+#ifndef dROUNDS
+ #define dROUNDS 4
+#endif
#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))