added libtomcrypt-0.91

This commit is contained in:
Tom St Denis 2003-09-26 01:16:18 +00:00 committed by Steffen Jaeckel
parent 16100c38eb
commit 55d745af4f
14 changed files with 386 additions and 354 deletions

View File

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

BIN
crypt.pdf

Binary file not shown.

View File

@ -47,7 +47,7 @@
\def\gap{\vspace{0.5ex}}
\makeindex
\begin{document}
\title{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.90}
\title{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.91}
\author{Tom St Denis \\
Algonquin College \\
\\

View File

@ -64,7 +64,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
void register_algs(void)
void register_algs(void)
{
register_hash(&sha512_desc);
register_hash(&sha384_desc);
@ -74,4 +74,6 @@ void register_algs(void)
register_hash(&md4_desc);
register_hash(&tiger_desc);
register_hash(&md2_desc);
register_hash(&rmd128_desc);
register_hash(&rmd160_desc);
}

View File

@ -1700,6 +1700,7 @@ test_errs (void)
ERR (CRYPT_PK_NOT_PRIVATE);
ERR (CRYPT_INVALID_ARG);
ERR (CRYPT_FILE_NOTFOUND);
ERR (CRYPT_PK_INVALID_TYPE);
ERR (CRYPT_PK_INVALID_SYSTEM);

View File

@ -50,20 +50,20 @@ void init_timer(void)
{
ulong64 c1, c2, t1, t2, t3;
unsigned long y1;
c1 = c2 = (ulong64)-1;
for (y1 = 0; y1 < TIMES*100; y1++) {
t_start();
t1 = t_read();
t3 = t_read();
t2 = t_read() - t1;
c1 = (c1 > t1) ? t1 : c1;
c2 = (c2 > t2) ? t2 : c2;
}
skew = c2 - c1;
printf("Clock Skew: %lu\n", (unsigned long)skew);
}
}
void reg_algs(void)
{
@ -135,6 +135,9 @@ void reg_algs(void)
#ifdef RIPEMD128
register_hash (&rmd128_desc);
#endif
#ifdef RIPEMD160
register_hash (&rmd160_desc);
#endif
}
@ -166,7 +169,7 @@ int time_keysched(void)
#undef DO1
}
return 0;
}
@ -196,13 +199,13 @@ int time_cipher(void)
DO2;
t2 = t_read();
t2 -= t1;
c1 = (t1 > c1 ? c1 : t1);
c2 = (t2 > c2 ? c2 : t2);
}
a1 = c2 - c1 - skew;
func = cipher_descriptor[x].ecb_decrypt;
c1 = c2 = (ulong64)-1;
for (y1 = 0; y1 < TIMES; y1++) {
@ -212,19 +215,19 @@ int time_cipher(void)
DO2;
t2 = t_read();
t2 -= t1;
c1 = (t1 > c1 ? c1 : t1);
c2 = (t2 > c2 ? c2 : t2);
}
a2 = c2 - c1 - skew;
printf
("%-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);
#undef DO2
#undef DO1
}
return 0;
}
@ -236,7 +239,7 @@ int time_hash(void)
void (*func)(hash_state *, const unsigned char *, unsigned long);
unsigned char pt[MAXBLOCKSIZE];
printf ("\n\nHASH Time Trials for:\n");
for (x = 0; hash_descriptor[x].name != NULL; x++) {
hash_descriptor[x].init(&md);
@ -246,7 +249,7 @@ int time_hash(void)
func = hash_descriptor[x].process;
len = hash_descriptor[x].blocksize;
c1 = c2 = (ulong64)-1;
for (y1 = 0; y1 < TIMES; y1++) {
t_start();
@ -257,16 +260,16 @@ int time_hash(void)
c1 = (t1 > c1) ? c1 : t1;
c2 = (t2 > c2) ? c2 : t2;
}
t1 = c2 - c1 - skew;
t1 = c2 - c1 - skew;
t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
printf
("%-20s: Process at %9.3f\n", hash_descriptor[x].name, t1 / 1000.0);
#undef DO2
#undef DO1
}
return 0;
}
@ -275,12 +278,12 @@ int main(void)
reg_algs();
printf("Timings for ciphers and hashes. Times are listed as cycles per byte processed.\n\n");
// init_timer();
time_cipher();
time_keysched();
time_hash();
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}

