Skip to content

Commit 08b69be

Browse files
committed
minor changes for amalgamation
* de-duplicate `struct oid_to_pbes` * add makefile target * add amalgamation to release * fix `small` demo * add header guards for `tomcrypt_private.h` * update docs * add CI job with amalgamated library Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 2364778 commit 08b69be

8 files changed

Lines changed: 74 additions & 10 deletions

File tree

.github/workflows/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,24 @@ jobs:
9898
name: build-${{ github.run_id }}.tar.xz
9999
path: build-${{ github.run_id }}.tar.xz
100100
retention-days: 1
101+
102+
Amalgam:
103+
runs-on: ${{ matrix.os }}
104+
strategy:
105+
matrix:
106+
cc: [ gcc, clang ]
107+
os: [ ubuntu-22.04, ubuntu-24.04 ]
108+
steps:
109+
- uses: actions/checkout@v4
110+
- name: install dependencies
111+
run: |
112+
sudo apt-get update -qq
113+
sudo apt-get remove -y libtommath1
114+
curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
115+
sudo apt-get install libtommath-git-dev
116+
- name: run tests
117+
env:
118+
CC: "${{ matrix.cc }}"
119+
run: |
120+
make pre_gen
121+
make CFLAGS="-DLTM_DESC -DUSE_LTM" EXTRALIBS="-ltommath" AMALGAM=1 -j$(nproc) check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# release files
1111
/libtomcrypt-*
1212
/crypt-*
13+
pre_gen/
1314

1415
# suppress output of build process
1516
gcc_[12].txt

doc/crypt.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8896,6 +8896,28 @@ \subsection{Installation Directories}
88968896
endif()
88978897
\end{verbatim}
88988898

8899+
8900+
\mysection{Amalgamated library}
8901+
8902+
LibTomCrypt can also be built as an amalgamated library, i.e. as a single C source file + the header files.
8903+
8904+
A release of the library contains the amalgamation in the path \texttt{pre\_gen/tomcrypt\_amalgam.c}.
8905+
8906+
To create the amalgamation one can run:
8907+
8908+
\begin{verbatim}
8909+
make pre_gen
8910+
\end{verbatim}
8911+
8912+
The makefiles also support building the amalgamated library via:
8913+
8914+
\begin{verbatim}
8915+
make CFLAGS="-DLTM_DESC" EXTRALIBS=-ltommath AMALGAM=1
8916+
\end{verbatim}
8917+
8918+
This will build the library and link against LibTomMath (which must be installed on your system).
8919+
8920+
88998921
\mysection{Header Configuration}
89008922
The file \textit{tomcrypt\_cfg.h} is what lets you control various high level macros which control the behaviour of the library. Build options are also
89018923
stored in \textit{tomcrypt\_custom.h} which allow the enabling and disabling of various algorithms.

makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,16 @@ coverage: $(call print-help,coverage,Create code-coverage of the library - but b
143143

144144
# cleans everything - coverage output and standard 'clean'
145145
cleancov: cleancov-clean clean
146+
ifndef AMALGAM
147+
AMALGAM_FILTER_OUT = src/ciphers/aes/aes_tab.c src/ciphers/aes/aes_enc.c src/ciphers/aes/aes_enc_desc.c
148+
SOURCES = $(filter-out $(AMALGAM_FILTER_OUT),$(OBJECTS:.o=.c))
149+
pre_gen/tomcrypt_amalgam.c: $(SOURCES)
150+
mkdir -p pre_gen
151+
printf "/*\n * This file has been auto-generated, do not edit!\n */\n\n" > $@
152+
cat $(SOURCES) >> $@
153+
154+
pre_gen: pre_gen/tomcrypt_amalgam.c
155+
156+
.PHONY: pre_gen
157+
endif
158+

makefile_include.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ library: $(call print-help,library,Builds the library) $(LIBNAME)
210210

211211

212212
# List of objects to compile (all goes to libtomcrypt.a)
213+
ifndef AMALGAM
213214
OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_desc.o src/ciphers/aes/aes_enc.o \
214215
src/ciphers/aes/aes_enc_desc.o src/ciphers/aes/aesni.o src/ciphers/anubis.o src/ciphers/blowfish.o \
215216
src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/idea.o src/ciphers/kasumi.o \
@@ -401,6 +402,11 @@ src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
401402
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
402403
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
403404
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o
405+
else
406+
OBJECTS=pre_gen/tomcrypt_amalgam.o
407+
408+
LTC_CFLAGS := $(LTC_CFLAGS) -Wno-shadow -Isrc/ciphers/aes -Isrc/ciphers/safer -Isrc/ciphers/twofish -Isrc/hashes/whirl -Isrc/stream/sober128
409+
endif
404410

405411
# List of test objects to compile (all goes to libtomcrypt_prof.a)
406412
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/bcrypt_test.o \
@@ -537,6 +543,7 @@ zipup: $(call print-help,zipup,Prepare the archives for a release) doc/crypt.pdf
537543
-@(find libtomcrypt-$(VERSION)/ -type f | xargs grep 'FIXM[E]') && echo '############## BEWARE: the "fixme" marker was found !!! ##############' || true
538544
mkdir -p libtomcrypt-$(VERSION)/doc
539545
cp doc/crypt.pdf libtomcrypt-$(VERSION)/doc/crypt.pdf
546+
$(MAKE) -C libtomcrypt-$(VERSION)/ pre_gen
540547
tar -c libtomcrypt-$(VERSION)/ | xz -6e -c - > crypt-$(VERSION).tar.xz
541548
zip -9rq crypt-$(VERSION).zip libtomcrypt-$(VERSION)
542549
rm -rf libtomcrypt-$(VERSION)

src/headers/tomcrypt_private.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "tomcrypt.h"
55
#include <stdarg.h>
66

7+
#ifndef TOMCRYPT_PRIVATE_H_
8+
#define TOMCRYPT_PRIVATE_H_
9+
710
/*
811
* Internal Macros
912
*/
@@ -105,6 +108,11 @@ typedef struct
105108
unsigned long key_bits;
106109
} pbes_arg;
107110

111+
typedef struct {
112+
const pbes_properties *data;
113+
const char *oid;
114+
} oid_to_pbes;
115+
108116
/*
109117
* Internal functions
110118
*/
@@ -692,3 +700,5 @@ int which ## _export(unsigned char *out, unsigned long *outlen, prng_state *prng
692700
#define LTC_WIN32_BCRYPT
693701
#endif
694702
#endif
703+
704+
#endif /* TOMCRYPT_PRIVATE_H_ */

src/misc/pbes/pbes1.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ static const pbes_properties s_pbes1_types[] = {
5050
{ s_pkcs_12_wrap, "sha1", "3des", 24, 8 },
5151
};
5252

53-
typedef struct {
54-
const pbes_properties *data;
55-
const char *oid;
56-
} oid_to_pbes;
57-
5853
static const oid_to_pbes s_pbes1_list[] = {
5954
{ &s_pbes1_types[0], "1.2.840.113549.1.5.1" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.1 pbeWithMD2AndDES-CBC */
6055
{ &s_pbes1_types[1], "1.2.840.113549.1.5.4" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.4 pbeWithMD2AndRC2-CBC */

src/misc/pbes/pbes2.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ static const pbes_properties s_pbes2_default_types[] = {
3939
{ s_pkcs_5_alg2_wrap, "sha1", "aes", 32, 0 },
4040
};
4141

42-
typedef struct {
43-
const pbes_properties *data;
44-
const char* oid;
45-
} oid_to_pbes;
46-
4742
static const oid_to_pbes s_pbes2_list[] = {
4843
{ &s_pbes2_default_types[0], "1.3.14.3.2.7" }, /* http://www.oid-info.com/get/1.3.14.3.2.7 desCBC */
4944
{ &s_pbes2_default_types[1], "1.2.840.113549.3.2" }, /* http://www.oid-info.com/get/1.2.840.113549.3.2 rc2CBC */

0 commit comments

Comments
 (0)