Skip to content

Commit 55d745a

Browse files
Tom St Denissjaeckel
authored andcommitted
added libtomcrypt-0.91
1 parent 16100c3 commit 55d745a

14 files changed

Lines changed: 384 additions & 352 deletions

File tree

changes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Sept 25th, 2003
2+
v0.91 -- HMAC fix of 0.90 was incorrect for keys larger than the block size of the hash.
3+
-- Added error CRYPT_FILE_NOTFOUND for the file [hmac/hash] routines.
4+
-- Added RIPEMD hashes to the hashsum demo.
5+
-- Added hashsum demo to MSVC makefile.
6+
-- Added RMD160 to the x86_prof demo [oops]
7+
-- Merged in LibTomMath-0.27 with a patch to mp_shrink() that will be in LibTomMath-0.28
8+
Fixes another potential memory leak.
9+
110
Sept 7th, 2003
211
v0.90 -- new ROL/ROR for x86 GCC
312
-- Jochen Katz submitted a patch to the makefile to prevent "make" from making the .a library

crypt.pdf

221 Bytes
Binary file not shown.

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{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.90}
50+
\title{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.91}
5151
\author{Tom St Denis \\
5252
Algonquin College \\
5353
\\

demos/hashsum.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
6464
return EXIT_SUCCESS;
6565
}
6666

67-
void register_algs(void)
67+
void register_algs(void)
6868
{
6969
register_hash(&sha512_desc);
7070
register_hash(&sha384_desc);
@@ -74,4 +74,6 @@ void register_algs(void)
7474
register_hash(&md4_desc);
7575
register_hash(&tiger_desc);
7676
register_hash(&md2_desc);
77+
register_hash(&rmd128_desc);
78+
register_hash(&rmd160_desc);
7779
}

demos/test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,7 @@ test_errs (void)
17001700
ERR (CRYPT_PK_NOT_PRIVATE);
17011701

17021702
ERR (CRYPT_INVALID_ARG);
1703+
ERR (CRYPT_FILE_NOTFOUND);
17031704

17041705
ERR (CRYPT_PK_INVALID_TYPE);
17051706
ERR (CRYPT_PK_INVALID_SYSTEM);

demos/x86_prof.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ void init_timer(void)
5050
{
5151
ulong64 c1, c2, t1, t2, t3;
5252
unsigned long y1;
53-
53+
5454
c1 = c2 = (ulong64)-1;
5555
for (y1 = 0; y1 < TIMES*100; y1++) {
5656
t_start();
5757
t1 = t_read();
5858
t3 = t_read();
5959
t2 = t_read() - t1;
60-
60+
6161
c1 = (c1 > t1) ? t1 : c1;
6262
c2 = (c2 > t2) ? t2 : c2;
6363
}
6464
skew = c2 - c1;
6565
printf("Clock Skew: %lu\n", (unsigned long)skew);
66-
}
66+
}
6767

6868
void reg_algs(void)
6969
{
@@ -135,6 +135,9 @@ void reg_algs(void)
135135
#ifdef RIPEMD128
136136
register_hash (&rmd128_desc);
137137
#endif
138+
#ifdef RIPEMD160
139+
register_hash (&rmd160_desc);
140+
#endif
138141

139142
}
140143

@@ -166,7 +169,7 @@ int time_keysched(void)
166169

167170
#undef DO1
168171
}
169-
172+
170173
return 0;
171174
}
172175

@@ -196,13 +199,13 @@ int time_cipher(void)
196199
DO2;
197200
t2 = t_read();
198201
t2 -= t1;
199-
202+
200203
c1 = (t1 > c1 ? c1 : t1);
201204
c2 = (t2 > c2 ? c2 : t2);
202205
}
203206
a1 = c2 - c1 - skew;
204-
205-
207+
208+
206209
func = cipher_descriptor[x].ecb_decrypt;
207210
c1 = c2 = (ulong64)-1;
208211
for (y1 = 0; y1 < TIMES; y1++) {
@@ -212,19 +215,19 @@ int time_cipher(void)
212215
DO2;
213216
t2 = t_read();
214217
t2 -= t1;
215-
218+
216219
c1 = (t1 > c1 ? c1 : t1);
217220
c2 = (t2 > c2 ? c2 : t2);
218221
}
219222
a2 = c2 - c1 - skew;
220-
223+
221224
printf
222225
("%-20s: Encrypt at %7.3f, Decrypt at %7.3f\n", cipher_descriptor[x].name, a1/(double)cipher_descriptor[x].block_length, a2/(double)cipher_descriptor[x].block_length);
223226

224227
#undef DO2
225228
#undef DO1
226229
}
227-
230+
228231
return 0;
229232
}
230233

@@ -236,7 +239,7 @@ int time_hash(void)
236239
void (*func)(hash_state *, const unsigned char *, unsigned long);
237240
unsigned char pt[MAXBLOCKSIZE];
238241

