added libtomcrypt-0.91
This commit is contained in:
parent
16100c38eb
commit
55d745af4f
9
changes
9
changes
@ -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
|
Sept 7th, 2003
|
||||||
v0.90 -- new ROL/ROR for x86 GCC
|
v0.90 -- new ROL/ROR for x86 GCC
|
||||||
-- Jochen Katz submitted a patch to the makefile to prevent "make" from making the .a library
|
-- Jochen Katz submitted a patch to the makefile to prevent "make" from making the .a library
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
\def\gap{\vspace{0.5ex}}
|
\def\gap{\vspace{0.5ex}}
|
||||||
\makeindex
|
\makeindex
|
||||||
\begin{document}
|
\begin{document}
|
||||||
\title{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.90}
|
\title{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.91}
|
||||||
\author{Tom St Denis \\
|
\author{Tom St Denis \\
|
||||||
Algonquin College \\
|
Algonquin College \\
|
||||||
\\
|
\\
|
||||||
|
@ -64,7 +64,7 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_algs(void)
|
void register_algs(void)
|
||||||
{
|
{
|
||||||
register_hash(&sha512_desc);
|
register_hash(&sha512_desc);
|
||||||
register_hash(&sha384_desc);
|
register_hash(&sha384_desc);
|
||||||
@ -74,4 +74,6 @@ void register_algs(void)
|
|||||||
register_hash(&md4_desc);
|
register_hash(&md4_desc);
|
||||||
register_hash(&tiger_desc);
|
register_hash(&tiger_desc);
|
||||||
register_hash(&md2_desc);
|
register_hash(&md2_desc);
|
||||||
|
register_hash(&rmd128_desc);
|
||||||
|
register_hash(&rmd160_desc);
|
||||||
}
|
}
|
||||||
|
@ -1700,6 +1700,7 @@ test_errs (void)
|
|||||||
ERR (CRYPT_PK_NOT_PRIVATE);
|
ERR (CRYPT_PK_NOT_PRIVATE);
|
||||||
|
|
||||||
ERR (CRYPT_INVALID_ARG);
|
ERR (CRYPT_INVALID_ARG);
|
||||||
|
ERR (CRYPT_FILE_NOTFOUND);
|
||||||
|
|
||||||
ERR (CRYPT_PK_INVALID_TYPE);
|
ERR (CRYPT_PK_INVALID_TYPE);
|
||||||
ERR (CRYPT_PK_INVALID_SYSTEM);
|
ERR (CRYPT_PK_INVALID_SYSTEM);
|
||||||
|
@ -50,20 +50,20 @@ void init_timer(void)
|
|||||||
{
|
{
|
||||||
ulong64 c1, c2, t1, t2, t3;
|
ulong64 c1, c2, t1, t2, t3;
|
||||||
unsigned long y1;
|
unsigned long y1;
|
||||||
|
|
||||||
c1 = c2 = (ulong64)-1;
|
c1 = c2 = (ulong64)-1;
|
||||||
for (y1 = 0; y1 < TIMES*100; y1++) {
|
for (y1 = 0; y1 < TIMES*100; y1++) {
|
||||||
t_start();
|
t_start();
|
||||||
t1 = t_read();
|
t1 = t_read();
|
||||||
t3 = t_read();
|
t3 = t_read();
|
||||||
t2 = t_read() - t1;
|
t2 = t_read() - t1;
|
||||||
|
|
||||||
c1 = (c1 > t1) ? t1 : c1;
|
c1 = (c1 > t1) ? t1 : c1;
|
||||||
c2 = (c2 > t2) ? t2 : c2;
|
c2 = (c2 > t2) ? t2 : c2;
|
||||||
}
|
}
|
||||||
skew = c2 - c1;
|
skew = c2 - c1;
|
||||||
printf("Clock Skew: %lu\n", (unsigned long)skew);
|
printf("Clock Skew: %lu\n", (unsigned long)skew);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reg_algs(void)
|
void reg_algs(void)
|
||||||
{
|
{
|
||||||
@ -135,6 +135,9 @@ void reg_algs(void)
|
|||||||
#ifdef RIPEMD128
|
#ifdef RIPEMD128
|
||||||
register_hash (&rmd128_desc);
|
register_hash (&rmd128_desc);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef RIPEMD160
|
||||||
|
register_hash (&rmd160_desc);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +169,7 @@ int time_keysched(void)
|
|||||||
|
|
||||||
#undef DO1
|
#undef DO1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,13 +199,13 @@ int time_cipher(void)
|
|||||||
DO2;
|
DO2;
|
||||||
t2 = t_read();
|
t2 = t_read();
|
||||||
t2 -= t1;
|
t2 -= t1;
|
||||||
|
|
||||||
c1 = (t1 > c1 ? c1 : t1);
|
c1 = (t1 > c1 ? c1 : t1);
|
||||||
c2 = (t2 > c2 ? c2 : t2);
|
c2 = (t2 > c2 ? c2 : t2);
|
||||||
}
|
}
|
||||||
a1 = c2 - c1 - skew;
|
a1 = c2 - c1 - skew;
|
||||||
|
|
||||||
|
|
||||||
func = cipher_descriptor[x].ecb_decrypt;
|
func = cipher_descriptor[x].ecb_decrypt;
|
||||||
c1 = c2 = (ulong64)-1;
|
c1 = c2 = (ulong64)-1;
|
||||||
for (y1 = 0; y1 < TIMES; y1++) {
|
for (y1 = 0; y1 < TIMES; y1++) {
|
||||||
@ -212,19 +215,19 @@ int time_cipher(void)
|
|||||||
DO2;
|
DO2;
|
||||||
t2 = t_read();
|
t2 = t_read();
|
||||||
t2 -= t1;
|
t2 -= t1;
|
||||||
|
|
||||||
c1 = (t1 > c1 ? c1 : t1);
|
c1 = (t1 > c1 ? c1 : t1);
|
||||||
c2 = (t2 > c2 ? c2 : t2);
|
c2 = (t2 > c2 ? c2 : t2);
|
||||||
}
|
}
|
||||||
a2 = c2 - c1 - skew;
|
a2 = c2 - c1 - skew;
|
||||||
|
|
||||||
printf
|
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);
|
("%-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 DO2
|
||||||
#undef DO1
|
#undef DO1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +239,7 @@ int time_hash(void)
|
|||||||
void (*func)(hash_state *, const unsigned char *, unsigned long);
|
void (*func)(hash_state *, const unsigned char *, unsigned long);
|
||||||
unsigned char pt[MAXBLOCKSIZE];
|
unsigned char pt[MAXBLOCKSIZE];
|
||||||
|
|
||||||
|
|
||||||
printf ("\n\nHASH Time Trials for:\n");
|
printf ("\n\nHASH Time Trials for:\n");
|
||||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||||
hash_descriptor[x].init(&md);
|
hash_descriptor[x].init(&md);
|
||||||
@ -246,7 +249,7 @@ int time_hash(void)
|
|||||||
|
|
||||||
func = hash_descriptor[x].process;
|
func = hash_descriptor[x].process;
|
||||||
len = hash_descriptor[x].blocksize;
|
len = hash_descriptor[x].blocksize;
|
||||||
|
|
||||||
c1 = c2 = (ulong64)-1;
|
c1 = c2 = (ulong64)-1;
|
||||||
for (y1 = 0; y1 < TIMES; y1++) {
|
for (y1 = 0; y1 < TIMES; y1++) {
|
||||||
t_start();
|
t_start();
|
||||||
@ -257,16 +260,16 @@ int time_hash(void)
|
|||||||
c1 = (t1 > c1) ? c1 : t1;
|
c1 = (t1 > c1) ? c1 : t1;
|
||||||
c2 = (t2 > c2) ? c2 : t2;
|
c2 = (t2 > c2) ? c2 : t2;
|
||||||
}
|
}
|
||||||
t1 = c2 - c1 - skew;
|
t1 = c2 - c1 - skew;
|
||||||
t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
|
t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
|
||||||
|
|
||||||
printf
|
printf
|
||||||
("%-20s: Process at %9.3f\n", hash_descriptor[x].name, t1 / 1000.0);
|
("%-20s: Process at %9.3f\n", hash_descriptor[x].name, t1 / 1000.0);
|
||||||
|
|
||||||
#undef DO2
|
#undef DO2
|
||||||
#undef DO1
|
#undef DO1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,12 +278,12 @@ int main(void)
|
|||||||
reg_algs();
|
reg_algs();
|
||||||
|
|
||||||
printf("Timings for ciphers and hashes. Times are listed as cycles per byte processed.\n\n");
|
printf("Timings for ciphers and hashes. Times are listed as cycles per byte processed.\n\n");
|
||||||
|
|
||||||
// init_timer();
|
// init_timer();
|
||||||
time_cipher();
|
time_cipher();
|
||||||
time_keysched();
|
time_keysched();
|
||||||
time_hash();
|
time_hash();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
hash.c
10
hash.c
@ -78,16 +78,12 @@ int hash_file(int hash, const char *fname, unsigned char *dst, unsigned long *ou
|
|||||||
|
|
||||||
in = fopen(fname, "rb");
|
in = fopen(fname, "rb");
|
||||||
if (in == NULL) {
|
if (in == NULL) {
|
||||||
return CRYPT_INVALID_ARG;
|
return CRYPT_FILE_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = hash_filehandle(hash, in, dst, outlen)) != CRYPT_OK) {
|
err = hash_filehandle(hash, in, dst, outlen);
|
||||||
(void)fclose(in);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
(void)fclose(in);
|
(void)fclose(in);
|
||||||
|
return err;
|
||||||
return CRYPT_OK;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
hmac.c
13
hmac.c
@ -38,7 +38,7 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* valid key length? */
|
/* valid key length? */
|
||||||
if (keylen == 0 || keylen > MAXBLOCKSIZE) {
|
if (keylen == 0) {
|
||||||
return CRYPT_INVALID_KEYSIZE;
|
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) {
|
if(hashsize < HMAC_BLOCKSIZE) {
|
||||||
zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
|
zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
|
||||||
}
|
}
|
||||||
|
keylen = hashsize;
|
||||||
} else {
|
} else {
|
||||||
memcpy(hmac->key, key, (size_t)keylen);
|
memcpy(hmac->key, key, (size_t)keylen);
|
||||||
if(keylen < HMAC_BLOCKSIZE) {
|
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)
|
// 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;
|
buf[i] = hmac->key[i] ^ 0x36;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( ; i < HMAC_BLOCKSIZE; i++) {
|
|
||||||
buf[i] = 0x36;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pre-pend that to the hash data
|
// Pre-pend that to the hash data
|
||||||
hash_descriptor[hash].init(&hmac->md);
|
hash_descriptor[hash].init(&hmac->md);
|
||||||
hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE);
|
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);
|
hash_descriptor[hash].done(&hmac->md, hashOut);
|
||||||
|
|
||||||
#ifdef CLEAN_STACK
|
#ifdef CLEAN_STACK
|
||||||
|
zeromem(isha, sizeof(buf));
|
||||||
|
zeromem(buf, sizeof(isha));
|
||||||
zeromem(hmac->key, sizeof(hmac->key));
|
zeromem(hmac->key, sizeof(hmac->key));
|
||||||
#endif
|
#endif
|
||||||
return CRYPT_OK;
|
return CRYPT_OK;
|
||||||
@ -188,7 +187,7 @@ int hmac_file(int hash, const char *fname, const unsigned char *key,
|
|||||||
|
|
||||||
in = fopen(fname, "rb");
|
in = fopen(fname, "rb");
|
||||||
if (in == NULL) {
|
if (in == NULL) {
|
||||||
return CRYPT_INVALID_ARG;
|
return CRYPT_FILE_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process the file contents */
|
/* process the file contents */
|
||||||
|
2
makefile
2
makefile
@ -9,7 +9,7 @@
|
|||||||
# a build. This is easy to remedy though, for those that have problems.
|
# a build. This is easy to remedy though, for those that have problems.
|
||||||
|
|
||||||
# The version
|
# The version
|
||||||
VERSION=0.90
|
VERSION=0.91
|
||||||
|
|
||||||
#ch1-01-1
|
#ch1-01-1
|
||||||
# Compiler and Linker Names
|
# Compiler and Linker Names
|
||||||
|
@ -26,3 +26,6 @@ x86_prof: demos/x86_prof.c library
|
|||||||
|
|
||||||
tv_gen: demos/tv_gen.c library
|
tv_gen: demos/tv_gen.c library
|
||||||
cl $(CFLAGS) demos/tv_gen.c tomcrypt.lib advapi32.lib
|
cl $(CFLAGS) demos/tv_gen.c tomcrypt.lib advapi32.lib
|
||||||
|
|
||||||
|
hashsum: demos/hashsum.c library
|
||||||
|
cl $(CFLAGS) demos/hashsum.c tomcrypt.lib advapi32.lib
|
@ -16,8 +16,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* version */
|
/* version */
|
||||||
#define CRYPT 0x0090
|
#define CRYPT 0x0091
|
||||||
#define SCRYPT "0.90"
|
#define SCRYPT "0.91"
|
||||||
|
|
||||||
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
|
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
|
||||||
#define MAXBLOCKSIZE 128
|
#define MAXBLOCKSIZE 128
|
||||||
@ -49,6 +49,7 @@ enum {
|
|||||||
CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
|
CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
|
||||||
|
|
||||||
CRYPT_INVALID_ARG, /* Generic invalid argument */
|
CRYPT_INVALID_ARG, /* Generic invalid argument */
|
||||||
|
CRYPT_FILE_NOTFOUND, /* File Not Found */
|
||||||
|
|
||||||
CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
|
CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
|
||||||
CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */
|
CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#define XCLOCK clock
|
#define XCLOCK clock
|
||||||
#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
|
#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
|
||||||
#define SMALL_CODE
|
#define SMALL_CODE
|
||||||
|
#define CLEAN_STACK
|
||||||
#define LTC_TEST
|
#define LTC_TEST
|
||||||
#define BLOWFISH
|
#define BLOWFISH
|
||||||
#define RC2
|
#define RC2
|
||||||
|
@ -27,6 +27,7 @@ static const char *err_2_str[] =
|
|||||||
"A private PK key is required.",
|
"A private PK key is required.",
|
||||||
|
|
||||||
"Invalid argument provided.",
|
"Invalid argument provided.",
|
||||||
|
"File Not Found",
|
||||||
|
|
||||||
"Invalid PK type.",
|
"Invalid PK type.",
|
||||||
"Invalid PK system.",
|
"Invalid PK system.",
|
||||||
@ -34,7 +35,8 @@ static const char *err_2_str[] =
|
|||||||
"Key not found in keyring.",
|
"Key not found in keyring.",
|
||||||
"Invalid sized parameter.",
|
"Invalid sized parameter.",
|
||||||
|
|
||||||
"Invalid size for prime."
|
"Invalid size for prime.",
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *error_to_string(int err)
|
const char *error_to_string(int err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user