Skip to content

Commit 1725b87

Browse files
authored
Merge pull request #234 from libtom/cleanup/3
Third general clean-up
2 parents 316450c + 5ce6025 commit 1725b87

61 files changed

Lines changed: 214 additions & 408 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/crypt.tex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383

8484

8585
\begin{tabular}{c}
86-
Tom St Denis \\
8786
LibTom Projects
8887
\end{tabular}
8988
\end{center}
@@ -98,6 +97,12 @@
9897
~
9998

10099
\begin{flushright}
100+
LibTom Projects
101+
~
102+
103+
\& originally
104+
~
105+
101106
Tom St Denis
102107
~
103108

helper.pl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ sub check_source {
5050
push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bfree\s*\(/;
5151
push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemset\s*\(/;
5252
push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcpy\s*\(/;
53+
push @{$troubles->{unwanted_memmove}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemmove\s*\(/;
5354
push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcmp\s*\(/;
5455
push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrcmp\s*\(/;
5556
push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bclock\s*\(/;
5657
push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bqsort\s*\(/;
58+
if ($file =~ m|src/.*\.c$| &&
59+
$file !~ m|src/ciphers/.*\.c$| &&
60+
$file !~ m|src/hashes/.*\.c$| &&
61+
$file !~ m|src/math/.+_desc.c$| &&
62+
$file !~ m|src/stream/sober128/sober128.c$| &&
63+
$l =~ /^static\s+\S+\s+([^_][a-zA-Z0-9_]+)\s*\(/) {
64+
push @{$troubles->{staticfunc_name}}, "$lineno($1)";
65+
}
5766
$lineno++;
5867
}
5968
for my $k (sort keys %$troubles) {

makefile.shared

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ $(LIBNAME): $(OBJECTS)
4747

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

5353
install_bins: .common_install_bins
5454

makefile.unix

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs"
2626
DESTDIR =
2727
PREFIX = /usr/local
28-
LIBPATH = $(DESTDIR)$(PREFIX)/lib
29-
INCPATH = $(DESTDIR)$(PREFIX)/include
30-
DATAPATH = $(DESTDIR)$(PREFIX)/share/doc/libtomcrypt/pdf
31-
BINPATH = $(DESTDIR)$(PREFIX)/bin
28+
LIBPATH = $(PREFIX)/lib
29+
INCPATH = $(PREFIX)/include
30+
DATAPATH = $(PREFIX)/share/doc/libtomcrypt/pdf
31+
BINPATH = $(PREFIX)/bin
3232
CC = cc
3333
AR = ar
3434
ARFLAGS = r
@@ -272,17 +272,17 @@ clean:
272272

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

280280
#Install useful tools
281281
install_bins: hashsum
282-
@mkdir -p $(BINPATH)
283-
@cp hashsum $(BINPATH)/
282+
@mkdir -p $(DESTDIR)/$(BINPATH)
283+
@cp hashsum $(DESTDIR)/$(BINPATH)/
284284

285285
#Install documentation
286286
install_docs: doc/crypt.pdf
287-
@mkdir -p $(DATAPATH)
288-
@cp doc/crypt.pdf $(DATAPATH)/
287+
@mkdir -p $(DESTDIR)/$(DATAPATH)
288+
@cp doc/crypt.pdf $(DESTDIR)/$(DATAPATH)/

makefile_include.mk

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ TIMINGS=demos/timing.o
132132
#BINPATH The directory to install the binaries provided.
133133
DESTDIR ?=
134134
PREFIX ?= /usr/local
135-
LIBPATH ?= $(DESTDIR)$(PREFIX)/lib
136-
INCPATH ?= $(DESTDIR)$(PREFIX)/include
137-
DATAPATH ?= $(DESTDIR)$(PREFIX)/share/doc/libtomcrypt/pdf
138-
BINPATH ?= $(DESTDIR)$(PREFIX)/bin
135+
LIBPATH ?= $(PREFIX)/lib
136+
INCPATH ?= $(PREFIX)/include
137+
DATAPATH ?= $(PREFIX)/share/doc/libtomcrypt/pdf
138+
BINPATH ?= $(PREFIX)/bin
139139

140140
#Who do we install as?
141141
ifdef INSTALL_USER
@@ -362,18 +362,18 @@ install_all: install install_bins install_docs install_test
362362
INSTALL_OPTS ?= -m 644
363363

364364
.common_install: $(LIBNAME)
365-
install -d $(INCPATH)
366-
install -d $(LIBPATH)
367-
$(INSTALL_CMD) $(INSTALL_OPTS) $(LIBNAME) $(LIBPATH)/$(LIBNAME)
368-
install -m 644 $(HEADERS) $(INCPATH)
365+
install -d $(DESTDIR)/$(INCPATH)
366+
install -d $(DESTDIR)/$(LIBPATH)
367+
$(INSTALL_CMD) $(INSTALL_OPTS) $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(LIBNAME)
368+
install -m 644 $(HEADERS) $(DESTDIR)/$(INCPATH)
369369

370370
.common_install_bins: $(USEFUL_DEMOS)
371371
install -d $(BINPATH)
372-
$(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(BINPATH)
372+
$(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(DESTDIR)/$(BINPATH)
373373

374374
install_docs: doc/crypt.pdf
375375
install -d $(DATAPATH)
376-
install -m 644 doc/crypt.pdf $(DATAPATH)
376+
install -m 644 doc/crypt.pdf $(DESTDIR)/$(DATAPATH)
377377

378378
install_hooks:
379379
for s in `ls hooks/`; do ln -s ../../hooks/$$s .git/hooks/$$s; done

src/ciphers/aes/aes.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -685,23 +685,8 @@ int ECB_TEST(void)
685685

686686
rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key);
687687
rijndael_ecb_decrypt(tmp[0], tmp[1], &key);
688-
if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
689-
#if 0
690-
printf("\n\nTest %d failed\n", i);
691-
if (XMEMCMP(tmp[0], tests[i].ct, 16)) {
692-
printf("CT: ");
693-
for (i = 0; i < 16; i++) {
694-
printf("%02x ", tmp[0][i]);
695-
}
696-
printf("\n");
697-
} else {
698-
printf("PT: ");
699-
for (i = 0; i < 16; i++) {
700-
printf("%02x ", tmp[1][i]);
701-
}
702-
printf("\n");
703-
}
704-
#endif
688+
if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "AES Encrypt", i) ||
689+
compare_testvector(tmp[1], 16, tests[i].pt, 16, "AES Decrypt", i)) {
705690
return CRYPT_FAIL_TESTVECTOR;
706691
}
707692

src/ciphers/anubis.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,13 +1498,14 @@ int anubis_test(void)
14981498
anubis_setup(tests[x].key, tests[x].keylen, 0, &skey);
14991499
anubis_ecb_encrypt(tests[x].pt, buf[0], &skey);
15001500
anubis_ecb_decrypt(buf[0], buf[1], &skey);
1501-
if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) {
1501+
if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis Encrypt", x) ||
1502+
compare_testvector(buf[1], 16, tests[x].pt, 16, "Anubis Decrypt", x)) {
15021503
return CRYPT_FAIL_TESTVECTOR;
15031504
}
15041505

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

src/ciphers/blowfish.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ int blowfish_test(void)
546546
blowfish_ecb_decrypt(tmp[0], tmp[1], &key);
547547

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

src/ciphers/camellia.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -697,22 +697,8 @@ int camellia_test(void)
697697
return err;
698698
}
699699
camellia_done(&skey);
700-
if (XMEMCMP(tests[x].ct, buf[0], 16) || XMEMCMP(tests[x].pt, buf[1], 16)) {
701-
#if 0
702-
int i, j;
703-
printf ("\n\nLTC_CAMELLIA failed for x=%d, I got:\n", x);
704-
for (i = 0; i < 2; i++) {
705-
const unsigned char *expected, *actual;
706-
expected = (i ? tests[x].pt : tests[x].ct);
707-
actual = buf[i];
708-
printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext"));
709-
for (j = 0; j < 16; j++) {
710-
const char *eq = (expected[j] == actual[j] ? "==" : "!=");
711-
printf (" %02x %s %02x\n", expected[j], eq, actual[j]);
712-
}
713-
printf ("\n");
714-
}
715-
#endif
700+
if (compare_testvector(tests[x].ct, 16, buf[0], 16, "Camellia Encrypt", x) ||
701+
compare_testvector(tests[x].pt, 16, buf[1], 16, "Camellia Decrypt", x)) {
716702
return CRYPT_FAIL_TESTVECTOR;
717703
}
718704
}

src/ciphers/cast5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,8 @@ int cast5_test(void)
674674
}
675675
cast5_ecb_encrypt(tests[i].pt, tmp[0], &key);
676676
cast5_ecb_decrypt(tmp[0], tmp[1], &key);
677-
if ((XMEMCMP(tmp[0], tests[i].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[i].pt, 8) != 0)) {
677+
if ((compare_testvector(tmp[0], 8, tests[i].ct, 8, "CAST5 Encrypt", i) != 0) ||
678+
(compare_testvector(tmp[1], 8, tests[i].pt, 8, "CAST5 Decrypt", i) != 0)) {
678679
return CRYPT_FAIL_TESTVECTOR;
679680
}
680681
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */

0 commit comments

Comments
 (0)