Skip to content

Commit 53f7f3b

Browse files
Tom St Denissjaeckel
authored andcommitted
added libtomcrypt-0.93
1 parent 033cec5 commit 53f7f3b

82 files changed

Lines changed: 3279 additions & 563 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
11+
112
/* AES implementation by Tom St Denis
213
*
314
* Derived from the Public Domain source code by

aes_tab.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
/* The precomputed tables for AES */
212
/*
313
Te0[x] = S [x].[02, 01, 01, 03];

base64.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
/* compliant base64 code donated by Wayne Scott (wscott@bitmover.com) */
212
#include "mycrypt.h"
313

bits.c

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
/* portable way to get secure random bits to feed a PRNG */
212
#include "mycrypt.h"
313

@@ -35,45 +45,8 @@ static unsigned long rng_nix(unsigned char *buf, unsigned long len,
3545

3646
#endif /* DEVRANDOM */
3747

38-
#ifdef SONY_PS2
39-
#include <eetypes.h>
40-
#include <eeregs.h>
41-
#define min(a,b) ((a) < (b) ? (a) : (b))
42-
// Very simple/stupid MD5-based RNG that samples "entropy" from various PS2 control registers
43-
static unsigned long rng_ps2(unsigned char *buf, unsigned long len,
44-
void (*callback)(void))
45-
{
46-
static unsigned long lastx[2] = { 0xaab7cb4b2fd3b2b9, 0xcec58aff72afe49f }; // md5sum of bits.c
47-
unsigned long j;
48-
unsigned int samples[10]; // number of sample data sources
49-
int l;
50-
hash_state md;
51-
52-
for (j = 0; j < len; j += sizeof(lastx)) {
53-
md5_init(&md);
54-
samples[0] = *T2_COUNT;
55-
samples[1] = *T3_COUNT;
56-
samples[2] = *IPU_TOP;
57-
samples[3] = *GIF_TAG0;
58-
samples[4] = *GIF_TAG1;
59-
samples[5] = *GIF_TAG2;
60-
samples[6] = *VIF1_CODE;
61-
samples[7] = *VIF0_CODE;
62-
samples[8] = *D0_MADR;
63-
samples[9] = *D1_MADR;
64-
md5_process(&md, (unsigned char *)(&samples[0]), sizeof(samples));
65-
// include previous round
66-
md5_process(&md, (unsigned char *)(&lastx[0]), sizeof(lastx));
67-
md5_done(&md, (unsigned char *)(&lastx[0]));
68-
l = min(sizeof(lastx), len-j);
69-
memcpy(buf+j, &lastx[0], l); //min(sizeof(lastx), len-j));
70-
}
71-
return len;
72-
}
73-
#endif /* SONY_PS2 */
74-
7548
/* on ANSI C platforms with 100 < CLOCKS_PER_SEC < 10000 */
76-
#if !defined(SONY_PS2) && defined(CLOCKS_PER_SEC)
49+
#if defined(CLOCKS_PER_SEC)
7750

7851
#define ANSI_RNG
7952

@@ -143,9 +116,7 @@ unsigned long rng_get_bytes(unsigned char *buf, unsigned long len,
143116

144117
_ARGCHK(buf != NULL);
145118

146-
#ifdef SONY_PS2
147-
x = rng_ps2(buf, len, callback); if (x != 0) { return x; }
148-
#elif defined(DEVRANDOM)
119+
#if defined(DEVRANDOM)
149120
x = rng_nix(buf, len, callback); if (x != 0) { return x; }
150121
#endif
151122
#ifdef WIN32

blowfish.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
#include "mycrypt.h"
212

313
#ifdef BLOWFISH
@@ -350,7 +360,11 @@ int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
350360
return CRYPT_OK;
351361
}
352362

363+
#ifndef __GNUC__
353364
#define F(x) ((S1[byte(x,3)] + S2[byte(x,2)]) ^ S3[byte(x,1)]) + S4[byte(x,0)]
365+
#else
366+
#define F(x) ((key->blowfish.S[0][byte(x,3)] + key->blowfish.S[1][byte(x,2)]) ^ key->blowfish.S[2][byte(x,1)]) + key->blowfish.S[3][byte(x,0)]
367+
#endif
354368

355369
#ifdef CLEAN_STACK
356370
static void _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
@@ -360,16 +374,20 @@ void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_
360374
{
361375
ulong32 L, R;
362376
int r;
377+
#ifndef __GNUC__
363378
ulong32 *S1, *S2, *S3, *S4;
379+
#endif
364380

365381
_ARGCHK(pt != NULL);
366382
_ARGCHK(ct != NULL);
367383
_ARGCHK(key != NULL);
368384

385+
#ifndef __GNUC__
369386
S1 = key->blowfish.S[0];
370387
S2 = key->blowfish.S[1];
371388
S3 = key->blowfish.S[2];
372389
S4 = key->blowfish.S[3];
390+
#endif
373391

374392
/* load it */
375393
LOAD32H(L, &pt[0]);
@@ -408,16 +426,20 @@ void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_
408426
{
409427
ulong32 L, R;
410428
int r;
429+
#ifndef __GNUC__
411430
ulong32 *S1, *S2, *S3, *S4;
431+
#endif
412432

413433
_ARGCHK(pt != NULL);
414434
_ARGCHK(ct != NULL);
415435
_ARGCHK(key != NULL);
416436

437+
#ifndef __GNUC__
417438
S1 = key->blowfish.S[0];
418439
S2 = key->blowfish.S[1];
419440
S3 = key->blowfish.S[2];
420441
S4 = key->blowfish.S[3];
442+
#endif
421443

422444
/* load it */
423445
LOAD32H(R, &ct[0]);

cast5.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
/* Implementation of CAST5 (RFC 2144) by Tom St Denis */
212
#include "mycrypt.h"
313

cbc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
#include "mycrypt.h"
212

313
#ifdef CBC

cfb.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* gurantee it works.
8+
*
9+
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
10+
*/
111
#include "mycrypt.h"
212

313
#ifdef CFB

changes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
Jan 25th, 2004
2+
v0.93 -- [note: deleted v0.93 changes by accident... recreating from memory...]
3+
-- Fix to RC2 to not deference pointer before ARGCHK
4+
-- Fix to NOEKEON to match published test vectors as well as cleaned up the code a bit
5+
-- Optimized Twofish [down to 28 cycles/byte on my box] and Blowfish
6+
-- Fix to OMAC to test cipher block size first [prevents wasting any time]
7+
-- Added more OMAC test vectors
8+
-- Added EAX Encrypt+Authenticate support
9+
-- Fix to DSA to check return of a few LTM functions I forgot [mp_to_unsigned_bin]
10+
-- Added common headers to all C files
11+
-- CTR mode supports big and little [default] endian counters now.
12+
-- fix to find_cipher_any() so that it can handle a fragmented cipher_descriptor table.
13+
-- added find_hash_any() akin to find_cipher_any().
14+
-- Added EAX code to demos/tv_gen.c Hazaa!
15+
-- Removed SONY defines and files from codebase.
16+
-- Added OCB support [patents be damned] and to demos/tv_gen.c
17+
-- Merge all of the INPUT/OUTPUT BIGNUM macros (less toc) into mycrypt_pk.h
18+
-- Made appropriate changes to the debug string in crypt.c
19+
120
Dec 24th, 2003
221
v0.92 -- Updated the config.pl script so the options have more details.
322
-- Updated demos/tv_gen to include RIPEMD hashes

config.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"RIPEMD160,Include RIPEMD-160 one-way hash,y",
6363
"HMAC,Include Hash based Message Authentication Support,y",
6464
"OMAC,Include OMAC1 Message Authentication Support,y",
65+
"EAX_MODE,Include EAX Encrypt-and-Authenticate Support,y",
66+
"OCB_MODE,Include OCB Encrypt-and-Authenticate Support,y",
6567

6668
"BASE64,Include Base64 encoding support,y",
6769

@@ -151,7 +153,7 @@
151153

152154
# output objects
153155
print OUT "\ndefault: library\n\n";
154-
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\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";
155157

156158
# some depends
157159
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";

0 commit comments

Comments
 (0)