Skip to content

Commit e9c1c53

Browse files
Tom St Denissjaeckel
authored andcommitted
added libtomcrypt-0.97a
1 parent 1a11416 commit e9c1c53

15 files changed

Lines changed: 132 additions & 80 deletions

changes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
June 23rd, 2004
2+
v0.97a ++ Fixed several potentially crippling bugs... [read on]
3+
-- Fixed bug in OAEP decoder that would incorrectly report
4+
buffer overflows. [Zhi Chen]
5+
-- Fixed headers which had various C++ missing [extern "C"]'s
6+
-- Added "extern" to sha384_desc descriptor which I removed by mistake
7+
-- Fixed bugs in ENDIAN_BIG macros using the wrong byte order [Matt Johnston]
8+
-- Updated tiger.c and des.c to not shadow "round" which is intrinsic on
9+
some C compilers.
10+
-- Updated demos/test/rsa_test.c to test the RSA functionality better
11+
++ This update has been tested with GCC [v3.3.3], ICC [v8] and MSVC [v6+SP6]
12+
all on a x86 P4 [GCC/ICC tested in Gentoo Linux, MSVC in WinXP]
13+
++ Outcome: The bug Zhi Chen pointed out has been fixed. So have the bugs
14+
that Matt Johnston found.
15+
116
June 19th, 2004
217
v0.97 -- Removed spurious unused files [arrg!]
318
-- Patched buffer overflow in tim_exptmod()

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.97}
50+
\title{LibTomCrypt \\ Version 0.97a}
5151
\author{Tom St Denis \\
5252
\\
5353
tomstdenis@iahu.ca \\

demos/test/rsa_test.c

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include "test.h"
22

3+
#define RSA_MSGSIZE 78
4+
5+
36
int rsa_test(void)
47
{
58
unsigned char in[1024], out[1024], tmp[1024];
69
rsa_key key;
710
int hash_idx, prng_idx, stat, stat2;
8-
unsigned long len, len2;
11+
unsigned long rsa_msgsize, len, len2;
912
static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
1013

1114
hash_idx = find_hash("sha1");
@@ -15,48 +18,82 @@ int rsa_test(void)
1518
return 1;
1619
}
1720

18-
/* make a random key/msg */
19-
yarrow_read(in, 20, &test_yarrow);
20-
2121
/* make a random key */
2222
DO(rsa_make_key(&test_yarrow, prng_idx, 1024/8, 65537, &key));
2323

2424
/* encrypt the key (without lparam) */
25-
len = sizeof(out);
26-
len2 = sizeof(tmp);
27-
DO(rsa_encrypt_key(in, 20, out, &len, NULL, 0, &test_yarrow, prng_idx, hash_idx, &key));
28-
/* change a byte */
29-
out[0] ^= 1;
30-
DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat2, &key));
31-
/* change a byte back */
32-
out[0] ^= 1;
33-
DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat, &key));
34-
if (!(stat == 1 && stat2 == 0)) {
35-
printf("rsa_decrypt_key failed");
36-
return 1;
37-
}
38-
if (len2 != 20 || memcmp(tmp, in, 20)) {
39-
printf("rsa_decrypt_key mismatch len %lu", len2);
40-
return 1;
25+
for (rsa_msgsize = 1; rsa_msgsize <= 86; 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+
DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, NULL, 0, &test_yarrow, prng_idx, hash_idx, &key));
33+
/* change a byte */
34+
out[8] ^= 1;
35+
DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat2, &key));
36+
/* change a byte back */
37+
out[8] ^= 1;
38+
if (len2 != rsa_msgsize) {
39+
printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
40+
return 1;
41+
}
42+
43+
len2 = rsa_msgsize;
44+
DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat, &key));
45+
if (!(stat == 1 && stat2 == 0)) {
46+
printf("rsa_decrypt_key failed");
47+
return 1;
48+
}
49+
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
50+
int x;
51+
printf("\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
52+
printf("Original contents: \n");
53+
for (x = 0; x < rsa_msgsize; ) {
54+
printf("%02x ", in[x]);
55+
if (!(++x % 16)) {
56+
printf("\n");
57+
}
58+
}
59+
printf("\n");
60+
printf("Output contents: \n");
61+
for (x = 0; x < rsa_msgsize; ) {
62+
printf("%02x ", out[x]);
63+
if (!(++x % 16)) {
64+
printf("\n");
65+
}
66+
}
67+
printf("\n");
68+
return 1;
69+
}
4170
}
4271

