Skip to content

Commit

Permalink
Merge pull request #234 from libtom/cleanup/3
Browse files Browse the repository at this point in the history
Third general clean-up
  • Loading branch information
sjaeckel committed Jun 22, 2017
2 parents 316450c + 5ce6025 commit 1725b87
Show file tree
Hide file tree
Showing 61 changed files with 214 additions and 408 deletions.
7 changes: 6 additions & 1 deletion doc/crypt.tex
Expand Up @@ -83,7 +83,6 @@


\begin{tabular}{c}
Tom St Denis \\
LibTom Projects
\end{tabular}
\end{center}
Expand All @@ -98,6 +97,12 @@
~

\begin{flushright}
LibTom Projects
~

\& originally
~

Tom St Denis
~

Expand Down
9 changes: 9 additions & 0 deletions helper.pl
Expand Up @@ -50,10 +50,19 @@ sub check_source {
push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bfree\s*\(/;
push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemset\s*\(/;
push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcpy\s*\(/;
push @{$troubles->{unwanted_memmove}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemmove\s*\(/;
push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcmp\s*\(/;
push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrcmp\s*\(/;
push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bclock\s*\(/;
push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bqsort\s*\(/;
if ($file =~ m|src/.*\.c$| &&
$file !~ m|src/ciphers/.*\.c$| &&
$file !~ m|src/hashes/.*\.c$| &&
$file !~ m|src/math/.+_desc.c$| &&
$file !~ m|src/stream/sober128/sober128.c$| &&
$l =~ /^static\s+\S+\s+([^_][a-zA-Z0-9_]+)\s*\(/) {
push @{$troubles->{staticfunc_name}}, "$lineno($1)";
}
$lineno++;
}
for my $k (sort keys %$troubles) {
Expand Down
4 changes: 2 additions & 2 deletions makefile.shared
Expand Up @@ -47,8 +47,8 @@ $(LIBNAME): $(OBJECTS)

install: .common_install
sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > libtomcrypt.pc
install -d $(LIBPATH)/pkgconfig
install -m 644 libtomcrypt.pc $(LIBPATH)/pkgconfig/
install -d $(DESTDIR)/$(LIBPATH)/pkgconfig
install -m 644 libtomcrypt.pc $(DESTDIR)/$(LIBPATH)/pkgconfig/

install_bins: .common_install_bins

Expand Down
24 changes: 12 additions & 12 deletions makefile.unix
Expand Up @@ -25,10 +25,10 @@
#The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs"
DESTDIR =
PREFIX = /usr/local
LIBPATH = $(DESTDIR)$(PREFIX)/lib
INCPATH = $(DESTDIR)$(PREFIX)/include
DATAPATH = $(DESTDIR)$(PREFIX)/share/doc/libtomcrypt/pdf
BINPATH = $(DESTDIR)$(PREFIX)/bin
LIBPATH = $(PREFIX)/lib
INCPATH = $(PREFIX)/include
DATAPATH = $(PREFIX)/share/doc/libtomcrypt/pdf
BINPATH = $(PREFIX)/bin
CC = cc
AR = ar
ARFLAGS = r
Expand Down Expand Up @@ -272,17 +272,17 @@ clean:

#Install the library + headers
install: $(LIBMAIN_S) $(HEADERS)
@mkdir -p $(INCPATH) $(LIBPATH)/pkgconfig
@cp $(LIBMAIN_S) $(LIBPATH)/
@cp $(HEADERS) $(INCPATH)/
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(LIBPATH)/pkgconfig/libtomcrypt.pc
@mkdir -p $(DESTDIR)/$(INCPATH) $(DESTDIR)/$(LIBPATH)/pkgconfig
@cp $(LIBMAIN_S) $(DESTDIR)/$(LIBPATH)/
@cp $(HEADERS) $(DESTDIR)/$(INCPATH)/
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(DESTDIR)/$(LIBPATH)/pkgconfig/libtomcrypt.pc

#Install useful tools
install_bins: hashsum
@mkdir -p $(BINPATH)
@cp hashsum $(BINPATH)/
@mkdir -p $(DESTDIR)/$(BINPATH)
@cp hashsum $(DESTDIR)/$(BINPATH)/

#Install documentation
install_docs: doc/crypt.pdf
@mkdir -p $(DATAPATH)
@cp doc/crypt.pdf $(DATAPATH)/
@mkdir -p $(DESTDIR)/$(DATAPATH)
@cp doc/crypt.pdf $(DESTDIR)/$(DATAPATH)/
20 changes: 10 additions & 10 deletions makefile_include.mk
Expand Up @@ -132,10 +132,10 @@ TIMINGS=demos/timing.o
#BINPATH The directory to install the binaries provided.
DESTDIR ?=
PREFIX ?= /usr/local
LIBPATH ?= $(DESTDIR)$(PREFIX)/lib
INCPATH ?= $(DESTDIR)$(PREFIX)/include
DATAPATH ?= $(DESTDIR)$(PREFIX)/share/doc/libtomcrypt/pdf
BINPATH ?= $(DESTDIR)$(PREFIX)/bin
LIBPATH ?= $(PREFIX)/lib
INCPATH ?= $(PREFIX)/include
DATAPATH ?= $(PREFIX)/share/doc/libtomcrypt/pdf
BINPATH ?= $(PREFIX)/bin

#Who do we install as?
ifdef INSTALL_USER
Expand Down Expand Up @@ -362,18 +362,18 @@ install_all: install install_bins install_docs install_test
INSTALL_OPTS ?= -m 644

.common_install: $(LIBNAME)
install -d $(INCPATH)
install -d $(LIBPATH)
$(INSTALL_CMD) $(INSTALL_OPTS) $(LIBNAME) $(LIBPATH)/$(LIBNAME)
install -m 644 $(HEADERS) $(INCPATH)
install -d $(DESTDIR)/$(INCPATH)
install -d $(DESTDIR)/$(LIBPATH)
$(INSTALL_CMD) $(INSTALL_OPTS) $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(LIBNAME)
install -m 644 $(HEADERS) $(DESTDIR)/$(INCPATH)

.common_install_bins: $(USEFUL_DEMOS)
install -d $(BINPATH)
$(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(BINPATH)
$(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(DESTDIR)/$(BINPATH)

install_docs: doc/crypt.pdf
install -d $(DATAPATH)
install -m 644 doc/crypt.pdf $(DATAPATH)
install -m 644 doc/crypt.pdf $(DESTDIR)/$(DATAPATH)

install_hooks:
for s in `ls hooks/`; do ln -s ../../hooks/$$s .git/hooks/$$s; done
Expand Down
19 changes: 2 additions & 17 deletions src/ciphers/aes/aes.c
Expand Up @@ -685,23 +685,8 @@ int ECB_TEST(void)

rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key);
rijndael_ecb_decrypt(tmp[0], tmp[1], &key);
if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
#if 0
printf("\n\nTest %d failed\n", i);
if (XMEMCMP(tmp[0], tests[i].ct, 16)) {
printf("CT: ");
for (i = 0; i < 16; i++) {
printf("%02x ", tmp[0][i]);
}
printf("\n");
} else {
printf("PT: ");
for (i = 0; i < 16; i++) {
printf("%02x ", tmp[1][i]);
}
printf("\n");
}
#endif
if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "AES Encrypt", i) ||
compare_testvector(tmp[1], 16, tests[i].pt, 16, "AES Decrypt", i)) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
5 changes: 3 additions & 2 deletions src/ciphers/anubis.c
Expand Up @@ -1498,13 +1498,14 @@ int anubis_test(void)
anubis_setup(tests[x].key, tests[x].keylen, 0, &skey);
anubis_ecb_encrypt(tests[x].pt, buf[0], &skey);
anubis_ecb_decrypt(buf[0], buf[1], &skey);
if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) {
if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis Encrypt", x) ||
compare_testvector(buf[1], 16, tests[x].pt, 16, "Anubis Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}

for (y = 0; y < 1000; y++) anubis_ecb_encrypt(buf[0], buf[0], &skey);
for (y = 0; y < 1000; y++) anubis_ecb_decrypt(buf[0], buf[0], &skey);
if (XMEMCMP(buf[0], tests[x].ct, 16)) {
if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis 1000", 1000)) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/blowfish.c
Expand Up @@ -546,7 +546,8 @@ int blowfish_test(void)
blowfish_ecb_decrypt(tmp[0], tmp[1], &key);

/* compare */
if ((XMEMCMP(tmp[0], tests[x].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[x].pt, 8) != 0)) {
if ((compare_testvector(tmp[0], 8, tests[x].ct, 8, "Blowfish Encrypt", x) != 0) ||
(compare_testvector(tmp[1], 8, tests[x].pt, 8, "Blowfish Decrypt", x) != 0)) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
18 changes: 2 additions & 16 deletions src/ciphers/camellia.c
Expand Up @@ -697,22 +697,8 @@ int camellia_test(void)
return err;
}
camellia_done(&skey);
if (XMEMCMP(tests[x].ct, buf[0], 16) || XMEMCMP(tests[x].pt, buf[1], 16)) {
#if 0
int i, j;
printf ("\n\nLTC_CAMELLIA failed for x=%d, I got:\n", x);
for (i = 0; i < 2; i++) {
const unsigned char *expected, *actual;
expected = (i ? tests[x].pt : tests[x].ct);
actual = buf[i];
printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext"));
for (j = 0; j < 16; j++) {
const char *eq = (expected[j] == actual[j] ? "==" : "!=");
printf (" %02x %s %02x\n", expected[j], eq, actual[j]);
}
printf ("\n");
}
#endif
if (compare_testvector(tests[x].ct, 16, buf[0], 16, "Camellia Encrypt", x) ||
compare_testvector(tests[x].pt, 16, buf[1], 16, "Camellia Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/cast5.c
Expand Up @@ -674,7 +674,8 @@ int cast5_test(void)
}
cast5_ecb_encrypt(tests[i].pt, tmp[0], &key);
cast5_ecb_decrypt(tmp[0], tmp[1], &key);
if ((XMEMCMP(tmp[0], tests[i].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[i].pt, 8) != 0)) {
if ((compare_testvector(tmp[0], 8, tests[i].ct, 8, "CAST5 Encrypt", i) != 0) ||
(compare_testvector(tmp[1], 8, tests[i].pt, 8, "CAST5 Decrypt", i) != 0)) {
return CRYPT_FAIL_TESTVECTOR;
}
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
Expand Down
4 changes: 2 additions & 2 deletions src/ciphers/des.c
Expand Up @@ -1977,7 +1977,7 @@ int des_test(void)
des_ecb_decrypt(cases[i].txt, tmp, &des);
}

if (XMEMCMP(cases[i].out, tmp, sizeof(tmp)) != 0) {
if (compare_testvector(cases[i].out, sizeof(tmp), tmp, sizeof(tmp), "DES", i) != 0) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down Expand Up @@ -2020,7 +2020,7 @@ int des3_test(void)
des3_ecb_encrypt(pt, ct, &skey);
des3_ecb_decrypt(ct, tmp, &skey);

if (XMEMCMP(pt, tmp, 8) != 0) {
if (compare_testvector(pt, 8, tmp, 8, "3DES", 0) != 0) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/kasumi.c
Expand Up @@ -302,7 +302,8 @@ int kasumi_test(void)
if ((err = kasumi_ecb_decrypt(tests[x].ct, buf[1], &key)) != CRYPT_OK) {
return err;
}
if (XMEMCMP(tests[x].pt, buf[1], 8) || XMEMCMP(tests[x].ct, buf[0], 8)) {
if (compare_testvector(buf[1], 8, tests[x].pt, 8, "Kasumi Decrypt", x) ||
compare_testvector(buf[0], 8, tests[x].ct, 8, "Kasumi Encrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ciphers/khazad.c
Expand Up @@ -808,13 +808,14 @@ int khazad_test(void)
khazad_setup(tests[x].key, 16, 0, &skey);
khazad_ecb_encrypt(tests[x].pt, buf[0], &skey);
khazad_ecb_decrypt(buf[0], buf[1], &skey);
if (XMEMCMP(buf[0], tests[x].ct, 8) || XMEMCMP(buf[1], tests[x].pt, 8)) {
if (compare_testvector(buf[0], 8, tests[x].ct, 8, "Khazad Encrypt", x) ||
compare_testvector(buf[1], 8, tests[x].pt, 8, "Khazad Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}

for (y = 0; y < 1000; y++) khazad_ecb_encrypt(buf[0], buf[0], &skey);
for (y = 0; y < 1000; y++) khazad_ecb_decrypt(buf[0], buf[0], &skey);
if (XMEMCMP(buf[0], tests[x].ct, 8)) {
if (compare_testvector(buf[0], 8, tests[x].ct, 8, "Khazad 1000", 1000)) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
18 changes: 2 additions & 16 deletions src/ciphers/kseed.c
Expand Up @@ -344,22 +344,8 @@ int kseed_test(void)
kseed_setup(tests[x].key, 16, 0, &skey);
kseed_ecb_encrypt(tests[x].pt, buf[0], &skey);
kseed_ecb_decrypt(buf[0], buf[1], &skey);
if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) {
#if 0
int i, j;
printf ("\n\nLTC_KSEED failed for x=%d, I got:\n", x);
for (i = 0; i < 2; i++) {
const unsigned char *expected, *actual;
expected = (i ? tests[x].pt : tests[x].ct);
actual = buf[i];
printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext"));
for (j = 0; j < 16; j++) {
const char *eq = (expected[j] == actual[j] ? "==" : "!=");
printf (" %02x %s %02x\n", expected[j], eq, actual[j]);
}
printf ("\n");
}
#endif
if (compare_testvector(buf[0], 16, tests[x].ct, 16, "KSEED Encrypt", x) ||
compare_testvector(buf[1], 16, tests[x].pt, 16, "KSEED Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ciphers/multi2.c
Expand Up @@ -256,14 +256,14 @@ int multi2_test(void)
return err;
}

if (XMEMCMP(buf, tests[x].ct, 8)) {
if (compare_testvector(buf, 8, tests[x].ct, 8, "Multi2 Encrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}

if ((err = multi2_ecb_decrypt(buf, buf, &skey)) != CRYPT_OK) {
return err;
}
if (XMEMCMP(buf, tests[x].pt, 8)) {
if (compare_testvector(buf, 8, tests[x].pt, 8, "Multi2 Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
Expand All @@ -280,7 +280,7 @@ int multi2_test(void)
if ((err = multi2_ecb_decrypt(ct, buf, &skey)) != CRYPT_OK) {
return err;
}
if (XMEMCMP(buf, tests[0].pt, 8)) {
if (compare_testvector(buf, 8, tests[0].pt, 8, "Multi2 Rounds", x)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
Expand Down
19 changes: 2 additions & 17 deletions src/ciphers/noekeon.c
Expand Up @@ -281,23 +281,8 @@ int noekeon_test(void)

noekeon_ecb_encrypt(tests[i].pt, tmp[0], &key);
noekeon_ecb_decrypt(tmp[0], tmp[1], &key);
if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
#if 0
printf("\n\nTest %d failed\n", i);
if (XMEMCMP(tmp[0], tests[i].ct, 16)) {
printf("CT: ");
for (i = 0; i < 16; i++) {
printf("%02x ", tmp[0][i]);
}
printf("\n");
} else {
printf("PT: ");
for (i = 0; i < 16; i++) {
printf("%02x ", tmp[1][i]);
}
printf("\n");
}
#endif
if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "Noekeon Encrypt", i) ||
compare_testvector(tmp[1], 16, tests[i].pt, 16, "Noekeon Decrypt", i)) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ciphers/rc5.c
Expand Up @@ -273,7 +273,8 @@ int rc5_test(void)
rc5_ecb_decrypt(tmp[0], tmp[1], &key);

/* compare */
if (XMEMCMP(tmp[0], tests[x].ct, 8) != 0 || XMEMCMP(tmp[1], tests[x].pt, 8) != 0) {
if (compare_testvector(tmp[0], 8, tests[x].ct, 8, "RC5 Encrypt", x) != 0 ||
compare_testvector(tmp[1], 8, tests[x].pt, 8, "RC5 Decrypt", x) != 0) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down
20 changes: 2 additions & 18 deletions src/ciphers/rc6.c
Expand Up @@ -283,24 +283,8 @@ int rc6_test(void)
rc6_ecb_decrypt(tmp[0], tmp[1], &key);

/* compare */
if (XMEMCMP(tmp[0], tests[x].ct, 16) || XMEMCMP(tmp[1], tests[x].pt, 16)) {
#if 0
printf("\n\nFailed test %d\n", x);
if (XMEMCMP(tmp[0], tests[x].ct, 16)) {
printf("Ciphertext: ");
for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]);
printf("\nExpected : ");
for (y = 0; y < 16; y++) printf("%02x ", tests[x].ct[y]);
printf("\n");
}
if (XMEMCMP(tmp[1], tests[x].pt, 16)) {
printf("Plaintext: ");
for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]);
printf("\nExpected : ");
for (y = 0; y < 16; y++) printf("%02x ", tests[x].pt[y]);
printf("\n");
}
#endif
if (compare_testvector(tmp[0], 16, tests[x].ct, 16, "RC6 Encrypt", x) ||
compare_testvector(tmp[1], 16, tests[x].pt, 16, "RC6 Decrypt", x)) {
return CRYPT_FAIL_TESTVECTOR;
}

Expand Down

0 comments on commit 1725b87

Please sign in to comment.