diff options
| author | Quentin Carbonneaux | 2023-03-01 11:22:33 +0100 |
|---|---|---|
| committer | Quentin Carbonneaux | 2023-03-01 11:22:33 +0100 |
| commit | af8d119ab72e44daf849fd77410c3d18e3ab1ff8 (patch) | |
| tree | f1022974b36f568a2f1c1affc3765bd1054e6c99 | |
| parent | ac981cbd173b1ff0d922eb937de33f37198cd9ce (diff) | |
lib/crypto -> lib/scrypt
| -rw-r--r-- | Makefile | 40 | ||||
| -rw-r--r-- | sdar/all.h | 5 | ||||
| -rw-r--r-- | sdar/arch.c | 4 | ||||
| -rw-r--r-- | sdar/key.c | 3 | ||||
| -rw-r--r-- | sdar/lib/nacl/box.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/curve25519.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/generic/poly1305_auth.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/generic/salsa20.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/generic/salsa20_stream.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/hsalsa20.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/poly1305_verify.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/randombytes.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/secretbox.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/verify_16.c | 2 | ||||
| -rw-r--r-- | sdar/lib/nacl/xsalsa20.c | 2 | ||||
| -rw-r--r-- | sdar/lib/scrypt/scrypt.c (renamed from sdar/lib/crypto/scrypt.c) | 2 | ||||
| -rw-r--r-- | sdar/lib/scrypt/scrypt.h | 22 | ||||
| -rw-r--r-- | sdar/lib/scrypt/sha256.c (renamed from sdar/lib/crypto/sha256.c) | 3 | ||||
| -rw-r--r-- | sdar/lib/scrypt/smix.c (renamed from sdar/lib/crypto/smix.c) | 2 | ||||
| -rw-r--r-- | sdar/lib/scrypt/util.c | 20 | ||||
| -rw-r--r-- | sdar/slice.c | 6 | ||||
| -rw-r--r-- | sdar/stash.c | 2 | ||||
| -rw-r--r-- | sdar/util.c | 19 |
23 files changed, 84 insertions, 66 deletions
@@ -8,35 +8,33 @@ ifeq ($(SYS),Linux) CFLAGS += -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE endif -LZ4DIR = sdar/lib/lz4 -LZ4SRC = $(LZ4DIR)/lz4.c +LZ4SRC = sdar/lib/lz4/lz4.c LZ4OBJ = $(LZ4SRC:sdar/%.c=obj/%.o) -BLAKE3DIR = sdar/lib/blake3 -BLAKE3SRC = $(BLAKE3DIR)/blake3.c $(BLAKE3DIR)/blake3_dispatch.c \ - $(BLAKE3DIR)/blake3_portable.c +BLAKE3SRC = sdar/lib/blake3/blake3.c \ + sdar/lib/blake3/blake3_dispatch.c \ + sdar/lib/blake3/blake3_portable.c BLAKE3FLAGS = -DBLAKE3_NO_SSE2 -DBLAKE3_NO_SSE41 \ -DBLAKE3_NO_AVX2 -DBLAKE3_NO_AVX512 ifeq ($(CPU),x86_64) -BLAKE3SRC += $(wildcard $(BLAKE3DIR)/*_x86-64_unix.S) +BLAKE3SRC += $(wildcard sdar/lib/blake3/*_x86-64_unix.S) BLAKE3FLAGS := -DBLAKE3_NO_SSE2 endif ifeq ($(CPU),arm64) -BLAKE3SRC += $(BLAKE3DIR)/blake3_neon.c +BLAKE3SRC += sdar/lib/blake3/blake3_neon.c BLAKE3FLAGS += -DBLAKE3_USE_NEON=1 endif BLAKE3OBJ = $(BLAKE3SRC:sdar/%.c=obj/%.o) BLAKE3OBJ := $(BLAKE3OBJ:sdar/%.S=obj/%.o) -CRYPTOSRC = $(wildcard sdar/lib/crypto/*.c) -CRYPTOOBJ = $(CRYPTOSRC:sdar/%.c=obj/%.o) +SCRYPTSRC = $(wildcard sdar/lib/scrypt/*.c) +SCRYPTOBJ = $(SCRYPTSRC:sdar/%.c=obj/%.o) -NACLDIR = sdar/lib/nacl -NACLSRC = $(wildcard $(NACLDIR)/*.c) +NACLSRC = $(wildcard sdar/lib/nacl/*.c) ifeq ($(CPU),x86_64) -NACLSRC += $(wildcard $(NACLDIR)/x86_64/*.[cS]) +NACLSRC += $(wildcard sdar/lib/nacl/x86_64/*.[cS]) else -NACLSRC += $(wildcard $(NACLDIR)/generic/*.[cS]) +NACLSRC += $(wildcard sdar/lib/nacl/generic/*.c) endif NACLOBJ = $(NACLSRC:sdar/%.c=obj/%.o) NACLOBJ := $(NACLOBJ:sdar/%.S=obj/%.o) @@ -49,11 +47,10 @@ OBJ = $(SRC:sdar/%.c=obj/%.o) SANFLAGS = -g -fsanitize=address,undefined LDFLAGS += $(SANFLAGS) CFLAGS += -fno-omit-frame-pointer -std=c11 -Wall -Wextra -pedantic -CFLAGS += -I$(NACLDIR) -I$(BLAKE3DIR) -I$(LZ4DIR) CFLAGS += -DMMH_KEYSZ=32 -DMMH_VALSZ=16 -DMMH_HDRSZ=8 LIBFLAGS = -O3 -Isdar $(BLAKE3FLAGS) -obj/$(BIN): $(OBJ) $(NACLOBJ) $(BLAKE3OBJ) $(CRYPTOOBJ) $(LZ4OBJ) +obj/$(BIN): $(OBJ) $(NACLOBJ) $(BLAKE3OBJ) $(SCRYPTOBJ) $(LZ4OBJ) @test -z "$(V)" || echo "ld $@" $(V)$(CC) $^ -o $@ $(LDFLAGS) @@ -72,19 +69,20 @@ obj/%.o: sdar/%.S obj/timestamp: @mkdir -p obj @mkdir -p obj/lib/blake3 - @mkdir -p obj/lib/crypto + @mkdir -p obj/lib/scrypt @mkdir -p obj/lib/lz4 @mkdir -p obj/lib/nacl @mkdir -p obj/lib/nacl/x86_64 @mkdir -p obj/lib/nacl/generic @touch $@ -$(OBJ) $(CRYPTOOBJ) $(LZ4OBJ) $(NACLOBJ) $(BLAKE3OBJ): obj/timestamp +$(OBJ) $(SCRYPTOBJ) $(LZ4OBJ) $(NACLOBJ) $(BLAKE3OBJ): obj/timestamp $(OBJ): sdar/all.h sdar/mmh.h -$(CRYPTOOBJ): sdar/all.h -$(LZ4OBJ): $(LZ4DIR)/lz4.h -$(NACLOBJ): $(NACLDIR)/nacl.h -$(BLAKE3OBJ): $(BLAKE3DIR)/blake3.h $(BLAKE3DIR)/blake3_impl.h +$(OBJ) $(SCRYPTOBJ): sdar/lib/scrypt/scrypt.h +$(OBJ) $(LZ4OBJ): sdar/lib/lz4/lz4.h +$(OBJ) $(NACLOBJ): sdar/lib/nacl/nacl.h +$(OBJ) $(BLAKE3OBJ): sdar/lib/blake3/blake3.h +$(BLAKE3OBJ): sdar/lib/blake3/blake3_impl.h clean: rm -fr obj @@ -242,8 +242,3 @@ int stashcommit(Arch *, uchar[Segidsz]); void writerinit(Writer *, flushcb *, void *); int writer(Writer *, uchar *, vlong); int writerdone(Writer *, Addr *); - -/* lib/crypto */ -void scrypt_smix(uint8_t *, size_t, uint64_t, void *, void *); -int scrypt(uint8_t *, size_t, uint8_t *, size_t, uint64_t, uint32_t, uint32_t, uint8_t *, size_t); -void pbkdf2_sha256(uchar *, size_t, uint8_t *, size_t, uint64_t, uint8_t *, size_t); diff --git a/sdar/arch.c b/sdar/arch.c index 6626457..fa1f8d2 100644 --- a/sdar/arch.c +++ b/sdar/arch.c @@ -7,8 +7,8 @@ #include <fcntl.h> #include <sys/stat.h> #include <unistd.h> -#include <nacl.h> -#include <lz4.h> +#include "lib/nacl/nacl.h" +#include "lib/lz4/lz4.h" typedef struct Cacheblk Cacheblk; @@ -1,7 +1,8 @@ #include "all.h" #include <stddef.h> #include <string.h> -#include <nacl.h> +#include "lib/scrypt/scrypt.h" +#include "lib/nacl/nacl.h" MAKESURE(nacl_nonce_len_is_Noncesz, crypto_secretbox_NONCEBYTES == Noncesz); MAKESURE(nacl_key_len_is_Keysz, crypto_secretbox_KEYBYTES == Keysz); diff --git a/sdar/lib/nacl/box.c b/sdar/lib/nacl/box.c index 8119596..5dd592b 100644 --- a/sdar/lib/nacl/box.c +++ b/sdar/lib/nacl/box.c @@ -1,4 +1,4 @@ -#include <nacl.h> +#include "nacl.h" int crypto_box_keypair( unsigned char *pk, diff --git a/sdar/lib/nacl/curve25519.c b/sdar/lib/nacl/curve25519.c index 51937ae..4c03562 100644 --- a/sdar/lib/nacl/curve25519.c +++ b/sdar/lib/nacl/curve25519.c @@ -22,7 +22,7 @@ * from the sample implementation. */ -#include <nacl.h> +#include "nacl.h" #include <string.h> #include <stdint.h> diff --git a/sdar/lib/nacl/generic/poly1305_auth.c b/sdar/lib/nacl/generic/poly1305_auth.c index 9ac7b9c..19e55f7 100644 --- a/sdar/lib/nacl/generic/poly1305_auth.c +++ b/sdar/lib/nacl/generic/poly1305_auth.c @@ -4,7 +4,7 @@ D. J. Bernstein Public domain. */ -#include <nacl.h> +#include "../nacl.h" typedef unsigned char uchar; typedef int int32; diff --git a/sdar/lib/nacl/generic/salsa20.c b/sdar/lib/nacl/generic/salsa20.c index 5376ff6..89e1934 100644 --- a/sdar/lib/nacl/generic/salsa20.c +++ b/sdar/lib/nacl/generic/salsa20.c @@ -4,7 +4,7 @@ D. J. Bernstein Public domain. */ -#include <nacl.h> +#include "../nacl.h" #define ROUNDS 20 diff --git a/sdar/lib/nacl/generic/salsa20_stream.c b/sdar/lib/nacl/generic/salsa20_stream.c index 2881ce8..9c8811a 100644 --- a/sdar/lib/nacl/generic/salsa20_stream.c +++ b/sdar/lib/nacl/generic/salsa20_stream.c @@ -4,7 +4,7 @@ D. J. Bernstein Public domain. */ -#include <nacl.h> +#include "../nacl.h" typedef unsigned int uint32; diff --git a/sdar/lib/nacl/hsalsa20.c b/sdar/lib/nacl/hsalsa20.c index 42a831a..5eda21a 100644 --- a/sdar/lib/nacl/hsalsa20.c +++ b/sdar/lib/nacl/hsalsa20.c @@ -4,7 +4,7 @@ D. J. Bernstein Public domain. */ -#include <nacl.h> +#include "nacl.h" #define ROUNDS 20 diff --git a/sdar/lib/nacl/poly1305_verify.c b/sdar/lib/nacl/poly1305_verify.c index db2bf0a..c011f43 100644 --- a/sdar/lib/nacl/poly1305_verify.c +++ b/sdar/lib/nacl/poly1305_verify.c @@ -1,4 +1,4 @@ -#include <nacl.h> +#include "nacl.h" int crypto_onetimeauth_poly1305_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k) { diff --git a/sdar/lib/nacl/randombytes.c b/sdar/lib/nacl/randombytes.c index f5f7ef1..bcdb898 100644 --- a/sdar/lib/nacl/randombytes.c +++ b/sdar/lib/nacl/randombytes.c @@ -1,4 +1,4 @@ -#include <nacl.h> +#include "nacl.h" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> diff --git a/sdar/lib/nacl/secretbox.c b/sdar/lib/nacl/secretbox.c index ab1e526..2ef6e87 100644 --- a/sdar/lib/nacl/secretbox.c +++ b/sdar/lib/nacl/secretbox.c @@ -1,4 +1,4 @@ -#include <nacl.h> +#include "nacl.h" int crypto_secretbox( unsigned char *c, diff --git a/sdar/lib/nacl/verify_16.c b/sdar/lib/nacl/verify_16.c index 09db9f5..948093f 100644 --- a/sdar/lib/nacl/verify_16.c +++ b/sdar/lib/nacl/verify_16.c @@ -1,4 +1,4 @@ -#include <nacl.h> +#include "nacl.h" int crypto_verify_16(const unsigned char *x,const unsigned char *y) { diff --git a/sdar/lib/nacl/xsalsa20.c b/sdar/lib/nacl/xsalsa20.c index 541fe04..c8f0a3d 100644 --- a/sdar/lib/nacl/xsalsa20.c +++ b/sdar/lib/nacl/xsalsa20.c @@ -4,7 +4,7 @@ D. J. Bernstein Public domain. */ -#include <nacl.h> +#include "nacl.h" static const unsigned char sigma[16] = "expand 32-byte k"; diff --git a/sdar/lib/crypto/scrypt.c b/sdar/lib/scrypt/scrypt.c index 730321c..a36b324 100644 --- a/sdar/lib/crypto/scrypt.c +++ b/sdar/lib/scrypt/scrypt.c @@ -26,7 +26,7 @@ * This file was originally written by Colin Percival as part of the Tarsnap * online backup system. */ -#include "../../all.h" +#include "scrypt.h" #include <errno.h> #include <stdint.h> #include <stdlib.h> diff --git a/sdar/lib/scrypt/scrypt.h b/sdar/lib/scrypt/scrypt.h new file mode 100644 index 0000000..1587601 --- /dev/null +++ b/sdar/lib/scrypt/scrypt.h @@ -0,0 +1,22 @@ +#ifndef scrypt_H +#define scrypt_H + +#include <inttypes.h> +#include <stddef.h> + +typedef unsigned char uchar; +typedef unsigned long long uvlong; + +void scrypt_smix(uint8_t *, size_t, uint64_t, void *, void *); +int scrypt(uint8_t *, size_t, uint8_t *, size_t, uint64_t, uint32_t, uint32_t, uint8_t *, size_t); +void pbkdf2_sha256(uchar *, size_t, uint8_t *, size_t, uint64_t, uint8_t *, size_t); + +void enc32le(uchar *, uvlong); +uvlong dec32le(uchar *); + +/* from sdar/util.c */ +extern void enc32be(uchar *, uvlong); +extern void enc64be(uchar *, uvlong); +extern uvlong dec32be(uchar *); + +#endif diff --git a/sdar/lib/crypto/sha256.c b/sdar/lib/scrypt/sha256.c index edb9018..a1b0fba 100644 --- a/sdar/lib/crypto/sha256.c +++ b/sdar/lib/scrypt/sha256.c @@ -1,4 +1,5 @@ -#include "../../all.h" +#include "scrypt.h" +#include <assert.h> #include <stdint.h> #include <string.h> diff --git a/sdar/lib/crypto/smix.c b/sdar/lib/scrypt/smix.c index f2a955b..208e8cc 100644 --- a/sdar/lib/crypto/smix.c +++ b/sdar/lib/scrypt/smix.c @@ -26,7 +26,7 @@ * This file was originally written by Colin Percival as part of the Tarsnap * online backup system. */ -#include "../../all.h" +#include "scrypt.h" #include <string.h> static void blkcpy(void *, const void *, size_t); diff --git a/sdar/lib/scrypt/util.c b/sdar/lib/scrypt/util.c new file mode 100644 index 0000000..7227220 --- /dev/null +++ b/sdar/lib/scrypt/util.c @@ -0,0 +1,20 @@ +#include "scrypt.h" + +void +enc32le(uchar *p, uvlong x) +{ + p[0] = x ; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +uvlong +dec32le(uchar *p) +{ + return + ((uvlong)p[0] ) + + ((uvlong)p[1] << 8) + + ((uvlong)p[2] << 16) + + ((uvlong)p[3] << 24); +} diff --git a/sdar/slice.c b/sdar/slice.c index 6febae9..5063d7e 100644 --- a/sdar/slice.c +++ b/sdar/slice.c @@ -3,9 +3,9 @@ #include <stddef.h> #include <stdlib.h> #include <string.h> -#include <blake3.h> -#include <nacl.h> -#include <lz4.h> +#include "lib/blake3/blake3.h" +#include "lib/nacl/nacl.h" +#include "lib/lz4/lz4.h" /* module wrapping buffer allocation, crypto, * and compression functions in a uniform api */ diff --git a/sdar/stash.c b/sdar/stash.c index a5d27b9..684a30a 100644 --- a/sdar/stash.c +++ b/sdar/stash.c @@ -5,7 +5,7 @@ #include <sys/mman.h> #include <sys/stat.h> #include <unistd.h> -#include <nacl.h> +#include "lib/nacl/nacl.h" MAKESURE(Segidsz_is_ok, Segidsz <= Keysz); diff --git a/sdar/util.c b/sdar/util.c index 7bb52b4..853b61a 100644 --- a/sdar/util.c +++ b/sdar/util.c @@ -130,15 +130,6 @@ enc32be(uchar *p, uvlong x) } void -enc32le(uchar *p, uvlong x) -{ - p[0] = x ; - p[1] = x >> 8; - p[2] = x >> 16; - p[3] = x >> 24; -} - -void enc64be(uchar *p, uvlong x) { p[0] = x >> 56; @@ -162,16 +153,6 @@ dec32be(uchar *p) } uvlong -dec32le(uchar *p) -{ - return - ((uvlong)p[0] ) + - ((uvlong)p[1] << 8) + - ((uvlong)p[2] << 16) + - ((uvlong)p[3] << 24); -} - -uvlong dec64be(uchar *p) { return |