4372
/* encrypt the key (with lparam) */
44-
len = sizeof(out);
45-
len2 = sizeof(tmp);
46-
DO(rsa_encrypt_key(in, 20, out, &len, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &key));
47-
/* change a byte */
48-
out[0] ^= 1;
49-
DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat2, &key));
50-
/* change a byte back */
51-
out[0] ^= 1;
52-
DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat, &key));
53-
if (!(stat == 1 && stat2 == 0)) {
54-
printf("rsa_decrypt_key failed");
55-
return 1;
56-
}
57-
if (len2 != 20 || memcmp(tmp, in, 20)) {
58-
printf("rsa_decrypt_key mismatch len %lu", len2);
59-
return 1;
73+
for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
74+
len = sizeof(out);
75+
len2 = rsa_msgsize;
76+
DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &key));
77+
/* change a byte */
78+
out[8] ^= 1;
79+
DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat2, &key));
80+
if (len2 != rsa_msgsize) {
81+
printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
82+
return 1;
83+
}
84+
/* change a byte back */
85+
out[8] ^= 1;
86+
87+
len2 = rsa_msgsize;
88+
DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat, &key));
89+
if (!(stat == 1 && stat2 == 0)) {
90+
printf("rsa_decrypt_key failed");
91+
return 1;
92+
}
93+
if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
94+
printf("rsa_decrypt_key mismatch len %lu", len2);
95+
return 1;
96+
}
6097
}
6198

6299
/* sign a message (unsalted, lower cholestorol and Atkins approved) now */

des.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ static void _desfunc(ulong32 *block, const ulong32 *keys)
13951395
#endif
13961396
{
13971397
ulong32 work, right, leftt;
1398-
int round;
1398+
int cur_round;
13991399

14001400
leftt = block[0];
14011401
right = block[1];
@@ -1439,7 +1439,7 @@ static void _desfunc(ulong32 *block, const ulong32 *keys)
14391439
}
14401440
#endif
14411441

1442-
for (round = 0; round < 8; round++) {
1442+
for (cur_round = 0; cur_round < 8; cur_round++) {
14431443
work = ROR(right, 4) ^ *keys++;
14441444
leftt ^= SP7[work & 0x3fL]
14451445
^ SP5[(work >> 8) & 0x3fL]
@@ -1534,7 +1534,7 @@ int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
15341534
_ARGCHK(key != NULL);
15351535
_ARGCHK(skey != NULL);
15361536

1537-
if( num_rounds != 0 && num_rounds != 16) {
1537+
if(num_rounds != 0 && num_rounds != 16) {
15381538
return CRYPT_INVALID_ROUNDS;
15391539
}
15401540

doc/crypt.pdf

81 Bytes
Binary file not shown.

ltc_tommath.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#define MAX(x,y) ((x)>(y)?(x):(y))
2828

2929
#ifdef __cplusplus
30-
"C" {
30+
extern "C" {
3131

3232
/* C++ compilers don't like assigning void * to mp_digit * */
3333
#define OPT_CAST(x) (x *)

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Modified by Clay Culver
55

66
# The version
7-
VERSION=0.97
7+
VERSION=0.97a
88

99
# Compiler and Linker Names
1010
#CC=gcc

mycrypt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
#include <mycrypt_custom.h>
1313

1414
#ifdef __cplusplus
15-
"C" {
15+
extern "C" {
1616
#endif
1717

1818
/* version */
1919
#define CRYPT 0x0097
20-
#define SCRYPT "0.97"
20+
#define SCRYPT "0.97a"
2121

2222
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
2323
#define MAXBLOCKSIZE 64

mycrypt_hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ extern struct _hash_descriptor {
149149
#define sha384_process sha512_process
150150
int sha384_done(hash_state * md, unsigned char *hash);
151151
int sha384_test(void);
152-
const struct _hash_descriptor sha384_desc;
152+
extern const struct _hash_descriptor sha384_desc;
153153
#endif
154154

155155
#ifdef SHA256

mycrypt_macros.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,26 @@ typedef unsigned long ulong32;
125125

126126
#ifdef ENDIAN_BIG
127127
#define STORE32L(x, y) \
128-
{ (y)[z0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
129-
(y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
128+
{ (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
129+
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
130130

131131
#define LOAD32L(x, y) \
132-
{ x = ((unsigned long)((y)[0] & 255)<<24) | \
133-
((unsigned long)((y)[1] & 255)<<16) | \
134-
((unsigned long)((y)[2] & 255)<<8) | \
135-
((unsigned long)((y)[3] & 255)); }
132+
{ x = ((unsigned long)((y)[3] & 255)<<24) | \
133+
((unsigned long)((y)[2] & 255)<<16) | \
134+
((unsigned long)((y)[1] & 255)<<8) | \
135+
((unsigned long)((y)[0] & 255)); }
136136

137137
#define STORE64L(x, y) \
138-
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
139-
(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
140-
(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
141-
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
138+
{ (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
139+
(y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
140+
(y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
141+
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
142142

143143
#define LOAD64L(x, y) \
144-
{ x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
145-
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
146-
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
147-
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
144+
{ x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
145+
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
146+
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
147+
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
148148

149149
#ifdef ENDIAN_32BITWORD
150150

@@ -155,16 +155,16 @@ typedef unsigned long ulong32;
155155
memcpy(&(x), y, 4);
156156

157157
#define STORE64H(x, y) \
158-
{ (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
159-
(y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
160-
(y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
161-
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
158+
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
159+
(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
160+
(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
161+
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
162162

163163
#define LOAD64H(x, y) \
164-
{ x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
165-
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
166-
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
167-
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
164+
{ x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
165+
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
166+
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
167+
(((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); }
168168

169169
#else /* 64-bit words then */
170170

0 commit comments

Comments
 (0)