Skip to content

Commit

Permalink
Rework make system. Now builds public key version of code as well as
Browse files Browse the repository at this point in the history
the private key version.
  • Loading branch information
diagprov committed Dec 10, 2019
1 parent 06b0769 commit 3b00a91
Show file tree
Hide file tree
Showing 17 changed files with 380 additions and 87 deletions.
79 changes: 79 additions & 0 deletions include/e4/crypto/fixedint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Portable header to provide the 32 and 64 bits type.
Not a compatible replacement for <stdint.h>, do not blindly use it as such.
*/

#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || \
(defined(__WATCOMC__) && (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || \
(defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || \
defined(__UINT_FAST64_TYPE__)))) && \
!defined(FIXEDINT_H_INCLUDED)
#include <stdint.h>
#define FIXEDINT_H_INCLUDED

#if defined(__WATCOMC__) && __WATCOMC__ >= 1250 && !defined(UINT64_C)
#include <limits.h>
#define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
#endif
#endif


#ifndef FIXEDINT_H_INCLUDED
#define FIXEDINT_H_INCLUDED

#include <limits.h>

/* (u)int32_t */
#ifndef uint32_t
#if (ULONG_MAX == 0xffffffffUL)
typedef unsigned long uint32_t;
#elif (UINT_MAX == 0xffffffffUL)
typedef unsigned int uint32_t;
#elif (USHRT_MAX == 0xffffffffUL)
typedef unsigned short uint32_t;
#endif
#endif


#ifndef int32_t
#if (LONG_MAX == 0x7fffffffL)
typedef signed long int32_t;
#elif (INT_MAX == 0x7fffffffL)
typedef signed int int32_t;
#elif (SHRT_MAX == 0x7fffffffL)
typedef signed short int32_t;
#endif
#endif


/* (u)int64_t */
#if (defined(__STDC__) && defined(__STDC_VERSION__) && __STDC__ && __STDC_VERSION__ >= 199901L)
typedef long long int64_t;
typedef unsigned long long uint64_t;

#define UINT64_C(v) v##ULL
#define INT64_C(v) v##LL
#elif defined(__GNUC__)
__extension__ typedef long long int64_t;
__extension__ typedef unsigned long long uint64_t;

#define UINT64_C(v) v##ULL
#define INT64_C(v) v##LL
#elif defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || \
defined(__APPLE_CC__) || defined(_LONG_LONG) || defined(_CRAYC)
typedef long long int64_t;
typedef unsigned long long uint64_t;

