Skip to content

Commit a21f63b

Browse files
Tom St Denissjaeckel
authored andcommitted
added libtomcrypt-0.97b
1 parent e9c1c53 commit a21f63b

41 files changed

Lines changed: 1191 additions & 325 deletions

Some content is hidden

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

aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ static ulong32 setup_mix(ulong32 temp)
8989
}
9090

9191
#ifndef ENCRYPT_ONLY
92-
92+
#ifdef SMALL_CODE
9393
static ulong32 setup_mix2(ulong32 temp)
9494
{
9595
return Td0(255 & Te4[byte(temp, 3)]) ^
9696
Td1(255 & Te4[byte(temp, 2)]) ^
9797
Td2(255 & Te4[byte(temp, 1)]) ^
9898
Td3(255 & Te4[byte(temp, 0)]);
9999
}
100-
100+
#endif
101101
#endif
102102

103103
int SETUP(const unsigned char *key, int keylen, int rounds, symmetric_key *skey)

changes

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
July 23rd, 2004
2+
v0.97b -- Added PKCS #1 v1.5 RSA encrypt/sign helpers (like rsa_sign_hash, etc...)
3+
-- Added missing prng check to rsa_decrypt_key() [not critical as I don't use
4+
descriptors directly in that function]
5+
-- Merged in LTM-SSE, define LTMSSE before you build and you will get SSE2 optimized math ;-)
6+
(roughly 3x faster on a P4 Northwood). By default it will compile as ISO C portable
7+
code (when LTMSSE is undefined).
8+
-- Fixed bug in ltc_tommath.h where I had the kara/toom cutoffs not marked as ``extern''
9+
Thanks to "Stefan Arentz" <stefan at organicnetwork.net>
10+
-- Steven Dake <scd@broked.org> and Richard Amacker <ramacker@yahoo.com> submitted patches to
11+
fix pkcs_5_2(). It now matches the output of another crypto library. Whoops... hehehe
12+
-- Updated PRNG api. Added Fortuna PRNG to the list of supported PRNGs
13+
-- Fixed up the descriptor tables since globals are automatically zero'ed on startup.
14+
-- Changed RC4 to store it's output. If you want to encrypt with RC4
15+
you'll have to do the XOR yourself.
16+
-- Fixed buffer overflows/overruns in the HMAC code.
17+
18+
++ API change for the PRNGs there now is a done() function per PRNG. You
19+
should call it when you are done with a prng state. So far it's
20+
not absolutely required (won't cause problems) but is a good idea to
21+
start.
22+
23+
124
June 23rd, 2004
225
v0.97a ++ Fixed several potentially crippling bugs... [read on]
326
-- Fixed bug in OAEP decoder that would incorrectly report

crypt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ const char *crypt_build_settings =
229229
#endif
230230
#if defined(NO_FILE)
231231
" NO_FILE "
232-
#endif
233-
#if defined(LTC_TEST)
234-
" LTC_TEST "
235232
#endif
236233
"\n"
237234
"\n\n\n"

crypt.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
\def\gap{\vspace{0.5ex}}
4848
\makeindex
4949
\begin{document}
50-
\title{LibTomCrypt \\ Version 0.97a}
50+
\title{LibTomCrypt \\ Version 0.97b}
5151
\author{Tom St Denis \\
5252
\\
5353
tomstdenis@iahu.ca \\

crypt_cipher_descriptor.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,5 @@
1010
*/
1111
#include "mycrypt.h"
1212

13-
struct _cipher_descriptor cipher_descriptor[TAB_SIZE] = {
14-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
15-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
16-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
17-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
18-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
19-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
20-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
21-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
22-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
23-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
24-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
25-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
26-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
27-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
28-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
29-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
30-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
31-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
32-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
33-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
34-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
35-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
36-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
37-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
38-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
39-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
40-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
41-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
42-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
43-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
44-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
45-
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } };
13+
struct _cipher_descriptor cipher_descriptor[TAB_SIZE];
4614

crypt_hash_descriptor.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,5 @@
1010
*/
1111
#include "mycrypt.h"
1212

13-
struct _hash_descriptor hash_descriptor[TAB_SIZE] = {
14-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
15-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
16-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
17-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
18-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
19-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
20-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
21-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
22-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
23-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
24-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
25-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
26-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
27-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
28-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
29-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
30-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
31-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
32-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
33-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
34-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
35-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
36-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
37-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
38-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
39-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
40-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
41-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
42-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
43-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
44-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
45-
{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL } };
13+
struct _hash_descriptor hash_descriptor[TAB_SIZE];
14+

crypt_prng_descriptor.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,4 @@
1010
*/
1111
#include "mycrypt.h"
1212

13-
struct _prng_descriptor prng_descriptor[TAB_SIZE] = {
14-
{ NULL, NULL, NULL, NULL, NULL },
15-
{ NULL, NULL, NULL, NULL, NULL },
16-
{ NULL, NULL, NULL, NULL, NULL },
17-
{ NULL, NULL, NULL, NULL, NULL },
18-
{ NULL, NULL, NULL, NULL, NULL },
19-
{ NULL, NULL, NULL, NULL, NULL },
20-
{ NULL, NULL, NULL, NULL, NULL },
21-
{ NULL, NULL, NULL, NULL, NULL },
22-
{ NULL, NULL, NULL, NULL, NULL },
23-
{ NULL, NULL, NULL, NULL, NULL },
24-
{ NULL, NULL, NULL, NULL, NULL },
25-
{ NULL, NULL, NULL, NULL, NULL },
26-
{ NULL, NULL, NULL, NULL, NULL },
27-
{ NULL, NULL, NULL, NULL, NULL },
28-
{ NULL, NULL, NULL, NULL, NULL },
29-
{ NULL, NULL, NULL, NULL, NULL },
30-
{ NULL, NULL, NULL, NULL, NULL },
31-
{ NULL, NULL, NULL, NULL, NULL },
32-
{ NULL, NULL, NULL, NULL, NULL },
33-
{ NULL, NULL, NULL, NULL, NULL },
34-
{ NULL, NULL, NULL, NULL, NULL },
35-
{ NULL, NULL, NULL, NULL, NULL },
36-
{ NULL, NULL, NULL, NULL, NULL },
37-
{ NULL, NULL, NULL, NULL, NULL },
38-
{ NULL, NULL, NULL, NULL, NULL },
39-
{ NULL, NULL, NULL, NULL, NULL },
40-
{ NULL, NULL, NULL, NULL, NULL },
41-
{ NULL, NULL, NULL, NULL, NULL },
42-
{ NULL, NULL, NULL, NULL, NULL },
43-
{ NULL, NULL, NULL, NULL, NULL },
44-
{ NULL, NULL, NULL, NULL, NULL },
45-
{ NULL, NULL, NULL, NULL, NULL } };
46-
13+
struct _prng_descriptor prng_descriptor[TAB_SIZE];

demos/test/rsa_test.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,35 @@ int rsa_test(void)
2121
/* make a random key */
2222
DO(rsa_make_key(&test_yarrow, prng_idx, 1024/8, 65537, &key));
2323

24+
/* test PKCS #1 v1.5 */
25+
for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) {
26+
/* make a random key/msg */
27+
yarrow_read(in, rsa_msgsize, &test_yarrow);
28+
29+
len = sizeof(out);
30+
len2 = rsa_msgsize;
31+
32+
/* encrypt */
33+
DO(rsa_v15_encrypt_key(in, rsa_msgsize, out, &len, &test_yarrow, prng_idx, &key));
34+
DO(rsa_v15_decrypt_key(out, len, tmp, rsa_msgsize, &test_yarrow, prng_idx, &stat, &key));
35+
if (stat != 1 || memcmp(tmp, in, rsa_msgsize)) {
36+
printf("PKCS #1 v1.5 encrypt/decrypt failure (rsa_msgsize: %lu, stat: %d)\n", rsa_msgsize, stat);
37+
return 1;
38+
}
39+
}
40+
41+
/* signature */
42+
len = sizeof(out);
43+
DO(rsa_v15_sign_hash(in, 20, out, &len, &test_yarrow, prng_idx, hash_idx, &key));
44+
in[1] ^= 1;
45+
DO(rsa_v15_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, &stat, &key));
46+
in[1] ^= 1;
47+
DO(rsa_v15_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, &stat2, &key));
48+
if (!(stat == 0 && stat2 == 1)) {
49+
printf("PKCS #1 v1.5 sign/verify failure (stat %d, stat2 %d)\n", stat, stat2);
50+
return 1;
51+
}
52+
2453
/* encrypt the key (without lparam) */
2554
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
2655
/* make a random key/msg */
@@ -47,7 +76,7 @@ int rsa_test(void)
4776
return 1;
4877
}
4978
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
50-
int x;
79+
unsigned long x;
5180
printf("\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
5281
printf("Original contents: \n");
5382
for (x = 0; x < rsa_msgsize; ) {

demos/tv_gen.c

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,50 @@ void reg_algs(void)
8686

8787
void hash_gen(void)
8888
{
89-
unsigned char md[MAXBLOCKSIZE], buf[MAXBLOCKSIZE*2+2];
89+
unsigned char md[MAXBLOCKSIZE], *buf;
9090
unsigned long outlen, x, y, z;
9191
FILE *out;
92+
int err;
9293

9394
out = fopen("hash_tv.txt", "w");
95+
if (out == NULL) {
96+
perror("can't open hash_tv");
97+
}
9498

9599
fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n");
96100
for (x = 0; hash_descriptor[x].name != NULL; x++) {
101+
buf = XMALLOC(2 * hash_descriptor[x].blocksize);
102+
if (buf == NULL) {
103+
perror("can't alloc mem");
104+
exit(EXIT_FAILURE);
105+
}
97106
fprintf(out, "Hash: %s\n", hash_descriptor[x].name);
98-
99107
for (y = 0; y <= (hash_descriptor[x].blocksize * 2); y++) {
100108
for (z = 0; z < y; z++) {
101109
buf[z] = (unsigned char)(z & 255);
102110
}
103111
outlen = sizeof(md);
104-
hash_memory(x, buf, y, md, &outlen);
112+
if ((err = hash_memory(x, buf, y, md, &outlen)) != CRYPT_OK) {
113+
printf("hash_memory error: %s\n", error_to_string(err));
114+
exit(EXIT_FAILURE);
115+
}
105116
fprintf(out, "%3lu: ", y);
106117
for (z = 0; z < outlen; z++) {
107118
fprintf(out, "%02X", md[z]);
108119
}
109120
fprintf(out, "\n");
110121
}
111122
fprintf(out, "\n");
123+
XFREE(buf);
112124
}
113125
fclose(out);
114126
}
115127

116128
void cipher_gen(void)
117129
{
118-
unsigned char key[MAXBLOCKSIZE], pt[MAXBLOCKSIZE];
130+
unsigned char *key, pt[MAXBLOCKSIZE];
119131
unsigned long x, y, z, w;
120-
int kl, lastkl;
132+
int err, kl, lastkl;
121133
FILE *out;
122134
symmetric_key skey;
123135

@@ -138,15 +150,27 @@ void cipher_gen(void)
138150
case 1: kl = (cipher_descriptor[x].min_key_length + cipher_descriptor[x].max_key_length)/2; break;
139151
case 2: kl = cipher_descriptor[x].max_key_length; break;
140152
}
141-
cipher_descriptor[x].keysize(&kl);
153+
if ((err = cipher_descriptor[x].keysize(&kl)) != CRYPT_OK) {
154+
printf("keysize error: %s\n", error_to_string(err));
155+
exit(EXIT_FAILURE);
156+
}
142157
if (kl == lastkl) break;
143158
lastkl = kl;
144159
fprintf(out, "Key Size: %d bytes\n", kl);
145160

161+
key = XMALLOC(kl);
162+
if (key == NULL) {
163+
perror("can't malloc memory");
164+
exit(EXIT_FAILURE);
165+
}
166+
146167
for (z = 0; (int)z < kl; z++) {
147168
key[z] = (unsigned char)z;
148169
}
149-
cipher_descriptor[x].setup(key, kl, 0, &skey);
170+
if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
171+
printf("setup error: %s\n", error_to_string(err));
172+
exit(EXIT_FAILURE);
173+
}
150174

151175
for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
152176
pt[z] = (unsigned char)z;
@@ -163,9 +187,13 @@ void cipher_gen(void)
163187
for (z = 0; z < (unsigned long)kl; z++) {
164188
key[z] = pt[z % cipher_descriptor[x].block_length];
165189
}
166-
cipher_descriptor[x].setup(key, kl, 0, &skey);
190+
if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
191+
printf("cipher setup2 error: %s\n", error_to_string(err));
192+
exit(EXIT_FAILURE);
193+
}
167194
}
168195
fprintf(out, "\n");
196+
XFREE(key);
169197
}
170198
fprintf(out, "\n");
171199
}
@@ -174,7 +202,7 @@ void cipher_gen(void)
174202

175203
void hmac_gen(void)
176204
{
177-
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
205+
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], *input;
178206
int x, y, z, kl, err;
179207
FILE *out;
180208
unsigned long len;
@@ -193,6 +221,12 @@ void hmac_gen(void)
193221
for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) {
194222
key[y] = (y&255);
195223
}
224+
225+
input = XMALLOC(hash_descriptor[x].blocksize * 2);
226+
if (input == NULL) {
227+
perror("Can't malloc memory");
228+
exit(EXIT_FAILURE);
229+
}
196230

197231
for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) {
198232
for (z = 0; z < y; z++) {
@@ -212,6 +246,7 @@ void hmac_gen(void)
212246
/* forward the key */
213247
memcpy(key, output, hash_descriptor[x].hashsize);
214248
}
249+
XFREE(input);
215250
fprintf(out, "\n");
216251
}
217252
fclose(out);

0 commit comments

Comments
 (0)