forked from dsprenkels/sss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daan Sprenkels
committed
Apr 11, 2017
1 parent
ed25e5f
commit 53b0e21
Showing
5 changed files
with
159 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# TweetNaCl is downloaded at compile time | ||
tweetnacl.h | ||
tweetnacl.c | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
CC = clang | ||
CFLAGS = -Wall -g -O2 -ansi -pedantic | ||
SRCS = sss.c hazmat.c | ||
CFLAGS = -Wall -g -O2 -pedantic | ||
SRCS = sss.c hazmat.c tweetnacl.c | ||
OBJS := ${SRCS:.c=.o} | ||
|
||
all: libsss.a | ||
all: libsss.a test | ||
|
||
libsss.a: $(OBJS) | ||
$(AR) -rcs libsss.a $^ | ||
|
||
%.o: tweetnacl.h %.c | ||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $^ | ||
|
||
tweetnacl.c: tweetnacl.h | ||
wget -q https://tweetnacl.cr.yp.to/20140427/tweetnacl.c | ||
|
||
tweetnacl.h: | ||
wget -q https://tweetnacl.cr.yp.to/20140427/tweetnacl.h | ||
|
||
%.out: %.o | ||
$(CC) -o $@ $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) | ||
./$@ | ||
|
||
test: test_hazmat.out | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f *.o *.gch *.a *.out | ||
$(RM) *.o *.gch *.a *.out tweetnacl.c tweetnacl.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "hazmat.c" | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
static void test_gf256_mul() | ||
{ | ||
assert(gf256_mul(0x00, 0x00) == 0x00); | ||
assert(gf256_mul(0x01, 0x00) == 0x00); | ||
assert(gf256_mul(0x00, 0x01) == 0x00); | ||
assert(gf256_mul(0x01, 0x01) == 0x01); | ||
assert(gf256_mul(0x88, 0x88) == 0xda); | ||
assert(gf256_mul(0xff, 0xff) == 0x13); | ||
} | ||
|
||
static void test_gf256_inv() | ||
{ | ||
size_t idx; | ||
uint8_t tmp; | ||
|
||
assert(gf256_inv(0) == 0); | ||
for (idx = 1; idx < 256; idx++) { | ||
tmp = idx; | ||
assert(gf256_mul(gf256_inv(tmp), tmp) == 1); | ||
} | ||
} | ||
|
||
|
||
static void test_key_shares() | ||
{ | ||
uint8_t key[32], restored[32]; | ||
SSS_Keyshare key_shares[256]; | ||
size_t idx; | ||
|
||
for (idx = 0; idx < 32; idx++) { | ||
key[idx] = idx; | ||
} | ||
|
||
SSS_create_keyshares(key_shares, key, 1, 1); | ||
SSS_combine_keyshares(restored, key_shares, 1); | ||
assert(memcmp(key, restored, 32) == 0); | ||
|
||
SSS_create_keyshares(key_shares, key, 3, 2); | ||
SSS_combine_keyshares(restored, &key_shares[1], 2); | ||
assert(memcmp(key, restored, 32) == 0); | ||
|
||
SSS_create_keyshares(key_shares, key, 255, 127); | ||
SSS_combine_keyshares(restored, &key_shares[128], 127); | ||
assert(memcmp(key, restored, 32) == 0); | ||
|
||
SSS_create_keyshares(key_shares, key, 255, 255); | ||
SSS_combine_keyshares(restored, key_shares, 255); | ||
assert(memcmp(key, restored, 32) == 0); | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
test_gf256_mul(); | ||
test_gf256_inv(); | ||
test_key_shares(); | ||
return 0; | ||
} |