#define UINT64_C(v) v##ULL
#define INT64_C(v) v##LL
#elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || \
(defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || \
(defined(__BORLANDC__) && __BORLANDC__ > 0x460) || defined(__alpha) || defined(__DECC)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;

#define UINT64_C(v) v##UI64
#define INT64_C(v) v##I64
#endif
#endif
31 changes: 0 additions & 31 deletions mk/objects.mk

This file was deleted.

26 changes: 26 additions & 0 deletions mk/pubkey/conf.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

CC ?= clang
AR ?= ar
LD ?= clang
ARFLAGS = rcs
CFLAGS = -Wall -Werror -g -DE4_STORE_FILE -std=c89 $(E4_CFLAGS)
LDFLAGS = -L. $(E4_CFLAGS)
INCLUDES = -Iinclude/

# BUILD environment
GITCOMMIT=$(shell git rev-list -1 HEAD)
NOW=$(shell date "+%Y%m%d%H%M")

# OBJ paths match their src folder equivalents
INCDIR = include
OBJDIR = tmp/symkey
SRCDIR = src
DOCDIR = doc
LIBDIR = build/symkey/lib
OUTINCDIR = build/symkey/include
LIBNAME = libe4
LIB = $(LIBDIR)/$(LIBNAME).a
DISTDIR = dist/symkey/
TESTDIR = build/symkey/test

O = o
30 changes: 30 additions & 0 deletions mk/pubkey/objects.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

OBJS = $(OBJDIR)/e4pkcclient.$O \
$(OBJDIR)/e4util.$O \
$(OBJDIR)/crypto/aes_siv.$O \
$(OBJDIR)/crypto/aes256enc_ref.$O \
$(OBJDIR)/crypto/sha3.$O \
$(OBJDIR)/crypto/keccakf1600.$O \
$(OBJDIR)/crypto/test_aes_siv.$O \
$(OBJDIR)/crypto/test_sha3.$O \
$(OBJDIR)/strlcpy.$O \
$(OBJDIR)/crypto/curve25519/curve25519-donna.$O \
$(OBJDIR)/crypto/ed25519/add_scalar.$O \
$(OBJDIR)/crypto/ed25519/ed25519_test.$O \
$(OBJDIR)/crypto/ed25519/fe.$O \
$(OBJDIR)/crypto/ed25519/ge.$O \
$(OBJDIR)/crypto/ed25519/key_exchange.$O \
$(OBJDIR)/crypto/ed25519/keypair.$O \
$(OBJDIR)/crypto/ed25519/sc.$O \
$(OBJDIR)/crypto/ed25519/seed.$O \
$(OBJDIR)/crypto/ed25519/sign.$O \
$(OBJDIR)/crypto/ed25519/verify.$O \
$(OBJDIR)/crypto/sha512.$O




TESTS = \
$(TESTDIR)/util \
$(TESTDIR)/crypto \
$(TESTDIR)/e4file
7 changes: 7 additions & 0 deletions mk/pubkey/tests.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

PUBKEY_TESTS = \
$(TESTDIR)/util \
$(TESTDIR)/crypto \
$(TESTDIR)/e4file

TESTS += $(PUBKEY_TESTS)
14 changes: 14 additions & 0 deletions mk/qa.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

E4_CFLAGS = -fsanitize=address,memory,undefined -fno-omit-frame-pointer
E4_LDFLAGS = -fsanitize=address,memory,undefined -fno-omit-frame-pointer

CONF = symkey
include mk/symkey/conf.mk
include mk/symkey/objects.mk
include mk/symkey/tests.mk
include mk/rules.mk

include mk/pubkey/conf.mk
include mk/pubkey/objects.mk
include mk/pubkey/tests.mk
include mk/rules.mk
5 changes: 2 additions & 3 deletions mk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ setup:
mkdir -p $(OBJDIR)/crypto; \
mkdir -p $(OBJDIR)/crypto/curve25519; \
mkdir -p $(OBJDIR)/crypto/ed25519; \
mkdir -p $(OBJDIR)/crypto/ctaes; \
mkdir -p $(TESTDIR); \
mkdir -p $(LIBDIR); \
mkdir -p $(DISTDIR); \

Expand Down Expand Up @@ -43,7 +45,4 @@ format:
$(TESTDIR)/%: test/%.c $(LIB)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $< $(LIB)

# Configuration mode tests
build/test/e4symmetric: test/e4.c $(LIB)
$(CC) $(CFLAGS) $(INCLUDES) -DE4_STORE_FILE=1 -o $@ $< $(LIB)

37 changes: 0 additions & 37 deletions mk/rules_qa.mk

This file was deleted.

17 changes: 9 additions & 8 deletions mk/conf_default.mk → mk/symkey/conf.mk
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@

CC ?= clang
CC ?= clang
AR ?= ar
ARFLAGS = rcs
CFLAGS = -Wall -Werror -g -DE4_STORE_FILE -std=c89
LDFLAGS = -L.
CFLAGS = -Wall -Werror -g -DE4_STORE_FILE -std=c89 $(E4_CFLAGS)
LDFLAGS = -L. $(E4_CFLAGS)
INCLUDES = -Iinclude/

# BUILD environment
GITCOMMIT=$(shell git rev-list -1 HEAD)
NOW=$(shell date "+%Y%m%d%H%M")

# OBJ paths match their src folder equivalents
INCDIR = include
OBJDIR = tmp/default
INCDIR = include
OBJDIR = tmp/symkey
SRCDIR = src
DOCDIR = doc
LIBDIR = build/lib
OUTINCDIR = build/include
LIBDIR = build/symkey/lib
OUTINCDIR = build/symkey/include
LIBNAME = libe4
LIB = $(LIBDIR)/$(LIBNAME).a
DISTDIR = dist
DISTDIR = dist/symkey/
TESTDIR = build/symkey/test

O = o
11 changes: 11 additions & 0 deletions mk/symkey/objects.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

OBJS = $(OBJDIR)/e4c_store_file.$O \
$(OBJDIR)/e4util.$O \
$(OBJDIR)/crypto/aes_siv.$O \
$(OBJDIR)/crypto/aes256enc_ref.$O \
$(OBJDIR)/crypto/sha3.$O \
$(OBJDIR)/crypto/keccakf1600.$O \
$(OBJDIR)/crypto/test_aes_siv.$O \
$(OBJDIR)/crypto/test_sha3.$O \
$(OBJDIR)/strlcpy.$O

7 changes: 7 additions & 0 deletions mk/symkey/tests.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

SYMKEY_TESTS = \
$(TESTDIR)/util \
$(TESTDIR)/crypto \
$(TESTDIR)/symkey/symkey_file

TESTS += $(SYMKEY_TESTS)
7 changes: 4 additions & 3 deletions mk/unix.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


CONF ?= default
include mk/conf_$(CONF).mk
include mk/objects.mk
CONF ?= symkey
include mk/$(CONF)/conf.mk
include mk/$(CONF)/objects.mk
include mk/$(CONF)/tests.mk
include mk/rules.mk
2 changes: 1 addition & 1 deletion src/crypto/ed25519/fe.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef FE_H
#define FE_H

#include "fixedint.h"
#include "e4/crypto/fixedint.h"


/*
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/

#include "fixedint.h"
#include "sha512.h"
#include "e4/crypto/fixedint.h"
#include "e4/crypto/sha512.h"

/* the K array */
static const uint64_t K[80] = {
Expand Down
Loading

0 comments on commit 3b00a91

Please sign in to comment.