Skip to content

Commit 1f8b8bd

Browse files
Tom St Denissjaeckel
authored andcommitted
added libtomcrypt-0.94
1 parent 53f7f3b commit 1f8b8bd

50 files changed

Lines changed: 3480 additions & 1490 deletions

Some content is hidden

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

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LibTomCrypt is public domain. As should all quality software be.
2+
3+
All of the software was either written by or donated to Tom St Denis for the purposes
4+
of this project. The only exception is the SAFER.C source which has no known
5+
license status (assumed copyrighted) which is why SAFER,C is shipped as disabled.
6+
7+
Tom St Denis

base64.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ int base64_encode(const unsigned char *in, unsigned long len,
4646
unsigned long i, len2, leven;
4747
unsigned char *p;
4848

49-
_ARGCHK(in != NULL);
50-
_ARGCHK(out != NULL);
49+
_ARGCHK(in != NULL);
50+
_ARGCHK(out != NULL);
5151
_ARGCHK(outlen != NULL);
5252

5353
/* valid output size ? */
@@ -58,21 +58,20 @@ int base64_encode(const unsigned char *in, unsigned long len,
5858
p = out;
5959
leven = 3*(len / 3);
6060
for (i = 0; i < leven; i += 3) {
61-
*p++ = codes[in[0] >> 2];
62-
*p++ = codes[((in[0] & 3) << 4) + (in[1] >> 4)];
63-
*p++ = codes[((in[1] & 0xf) << 2) + (in[2] >> 6)];
64-
*p++ = codes[in[2] & 0x3f];
61+
*p++ = codes[(in[0] >> 2) & 0x3F];
62+
*p++ = codes[(((in[0] & 3) << 4) + (in[1] >> 4)) & 0x3F];
63+
*p++ = codes[(((in[1] & 0xf) << 2) + (in[2] >> 6)) & 0x3F];
64+
*p++ = codes[in[2] & 0x3F];
6565
in += 3;
6666
}
6767
/* Pad it if necessary... */
6868
if (i < len) {
6969
unsigned a = in[0];
7070
unsigned b = (i+1 < len) ? in[1] : 0;
71-
unsigned c = 0;
7271

73-
*p++ = codes[a >> 2];
74-
*p++ = codes[((a & 3) << 4) + (b >> 4)];
75-
*p++ = (i+1 < len) ? codes[((b & 0xf) << 2) + (c >> 6)] : '=';
72+
*p++ = codes[(a >> 2) & 0x3F];
73+
*p++ = codes[(((a & 3) << 4) + (b >> 4)) & 0x3F];
74+
*p++ = (i+1 < len) ? codes[(((b & 0xf) << 2)) & 0x3F] : '=';
7675
*p++ = '=';
7776
}
7877

@@ -89,19 +88,22 @@ int base64_decode(const unsigned char *in, unsigned long len,
8988
{
9089
unsigned long t, x, y, z;
9190
unsigned char c;
92-
int g = 3;
91+
int g;
9392

94-
_ARGCHK(in != NULL);
95-
_ARGCHK(out != NULL);
93+
_ARGCHK(in != NULL);
94+
_ARGCHK(out != NULL);
9695
_ARGCHK(outlen != NULL);
9796

97+
g = 3;
9898
for (x = y = z = t = 0; x < len; x++) {
99-
c = map[in[x]];
99+
c = map[in[x]&0xFF];
100100
if (c == 255) continue;
101101
if (c == 254) { c = 0; g--; }
102102
t = (t<<6)|c;
103103
if (++y == 4) {
104-
if (z + g > *outlen) { return CRYPT_BUFFER_OVERFLOW; }
104+
if (z + g > *outlen) {
105+
return CRYPT_BUFFER_OVERFLOW;
106+
}
105107
out[z++] = (unsigned char)((t>>16)&255);
106108
if (g > 1) out[z++] = (unsigned char)((t>>8)&255);
107109
if (g > 2) out[z++] = (unsigned char)(t&255);

changes

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
Feb 20th, 2004
2+
v0.94 -- removed unused variables from ocb.c and fixed it to match known test vectors.
3+
-- Added PMAC support, minor changes to OMAC/EAX code [I think....]
4+
-- Teamed up with Brian Gladman. His code verifies against my vectors and my code
5+
verifies against his test vectors. Hazaa for co-operation!
6+
-- Various small changes (added missing ARGCHKs and cleaned up indentation)
7+
-- Optimization to base64, removed unused variable "c"
8+
-- Added base64 gen to demos/tv_gen.c
9+
-- Fix to demos/x86_prof.c to correctly identify the i386 architecture... weird...
10+
-- Fixed up all of the PK code by adding missing error checking, removed "res" variables,
11+
shrunk some stack variables, removed non-required stack variables and added proper
12+
error conversion from MPI to LTC codes. I also spotted a few "off by one" error
13+
checking which could have been used to force the code to read past the end of
14+
the buffer (in theory, haven't checked if it would work) by a few bytes.
15+
-- Added checks to OUTPUT_BIGNUM so the *_export() functions cannot overflow the output and I
16+
also modded it so it stores in the output provided to the function (that is not on
17+
the local stack) which saves memory and time.
18+
-- Made SAFER default to disabled for now (plans are to cleanhouse write an implementation later)
19+
-- Added the 512-bit one-way hash WHIRLPOOL which clocks in at 138 cycles per byte on my
20+
Athlon XP [for comparison, SHA-512 clocks in at 77 cycles per byte]. This code uses the
21+
teams new sbox design (not the original NESSIE one).
22+
23+
124
Jan 25th, 2004
225
v0.93 -- [note: deleted v0.93 changes by accident... recreating from memory...]
326
-- Fix to RC2 to not deference pointer before ARGCHK

config.pl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"RC5,Include RC5 block cipher,y",
3232
"RC6,Include RC6 block cipher,y",
3333
"SAFERP,Include Safer+ block cipher,y",
34-
"SAFER,Include Safer-64 block ciphers,y",
34+
"SAFER,Include Safer-64 block ciphers,n",
3535
"RIJNDAEL,Include Rijndael (AES) block cipher,y",
3636
"XTEA,Include XTEA block cipher,y",
3737
"TWOFISH,Include Twofish block cipher (default: fast),y",
@@ -49,6 +49,7 @@
4949
"CBC,Include CBC block mode of operation,y",
5050
"CTR,Include CTR block mode of operation,y",
5151

52+
"WHIRLPOOL,Include WHIRLPOOL 512-bit one-way hash,y",
5253
"SHA512,Include SHA512 one-way hash,y",
5354
"SHA384,Include SHA384 one-way hash (requires SHA512),y",
5455
"SHA256,Include SHA256 one-way hash,y",
@@ -62,6 +63,7 @@
6263
"RIPEMD160,Include RIPEMD-160 one-way hash,y",
6364
"HMAC,Include Hash based Message Authentication Support,y",
6465
"OMAC,Include OMAC1 Message Authentication Support,y",
66+
"PMAC,Include PMAC Message Authentication Support,y",
6567
"EAX_MODE,Include EAX Encrypt-and-Authenticate Support,y",
6668
"OCB_MODE,Include OCB Encrypt-and-Authenticate Support,y",
6769

@@ -153,7 +155,7 @@
153155

154156
# output objects
155157
print OUT "\ndefault: library\n\n";
156-
print OUT "OBJECTS = keyring.o gf.o mem.o sprng.o ecc.o base64.o dh.o rsa.o bits.o yarrow.o cfb.o ofb.o ecb.o ctr.o cbc.o hash.o tiger.o sha1.o md5.o md4.o md2.o sha256.o sha512.o xtea.o aes.o des.o safer_tab.o safer.o safer+.o rc4.o rc2.o rc6.o rc5.o cast5.o noekeon.o blowfish.o crypt.o mpi.o prime.o twofish.o packet.o hmac.o strings.o rmd128.o rmd160.o skipjack.o omac.o dsa.o eax.o ocb.o \n\n";
158+
print OUT "OBJECTS = keyring.o gf.o mem.o sprng.o ecc.o base64.o dh.o rsa.o bits.o yarrow.o cfb.o ofb.o ecb.o ctr.o cbc.o hash.o tiger.o sha1.o md5.o md4.o md2.o sha256.o sha512.o xtea.o aes.o des.o safer_tab.o safer.o saferp.o rc4.o rc2.o rc6.o rc5.o cast5.o noekeon.o blowfish.o crypt.o mpi.o prime.o twofish.o packet.o hmac.o strings.o rmd128.o rmd160.o skipjack.o omac.o dsa.o eax.o ocb.o pmac.o whirl.o\n\n";
157159

158160
# some depends
159161
print OUT "rsa.o: rsa_sys.c\ndh.o: dh_sys.c\necc.o: ecc_sys.c\naes.o: aes.c aes_tab.c\ntwofish.o: twofish.c twofish_tab.c\nsha512.o: sha384.c sha512.c\nsha256.o: sha256.c sha224.c\n\n";

crypt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ const char *crypt_build_settings =
566566
#if defined(OMAC)
567567
" OMAC "
568568
#endif
569+
#if defined(PMAC)
570+
" PMAC "
571+
#endif
569572
#if defined(EAX_MODE)
570573
" EAX_MODE "
571574
#endif

crypt.out

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,56 +31,58 @@
3131
\BOOKMARK [1][-]{section.4.1}{Core Functions}{chapter.4}
3232
\BOOKMARK [1][-]{section.4.2}{Hash Descriptors}{chapter.4}
3333
\BOOKMARK [2][-]{subsection.4.2.1}{Notice}{section.4.2}
34-
\BOOKMARK [1][-]{section.4.3}{Hash based Message Authenication Codes}{chapter.4}
35-
\BOOKMARK [1][-]{section.4.4}{OMAC Support}{chapter.4}
36-
\BOOKMARK [0][-]{chapter.5}{Pseudo-Random Number Generators}{}
37-
\BOOKMARK [1][-]{section.5.1}{Core Functions}{chapter.5}
38-
\BOOKMARK [2][-]{subsection.5.1.1}{Remarks}{section.5.1}
39-
\BOOKMARK [2][-]{subsection.5.1.2}{Example}{section.5.1}
40-
\BOOKMARK [1][-]{section.5.2}{PRNG Descriptors}{chapter.5}
41-
\BOOKMARK [1][-]{section.5.3}{The Secure RNG}{chapter.5}
42-
\BOOKMARK [2][-]{subsection.5.3.1}{The Secure PRNG Interface}{section.5.3}
43-
\BOOKMARK [0][-]{chapter.6}{RSA Routines}{}
44-
\BOOKMARK [1][-]{section.6.1}{Background}{chapter.6}
45-
\BOOKMARK [1][-]{section.6.2}{Core Functions}{chapter.6}
46-
\BOOKMARK [1][-]{section.6.3}{Packet Routines}{chapter.6}
47-
\BOOKMARK [1][-]{section.6.4}{Remarks}{chapter.6}
48-
\BOOKMARK [0][-]{chapter.7}{Diffie-Hellman Key Exchange}{}
34+
\BOOKMARK [0][-]{chapter.5}{Message Authentication Codes}{}
35+
\BOOKMARK [1][-]{section.5.1}{HMAC Protocol}{chapter.5}
36+
\BOOKMARK [1][-]{section.5.2}{OMAC Support}{chapter.5}
37+
\BOOKMARK [1][-]{section.5.3}{PMAC Support}{chapter.5}
38+
\BOOKMARK [0][-]{chapter.6}{Pseudo-Random Number Generators}{}
39+
\BOOKMARK [1][-]{section.6.1}{Core Functions}{chapter.6}
40+
\BOOKMARK [2][-]{subsection.6.1.1}{Remarks}{section.6.1}
41+
\BOOKMARK [2][-]{subsection.6.1.2}{Example}{section.6.1}
42+
\BOOKMARK [1][-]{section.6.2}{PRNG Descriptors}{chapter.6}
43+
\BOOKMARK [1][-]{section.6.3}{The Secure RNG}{chapter.6}
44+
\BOOKMARK [2][-]{subsection.6.3.1}{The Secure PRNG Interface}{section.6.3}
45+
\BOOKMARK [0][-]{chapter.7}{RSA Routines}{}
4946
\BOOKMARK [1][-]{section.7.1}{Background}{chapter.7}
5047
\BOOKMARK [1][-]{section.7.2}{Core Functions}{chapter.7}
51-
\BOOKMARK [2][-]{subsection.7.2.1}{Remarks on Usage}{section.7.2}
52-
\BOOKMARK [2][-]{subsection.7.2.2}{Remarks on The Snippet}{section.7.2}
53-
\BOOKMARK [1][-]{section.7.3}{Other Diffie-Hellman Functions}{chapter.7}
54-
\BOOKMARK [1][-]{section.7.4}{DH Packet}{chapter.7}
55-
\BOOKMARK [0][-]{chapter.8}{Elliptic Curve Cryptography}{}
48+
\BOOKMARK [1][-]{section.7.3}{Packet Routines}{chapter.7}
49+
\BOOKMARK [1][-]{section.7.4}{Remarks}{chapter.7}
50+
\BOOKMARK [0][-]{chapter.8}{Diffie-Hellman Key Exchange}{}
5651
\BOOKMARK [1][-]{section.8.1}{Background}{chapter.8}
5752
\BOOKMARK [1][-]{section.8.2}{Core Functions}{chapter.8}
58-
\BOOKMARK [1][-]{section.8.3}{ECC Packet}{chapter.8}
59-
\BOOKMARK [1][-]{section.8.4}{ECC Keysizes}{chapter.8}
60-
\BOOKMARK [0][-]{chapter.9}{Digital Signature Algorithm}{}
61-
\BOOKMARK [1][-]{section.9.1}{Introduction}{chapter.9}
62-
\BOOKMARK [1][-]{section.9.2}{Key Generation}{chapter.9}
63-
\BOOKMARK [1][-]{section.9.3}{Key Verification}{chapter.9}
64-
\BOOKMARK [1][-]{section.9.4}{Signatures}{chapter.9}
65-
\BOOKMARK [1][-]{section.9.5}{Import and Export}{chapter.9}
66-
\BOOKMARK [0][-]{chapter.10}{Public Keyrings}{}
53+
\BOOKMARK [2][-]{subsection.8.2.1}{Remarks on Usage}{section.8.2}
54+
\BOOKMARK [2][-]{subsection.8.2.2}{Remarks on The Snippet}{section.8.2}
55+
\BOOKMARK [1][-]{section.8.3}{Other Diffie-Hellman Functions}{chapter.8}
56+
\BOOKMARK [1][-]{section.8.4}{DH Packet}{chapter.8}
57+
\BOOKMARK [0][-]{chapter.9}{Elliptic Curve Cryptography}{}
58+
\BOOKMARK [1][-]{section.9.1}{Background}{chapter.9}
59+
\BOOKMARK [1][-]{section.9.2}{Core Functions}{chapter.9}
60+
\BOOKMARK [1][-]{section.9.3}{ECC Packet}{chapter.9}
61+
\BOOKMARK [1][-]{section.9.4}{ECC Keysizes}{chapter.9}
62+
\BOOKMARK [0][-]{chapter.10}{Digital Signature Algorithm}{}
6763
\BOOKMARK [1][-]{section.10.1}{Introduction}{chapter.10}
68-
\BOOKMARK [1][-]{section.10.2}{The Keyring API}{chapter.10}
69-
\BOOKMARK [0][-]{chapter.11}{GF\(2w\) Math Routines}{}
70-
\BOOKMARK [0][-]{chapter.12}{Miscellaneous}{}
71-
\BOOKMARK [1][-]{section.12.1}{Base64 Encoding and Decoding}{chapter.12}
72-
\BOOKMARK [1][-]{section.12.2}{The Multiple Precision Integer Library \(MPI\)}{chapter.12}
73-
\BOOKMARK [2][-]{subsection.12.2.1}{Binary Forms of ``mp\137int'' Variables}{section.12.2}
74-
\BOOKMARK [2][-]{subsection.12.2.2}{Primality Testing}{section.12.2}
75-
\BOOKMARK [0][-]{chapter.13}{Programming Guidelines}{}
76-
\BOOKMARK [1][-]{section.13.1}{Secure Pseudo Random Number Generators}{chapter.13}
77-
\BOOKMARK [1][-]{section.13.2}{Preventing Trivial Errors}{chapter.13}
78-
\BOOKMARK [1][-]{section.13.3}{Registering Your Algorithms}{chapter.13}
79-
\BOOKMARK [1][-]{section.13.4}{Key Sizes}{chapter.13}
80-
\BOOKMARK [2][-]{subsection.13.4.1}{Symmetric Ciphers}{section.13.4}
81-
\BOOKMARK [2][-]{subsection.13.4.2}{Assymetric Ciphers}{section.13.4}
82-
\BOOKMARK [1][-]{section.13.5}{Thread Safety}{chapter.13}
83-
\BOOKMARK [0][-]{chapter.14}{Configuring the Library}{}
84-
\BOOKMARK [1][-]{section.14.1}{Introduction}{chapter.14}
85-
\BOOKMARK [1][-]{section.14.2}{mycrypt\137cfg.h}{chapter.14}
86-
\BOOKMARK [1][-]{section.14.3}{The Configure Script}{chapter.14}
64+
\BOOKMARK [1][-]{section.10.2}{Key Generation}{chapter.10}
65+
\BOOKMARK [1][-]{section.10.3}{Key Verification}{chapter.10}
66+
\BOOKMARK [1][-]{section.10.4}{Signatures}{chapter.10}
67+
\BOOKMARK [1][-]{section.10.5}{Import and Export}{chapter.10}
68+
\BOOKMARK [0][-]{chapter.11}{Public Keyrings}{}
69+
\BOOKMARK [1][-]{section.11.1}{Introduction}{chapter.11}
70+
\BOOKMARK [1][-]{section.11.2}{The Keyring API}{chapter.11}
71+
\BOOKMARK [0][-]{chapter.12}{GF\(2w\) Math Routines}{}
72+
\BOOKMARK [0][-]{chapter.13}{Miscellaneous}{}
73+
\BOOKMARK [1][-]{section.13.1}{Base64 Encoding and Decoding}{chapter.13}
74+
\BOOKMARK [1][-]{section.13.2}{The Multiple Precision Integer Library \(MPI\)}{chapter.13}
75+
\BOOKMARK [2][-]{subsection.13.2.1}{Binary Forms of ``mp\137int'' Variables}{section.13.2}
76+
\BOOKMARK [2][-]{subsection.13.2.2}{Primality Testing}{section.13.2}
77+
\BOOKMARK [0][-]{chapter.14}{Programming Guidelines}{}
78+
\BOOKMARK [1][-]{section.14.1}{Secure Pseudo Random Number Generators}{chapter.14}
79+
\BOOKMARK [1][-]{section.14.2}{Preventing Trivial Errors}{chapter.14}
80+
\BOOKMARK [1][-]{section.14.3}{Registering Your Algorithms}{chapter.14}
81+
\BOOKMARK [1][-]{section.14.4}{Key Sizes}{chapter.14}
82+
\BOOKMARK [2][-]{subsection.14.4.1}{Symmetric Ciphers}{section.14.4}
83+
\BOOKMARK [2][-]{subsection.14.4.2}{Assymetric Ciphers}{section.14.4}
84+
\BOOKMARK [1][-]{section.14.5}{Thread Safety}{chapter.14}
85+
\BOOKMARK [0][-]{chapter.15}{Configuring the Library}{}
86+
\BOOKMARK [1][-]{section.15.1}{Introduction}{chapter.15}
87+
\BOOKMARK [1][-]{section.15.2}{mycrypt\137cfg.h}{chapter.15}
88+
\BOOKMARK [1][-]{section.15.3}{The Configure Script}{chapter.15}

crypt.pdf

-39.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)