10
hash.c
View File

@ -78,16 +78,12 @@ int hash_file(int hash, const char *fname, unsigned char *dst, unsigned long *ou
in = fopen(fname, "rb");
if (in == NULL) {
return CRYPT_INVALID_ARG;
return CRYPT_FILE_NOTFOUND;
}
if ((err = hash_filehandle(hash, in, dst, outlen)) != CRYPT_OK) {
(void)fclose(in);
return err;
}
err = hash_filehandle(hash, in, dst, outlen);
(void)fclose(in);
return CRYPT_OK;
return err;
#endif
}

13
hmac.c
View File

@ -38,7 +38,7 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
}
/* valid key length? */
if (keylen == 0 || keylen > MAXBLOCKSIZE) {
if (keylen == 0) {
return CRYPT_INVALID_KEYSIZE;
}
@ -54,6 +54,7 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
if(hashsize < HMAC_BLOCKSIZE) {
zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
}
keylen = hashsize;
} else {
memcpy(hmac->key, key, (size_t)keylen);
if(keylen < HMAC_BLOCKSIZE) {
@ -62,14 +63,10 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
}
// Create the initial vector for step (3)
for(i=0; i < keylen; i++) {
for(i=0; i < HMAC_BLOCKSIZE; i++) {
buf[i] = hmac->key[i] ^ 0x36;
}
for( ; i < HMAC_BLOCKSIZE; i++) {
buf[i] = 0x36;
}
// Pre-pend that to the hash data
hash_descriptor[hash].init(&hmac->md);
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)
hash_descriptor[hash].done(&hmac->md, hashOut);
#ifdef CLEAN_STACK
zeromem(isha, sizeof(buf));
zeromem(buf, sizeof(isha));
zeromem(hmac->key, sizeof(hmac->key));
#endif
return CRYPT_OK;
@ -188,7 +187,7 @@ int hmac_file(int hash, const char *fname, const unsigned char *key,
in = fopen(fname, "rb");
if (in == NULL) {
return CRYPT_INVALID_ARG;
return CRYPT_FILE_NOTFOUND;
}
/* process the file contents */

View File

@ -9,7 +9,7 @@
# a build. This is easy to remedy though, for those that have problems.
# The version
VERSION=0.90
VERSION=0.91
#ch1-01-1
# Compiler and Linker Names

View File

@ -26,3 +26,6 @@ x86_prof: demos/x86_prof.c library
tv_gen: demos/tv_gen.c library
cl $(CFLAGS) demos/tv_gen.c tomcrypt.lib advapi32.lib
hashsum: demos/hashsum.c library
cl $(CFLAGS) demos/hashsum.c tomcrypt.lib advapi32.lib

645
mpi.c

File diff suppressed because it is too large Load Diff

View File

@ -16,8 +16,8 @@ extern "C" {
#endif
/* version */
#define CRYPT 0x0090
#define SCRYPT "0.90"
#define CRYPT 0x0091
#define SCRYPT "0.91"
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
#define MAXBLOCKSIZE 128
@ -49,6 +49,7 @@ enum {
CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
CRYPT_INVALID_ARG, /* Generic invalid argument */
CRYPT_FILE_NOTFOUND, /* File Not Found */
CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */

View File

@ -16,6 +16,7 @@
#define XCLOCK clock
#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
#define SMALL_CODE
#define CLEAN_STACK
#define LTC_TEST
#define BLOWFISH
#define RC2

View File

@ -27,6 +27,7 @@ static const char *err_2_str[] =
"A private PK key is required.",
"Invalid argument provided.",
"File Not Found",
"Invalid PK type.",
"Invalid PK system.",
@ -34,7 +35,8 @@ static const char *err_2_str[] =
"Key not found in keyring.",
"Invalid sized parameter.",
"Invalid size for prime."
"Invalid size for prime.",
};
const char *error_to_string(int err)