Commit c238d930 authored by Davide Galassi's avatar Davide Galassi

Merge branch 'master' into unit_test_refactory

parents 5e64e317 d785d79b
Pipeline #65296117 passed with stages
in 2 minutes and 37 seconds
BasedOnStyle: LLVM
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Merge
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
libcry.a
build
include/cry/config.h
test/test
test/out
doc/html
......
......@@ -17,7 +17,7 @@ test:
dependencies:
- build
script:
- make test
- make test CONFIG=config/config-ci.mk
- (cd test; valgrind --leak-check=full --error-exitcode=2 ./test)
- gcovr --exclude test -r . | grep TOTAL
......
language: c
script:
- make test && (cd test; ./test)
- make test CONFIG=config/config-ci.mk
- (cd test; ./test)
before_install:
- pip install --user -q cpp-coveralls
......
......@@ -28,6 +28,7 @@ Added
* Some NIST recommended elliptic curve domain parameters over Fp.
* Some Brainpool standard curve domain parameters over Fp (RFC 5639).
* Malloc mock and Valgrind used to execute CI unit-tests
[0.0.9] - 2019-04-22
......
include config.mk
CONFIG := config/config.mk
include $(CONFIG)
CC := gcc
AR := ar
......@@ -7,18 +9,14 @@ CP := cp
RM := rm -rf
source_dir := src
config := include/cry/config.h
#
# Get build name
#
config_mk := $(CONFIG)
config_h := include/cry/config.h
# $(call normalstr,str)
build_name = $(shell $(CC) -dumpmachine)
# convert to lowercase
binary_dir = build/$(build_name)
# call $(src_to_bin_dir,list)
src_to_bin_dir = $(patsubst $(source_dir)%,$(binary_dir)%,$1)
......@@ -26,31 +24,29 @@ target = $(binary_dir)/libcry.a
.SUFFIXES:
includes-y := -Iinclude -Isrc -include $(config)
warnings := -Wall -Wextra -Wshadow -Wstrict-prototypes -Wmissing-prototypes
#-Wpedantic
#-Wconversion
includes-y := -Iinclude -Isrc
cflags-y := -Wall -MMD -MP
cflags-y := -MMD -MP $(warnings)
cflags-$(CRY_COVERAGE) += --coverage
cflags-$(CRY_SHORT_ENUMS) += -fshort-enums
cflags-$(CRY_OMIT_FRAME_POINTER) += -fomit-frame-pointer
ifeq ($(CRY_STACK_PROTECTOR),y)
cflags-y += -fstack-protector
else
cflags-y += -fno-stack-protector
endif
cflags-$(CRY_NO_STACK_PROTECTOR) += -fno-stack-protector
ifeq ($(CRY_DEBUG),y)
cflags-y += -O0 -g3 -fno-inline
cflags-y += -O0 -g3
else
cflags-y += -DNDEBUG
ifeq ($(CRY_SMALL_SIZE),y)
cflags-y += -Os
else
cflags-y += -O3 -funroll-loops
cflags-y += -O3
endif
endif
objects-y :=
paths-y :=
objects_list :=
......@@ -72,51 +68,67 @@ $(eval $(call include_subdir,src))
objects = $(call src_to_bin_dir,$(objects_list))
depends = $(patsubst %.o,%.d,$(objects))
CPPFLAGS = $(includes-y)
CFLAGS = $(cflags-y)
AFLAGS = $(aflags-y)
LDFLAGS = $(lflags-y)
DATE := $(shell date +'%y%m%d')
CPPFLAGS := $(includes-y)
CFLAGS := $(cflags-y)
AFLAGS := $(aflags-y)
LDFLAGS := $(lflags-y)
.PHONY: all cry clean test testclean doc
################################################################################
# Targets
################################################################################
all: cry
.PHONY: all clean config test testclean doc
cry: $(target)
# Force serial run
all:
$(MAKE) config
$(MAKE) $(target)
clean:
@$(RM) $(binary_dir) $(config) *.a
@echo "Cleanup ..."
@$(RM) $(binary_dir) *.a
@$(RM) `find . -type f \( -name \*.gcda -o -name \*.gcno \)`
$(objects): Makefile config.mk $(config)
config: $(config_mk)
@printf "/*\n * Automatically generated from \"$^\".\n */\n\n" > tmp
@$(AWK) -F= 'NF > 1 && $$1 !~ /^[# ]/ { print "#define", $$1; }' < $^ >> tmp
@cmp -s tmp $(config_h) || (echo "Configuration update"; cp tmp $(config_h))
@$(RM) tmp
@echo ">>> Config : $(config_mk)"
@cat $(config_h) | grep CRY_ | $(AWK) '{ printf(" * %s\n", $$2); }'
$(target): $(objects)
$(AR) rcs $@ $^
$(CP) $(target) .
$(config): config.mk
@printf "/*\n * Automatically generated. Do not edit.\n */\n\n" > $(config)
@$(AWK) -F= 'NF > 1 && $$1 !~ /^[# ]/ { print "#define", $$1; }' $< >> $(config)
@echo "#define CRY_RELEASE $(DATE)" >> $(config)
@echo "#define CRY_CFLAGS \"$(CFLAGS)\"" >> $(config)
$(objects): Makefile $(config_h)
$(config_h): $(config_mk)
touch $(config_h)
$(binary_dir)/%.o: $(source_dir)/%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
test: $(target)
make -C test
test: all
$(MAKE) -C test
testclean:
make -C test clean
$(MAKE) -C test clean
doc:
cd doc; doxygen Doxyfile.in
###############################################################################
# Code quality tools reports
###############################################################################
# include the .d files, if they do not exists then are generated by
# the rule the pattern rule.
# The `-` prefix suppress the warnings relative to the fact that initially
# make do not finds the files (before trying to create them).
ifneq ($(MAKECMDGOALS),clean)
-include $(depends)
endif
################################################################################
# Code quality tools reports targets
################################################################################
# Overwrite from command line with: `make SONAR_SCANNER=<path>`
SONAR_SCANNER := sonar-scanner
......
......@@ -9,9 +9,9 @@
################################################################################
CRY_DEBUG=y
#CRY_OMIT_FRAME_POINTER=y
#CRY_SMALL_SIZE=y
#CRY_STACK_PROTECTOR=y
#CRY_OMIT_FRAME_POINTER=y
#CRY_NO_STACK_PROTECTOR=y
CRY_COVERAGE=y
################################################################################
......@@ -69,4 +69,4 @@ CRY_ECP_GRP_BP512R1_ENABLE=y
################################################################################
CRY_MPI_DEBUG_CONF=y
CRY_CONTRACT_VALIDATE=y
################################################################################
# CRY build configuration.
#
# This file is included by Makefile.
################################################################################
################################################################################
# Compiler
################################################################################
CRY_DEBUG=y
#CRY_SMALL_SIZE=y
#CRY_OMIT_FRAME_POINTER=y
#CRY_NO_STACK_PROTECTOR=y
#CRY_COVERAGE=y
################################################################################
# Platform
################################################################################
#CRY_ARCH_X86_64=y
#CRY_ARCH_x86=y
################################################################################
# Algorithms tweaks
################################################################################
# Use Extended Euclidean Algorithm to compute inverse.
# If not defined the faster Binary Extended Algorithm (HAC 14.4.3) is used.
CRY_MPI_INV_EUCLID=y
# Small footprint division. Slower.
#CRY_MPI_DIV_SMALL=y
# Comba as baseline multiplier
CRY_MPI_MUL_COMBA=y
# Karatsuba multiplier enabled, see the mpi_mul.c to set the CUTOFF
CRY_MPI_MUL_KARATSUBA=y
#
# Toom-3 multiplier enabled, see the mpi_mul.c to set the CUTOFF
CRY_MPI_MUL_TOOM3=y
# Elliptic curve point multiplication with windowed algorithm
CRY_ECP_MUL_WIN=y
# Elliptic curve point multiplication with sliding window algorithm (faster)
# Have precedence against the simple windowed one.
CRY_ECP_MUL_SLIDING_WIN=y
################################################################################
# Elliptic curves group parameters
################################################################################
CRY_ECP_GRP_SECP192R1_ENABLE=y
CRY_ECP_GRP_SECP224R1_ENABLE=y
CRY_ECP_GRP_SECP256R1_ENABLE=y
CRY_ECP_GRP_SECP384R1_ENABLE=y
CRY_ECP_GRP_SECP521R1_ENABLE=y
CRY_ECP_GRP_SECP192K1_ENABLE=y
CRY_ECP_GRP_SECP224K1_ENABLE=y
CRY_ECP_GRP_SECP256K1_ENABLE=y
CRY_ECP_GRP_BP256R1_ENABLE=y
CRY_ECP_GRP_BP384R1_ENABLE=y
CRY_ECP_GRP_BP512R1_ENABLE=y
################################################################################
# Miscelanea configurations
################################################################################
#CRY_MPI_DEBUG_CONF=y
#CRY_CONTRACT_VALIDATE=y
This diff is collapsed.
......@@ -30,9 +30,9 @@
<locationURI>SOURCE_DIR/Makefile</locationURI>
</link>
<link>
<name>config.mk</name>
<type>1</type>
<locationURI>SOURCE_DIR/config.mk</locationURI>
<name>config</name>
<type>2</type>
<locationURI>SOURCE_DIR/config</locationURI>
</link>
<link>
<name>include</name>
......
......@@ -15,15 +15,15 @@
#define CRY_AES_MODE_DECRYPT 2
struct cry_aes_ctx {
uint32_t keys[60]; /** Maximum size of key schedule */
unsigned int nr; /** Number of rounds */
int mode; /** Encrypt/decrypt */
uint32_t keys[60]; /** Maximum size of key schedule */
unsigned int nr; /** Number of rounds */
int mode; /** Encrypt/decrypt */
};
typedef struct cry_aes_ctx cry_aes_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
/**
......
......@@ -46,9 +46,9 @@ int cry_affine_init(struct cry_affine_ctx *ctx, const unsigned char *keya,
const unsigned char *keyb, size_t keylen);
void cry_affine_encrypt(struct cry_affine_ctx *ctx, unsigned char *out,
const unsigned char *in, size_t len);
const unsigned char *in, size_t len);
void cry_affine_decrypt(struct cry_affine_ctx *ctx, unsigned char *out,
const unsigned char *in, size_t len);
const unsigned char *in, size_t len);
#endif /* CRY_AFFINE_H_ */
......@@ -6,12 +6,12 @@
#ifndef CRY_BASE64_H_
#define CRY_BASE64_H_
#include <stddef.h>
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
#include <stddef.h>
size_t cry_base64_encode(char *out, const char *in, size_t len);
size_t cry_base64_decode(char *out, const char *in, size_t len);
......
......@@ -19,15 +19,15 @@ struct cry_cbc_ctx {
/** Cipher interface. */
const struct cry_ciph_itf *ciph_itf;
/** Counter */
unsigned char ctr[CRY_CBC_BLOCK_MAX];
unsigned char ctr[CRY_CBC_BLOCK_MAX];
/** Counter length */
size_t ctrlen;
size_t ctrlen;
};
typedef struct cry_cbc_ctx cry_cbc_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
/**
......
......@@ -26,15 +26,15 @@ struct cry_cfb_ctx {
/** Cipher interface. */
const struct cry_ciph_itf *ciph_itf;
/** Initialization vector length */
size_t vlen;
size_t vlen;
/** Initialization vector data. */
unsigned char v[CRY_CFB_BLOCK_MAX];
unsigned char v[CRY_CFB_BLOCK_MAX];
};
typedef struct cry_cfb_ctx cry_cfb_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
/**
......
......@@ -9,7 +9,7 @@
#include <stddef.h>
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
/**
......@@ -71,12 +71,12 @@ typedef void (* cry_ciph_decrypt_f)(void *ctx, unsigned char *dst,
* Cipher algorithm generic interface.
*/
struct cry_ciph_itf {
cry_ciph_init_f init;
cry_ciph_clean_f clean;
cry_ciph_key_set_f key_set;
cry_ciph_iv_set_f iv_set;
cry_ciph_encrypt_f encrypt;
cry_ciph_decrypt_f decrypt;
cry_ciph_init_f init;
cry_ciph_clean_f clean;
cry_ciph_key_set_f key_set;
cry_ciph_iv_set_f iv_set;
cry_ciph_encrypt_f encrypt;
cry_ciph_decrypt_f decrypt;
};
typedef struct cry_ciph_itf cry_ciph_itf;
......
......@@ -12,7 +12,7 @@
#include <stddef.h>
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
#define CRY_CMAC_BLOCK_SIZE 16
......@@ -20,9 +20,9 @@ extern "C"{
struct cry_cmac_ctx {
void *ciph_ctx; /**< Block cipher context */
const struct cry_ciph_itf *ciph_itf; /**< Block cipher interface */
size_t blklen; /**< Pending block size */
unsigned char blk[CRY_CMAC_BLOCK_SIZE]; /**< Pending block */
unsigned char mac[CRY_CMAC_BLOCK_SIZE]; /**< Current MAC */
size_t blklen; /**< Pending block size */
unsigned char blk[CRY_CMAC_BLOCK_SIZE]; /**< Pending block */
unsigned char mac[CRY_CMAC_BLOCK_SIZE]; /**< Current MAC */
};
typedef struct cry_cmac_ctx cry_cmac_ctx;
......
/*
* Automatically generated from "config/config.mk".
*/
#define CRY_DEBUG
#define CRY_MPI_INV_EUCLID
#define CRY_MPI_MUL_COMBA
#define CRY_MPI_MUL_KARATSUBA
#define CRY_MPI_MUL_TOOM3
#define CRY_ECP_MUL_WIN
#define CRY_ECP_MUL_SLIDING_WIN
#define CRY_ECP_GRP_SECP192R1_ENABLE
#define CRY_ECP_GRP_SECP224R1_ENABLE
#define CRY_ECP_GRP_SECP256R1_ENABLE
#define CRY_ECP_GRP_SECP384R1_ENABLE
#define CRY_ECP_GRP_SECP521R1_ENABLE
#define CRY_ECP_GRP_SECP192K1_ENABLE
#define CRY_ECP_GRP_SECP224K1_ENABLE
#define CRY_ECP_GRP_SECP256K1_ENABLE
#define CRY_ECP_GRP_BP256R1_ENABLE
#define CRY_ECP_GRP_BP384R1_ENABLE
#define CRY_ECP_GRP_BP512R1_ENABLE
......@@ -24,8 +24,8 @@
*/
struct cry_crc16_ctx {
const uint16_t *tab;
uint16_t crc;
unsigned char flags;
uint16_t crc;
unsigned char flags;
};
typedef struct cry_crc16_ctx cry_crc16_ctx;
......@@ -35,14 +35,14 @@ typedef struct cry_crc16_ctx cry_crc16_ctx;
*/
struct cry_crc32_ctx {
const uint32_t *tab;
uint32_t crc;
unsigned char flags;
uint32_t crc;
unsigned char flags;
};
typedef struct cry_crc32_ctx cry_crc32_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
/**
......
......@@ -27,15 +27,15 @@ struct cry_ctr_ctx {
/** Cipher interface. */
const struct cry_ciph_itf *ciph_itf;
/** Counter. */
unsigned char ctr[CRY_CTR_BLOCK_MAX];
unsigned char ctr[CRY_CTR_BLOCK_MAX];
/** Counter length */
size_t ctrlen;
size_t ctrlen;
};
typedef struct cry_ctr_ctx cry_ctr_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
/**
......
......@@ -14,7 +14,7 @@
/** DES context */
struct cry_des_ctx {
size_t keylen; /* 8 for normal DES, 24 for triple DES */
size_t keylen; /* 8 for normal DES, 24 for triple DES */
unsigned char key[3*CRY_DES_BLOCK_SIZE];
};
......
......@@ -20,7 +20,7 @@ struct cry_dh_ctx {
typedef struct cry_dh_ctx cry_dh_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
int cry_dh_init(cry_dh_ctx *ctx);
......
......@@ -9,11 +9,11 @@
#include <cry/mpi.h>
struct cry_dsa_ctx {
cry_mpi g;
cry_mpi p;
cry_mpi q;
cry_mpi pvt; /**< Private signing key */
cry_mpi pub; /**< Public verification key */
cry_mpi g;
cry_mpi p;
cry_mpi q;
cry_mpi pvt; /**< Private signing key */
cry_mpi pub; /**< Public verification key */
};
typedef struct cry_dsa_ctx cry_dsa_ctx;
......@@ -26,7 +26,7 @@ struct cry_dsa_signature {
typedef struct cry_dsa_signature cry_dsa_signature;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
int cry_dsa_sign(cry_dsa_ctx *ctx, cry_dsa_signature *sign,
......
......@@ -10,15 +10,15 @@
struct cry_ecdh_ctx {
cry_ecp_grp ec; /**> Elliptic curve group */
cry_mpi d; /**> Private key */
cry_ecp q; /**> Public key */
cry_ecp z; /**> Shared secret */
cry_mpi d; /**> Private key */
cry_ecp q; /**> Public key */
cry_ecp z; /**> Shared secret */
};
typedef struct cry_ecdh_ctx cry_ecdh_ctx;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
int cry_ecdh_init(cry_ecdh_ctx *ctx);
......
......@@ -9,7 +9,7 @@
#include <cry/ecp.h>
struct cry_ecdsa_ctx {
cry_ecp_grp ec; /**< Elliptic curve group parameters */
cry_ecp_grp ec; /**< Elliptic curve group parameters */
cry_mpi d; /**< Private signing key */
cry_ecp q; /**< Public verification key */
};
......@@ -24,7 +24,7 @@ struct cry_ecdsa_signature {
typedef struct cry_ecdsa_signature cry_ecdsa_signature;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
int cry_ecdsa_sign(cry_ecdsa_ctx *ctx, cry_ecdsa_signature *sign,
......
......@@ -46,7 +46,7 @@ typedef struct cry_ecp_grp cry_ecp_grp;
#ifdef __cplusplus
extern "C"{
extern "C" {
#endif
int cry_ecp_init(cry_ecp *p);
......
......@@ -18,24 +18,24 @@ struct cry_gcm_ctx {
/** Block cipher interface. */
const struct cry_ciph_itf *ciph_itf;
/** Initialization vector */
unsigned char iv[CRY_GCM_BLOCK_SIZE];
unsigned char iv[CRY_GCM_BLOCK_SIZE];
/** Counter. */
unsigned char ctr[CRY_GCM_BLOCK_SIZE];