mirror of
https://github.com/AtHeartEngineer/sss.git
synced 2026-01-10 13:18:08 -05:00
Add separate randombytes module
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "randombytes"]
|
||||
path = randombytes
|
||||
url = https://github.com/dsprenkels/randombytes.git
|
||||
14
Makefile
14
Makefile
@@ -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
|
||||
|
||||
1
hazmat.c
1
hazmat.c
@@ -1,5 +1,4 @@
|
||||
#include "hazmat.h"
|
||||
#include "randombytes.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
1
randombytes
Submodule
1
randombytes
Submodule
Submodule randombytes added at db49030e62
@@ -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 */
|
||||
}
|
||||
@@ -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 */
|
||||
Reference in New Issue
Block a user