Add separate randombytes module

This commit is contained in:
Daan Sprenkels
2017-05-13 21:01:41 +02:00
parent 35cf931c00
commit acdc769e29
7 changed files with 15 additions and 40 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "randombytes"]
path = randombytes
url = https://github.com/dsprenkels/randombytes.git

View File

@@ -1,13 +1,18 @@
CFLAGS = -Wall -g -O2
SRCS = hazmat.c randombytes.c serialize.c sss.c keccak.c tweetnacl.c
OBJS := ${SRCS:.c=.o}
SRCS = hazmat.c serialize.c sss.c keccak.c tweetnacl.c
OBJS = ${SRCS:.c=.o}
LDFLAGS = -L./randombytes
LDLIBS = -lrandombytes
all: libsss.a
libsss.a: $(OBJS)
libsss.a: randombytes/librandombytes.a $(OBJS)
$(AR) -rcs libsss.a $^
%.out: %.o
randombytes/librandombytes.a:
$(MAKE) -C randombytes librandombytes.a
%.out: %.o randombytes/librandombytes.a
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS)
valgrind -q --leak-check=full --error-exitcode=1 ./$@
@@ -20,4 +25,5 @@ test: test_hazmat.out test_serialize.out test_sss.out
.PHONY: clean
clean:
$(MAKE) -C randombytes $@
$(RM) *.o *.gch *.a *.out

View File

@@ -1,5 +1,4 @@
#include "hazmat.h"
#include "randombytes.h"
#include <assert.h>
#include <string.h>

1
randombytes Submodule

Submodule randombytes added at db49030e62

View File

@@ -1,20 +0,0 @@
#include "randombytes.h"
#include <assert.h>
#ifdef __linux__
# define _GNU_SOURCE
# include <sys/syscall.h>
#endif
void randombytes(const void *buf, const size_t n)
{
int tmp;
#ifdef __linux__
tmp = syscall(SYS_getrandom, buf, n, 0);
#else
# warning "randombytes(...) is not supported on this platform. Using INSECURE dummy version."
memset(buf, 42, n);
#endif /* __linux__ */
assert(tmp == n); /* Failure indicates a bug in the code */
}

View File

@@ -1,14 +0,0 @@
#ifndef sss_RANDOMBYTES_H
#define sss_RANDOMBYTES_H
#include <sys/syscall.h>
#include <unistd.h>
/*
* Write `n` bytes of high quality random bytes to `buf`
*/
void randombytes(const void *buf, size_t n);
#endif /* sss_RANDOMBYTES_H */

2
sss.c
View File

@@ -1,4 +1,4 @@
#include "randombytes.h"
#include "randombytes/randombytes.h"
#include "sss.h"
#include "tweetnacl.h"
#include <assert.h>