239-
242+
240243
printf ("\n\nHASH Time Trials for:\n");
241244
for (x = 0; hash_descriptor[x].name != NULL; x++) {
242245
hash_descriptor[x].init(&md);
@@ -246,7 +249,7 @@ int time_hash(void)
246249

247250
func = hash_descriptor[x].process;
248251
len = hash_descriptor[x].blocksize;
249-
252+
250253
c1 = c2 = (ulong64)-1;
251254
for (y1 = 0; y1 < TIMES; y1++) {
252255
t_start();
@@ -257,16 +260,16 @@ int time_hash(void)
257260
c1 = (t1 > c1) ? c1 : t1;
258261
c2 = (t2 > c2) ? c2 : t2;
259262
}
260-
t1 = c2 - c1 - skew;
263+
t1 = c2 - c1 - skew;
261264
t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
262-
265+
263266
printf
264267
("%-20s: Process at %9.3f\n", hash_descriptor[x].name, t1 / 1000.0);
265268

266269
#undef DO2
267270
#undef DO1
268271
}
269-
272+
270273
return 0;
271274
}
272275

@@ -275,12 +278,12 @@ int main(void)
275278
reg_algs();
276279

277280
printf("Timings for ciphers and hashes. Times are listed as cycles per byte processed.\n\n");
278-
281+
279282
// init_timer();
280283
time_cipher();
281284
time_keysched();
282285
time_hash();
283-
286+
284287
return EXIT_SUCCESS;
285-
}
288+
}
286289

hash.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,12 @@ int hash_file(int hash, const char *fname, unsigned char *dst, unsigned long *ou
7878

7979
in = fopen(fname, "rb");
8080
if (in == NULL) {
81-
return CRYPT_INVALID_ARG;
81+
return CRYPT_FILE_NOTFOUND;
8282
}
8383

84-
if ((err = hash_filehandle(hash, in, dst, outlen)) != CRYPT_OK) {
85-
(void)fclose(in);
86-
return err;
87-
}
84+
err = hash_filehandle(hash, in, dst, outlen);
8885
(void)fclose(in);
89-
90-
return CRYPT_OK;
86+
return err;
9187
#endif
9288
}
9389

hmac.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
3838
}
3939

4040
/* valid key length? */
41-
if (keylen == 0 || keylen > MAXBLOCKSIZE) {
41+
if (keylen == 0) {
4242
return CRYPT_INVALID_KEYSIZE;
4343
}
4444

@@ -54,6 +54,7 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
5454
if(hashsize < HMAC_BLOCKSIZE) {
5555
zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
5656
}
57+
keylen = hashsize;
5758
} else {
5859
memcpy(hmac->key, key, (size_t)keylen);
5960
if(keylen < HMAC_BLOCKSIZE) {
@@ -62,14 +63,10 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
6263
}
6364

6465
// Create the initial vector for step (3)
65-
for(i=0; i < keylen; i++) {
66+
for(i=0; i < HMAC_BLOCKSIZE; i++) {
6667
buf[i] = hmac->key[i] ^ 0x36;
6768
}
6869

69-
for( ; i < HMAC_BLOCKSIZE; i++) {
70-
buf[i] = 0x36;
71-
}
72-
7370
// Pre-pend that to the hash data
7471
hash_descriptor[hash].init(&hmac->md);
7572
hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE);
@@ -126,6 +123,8 @@ int hmac_done(hmac_state *hmac, unsigned char *hashOut, unsigned long *outlen)
126123
hash_descriptor[hash].done(&hmac->md, hashOut);
127124

128125
#ifdef CLEAN_STACK
126+
zeromem(isha, sizeof(buf));
127+
zeromem(buf, sizeof(isha));
129128
zeromem(hmac->key, sizeof(hmac->key));
130129
#endif
131130
return CRYPT_OK;
@@ -188,7 +187,7 @@ int hmac_file(int hash, const char *fname, const unsigned char *key,
188187

189188
in = fopen(fname, "rb");
190189
if (in == NULL) {
191-
return CRYPT_INVALID_ARG;
190+
return CRYPT_FILE_NOTFOUND;
192191
}
193192

194193
/* process the file contents */

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# a build. This is easy to remedy though, for those that have problems.
1010

1111
# The version
12-
VERSION=0.90
12+
VERSION=0.91
1313

1414
#ch1-01-1
1515
# Compiler and Linker Names

makefile.msvc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ x86_prof: demos/x86_prof.c library
2626

2727
tv_gen: demos/tv_gen.c library
2828
cl $(CFLAGS) demos/tv_gen.c tomcrypt.lib advapi32.lib
29+
30+
hashsum: demos/hashsum.c library
31+
cl $(CFLAGS) demos/hashsum.c tomcrypt.lib advapi32.lib

0 commit comments

Comments
 (0)