added libtomcrypt-1.04

This commit is contained in:
Tom St Denis 2005-06-14 22:16:11 +00:00 committed by Steffen Jaeckel
parent 3964a6523a
commit 9da48eb84b
12 changed files with 54 additions and 135 deletions

View File

@ -23,7 +23,7 @@ PROJECT_NAME = LibTomCrypt
# This could be handy for archiving the generated documentation or # This could be handy for archiving the generated documentation or
# if some version control system is used. # if some version control system is used.
PROJECT_NUMBER = 1.03 PROJECT_NUMBER = 1.04
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put. # base path where the generated documentation will be put.

5
TODO
View File

@ -1,9 +1,10 @@
Things ideal for 1.04 Things ideal for 1.05
- ASN.1 SET and UTCtime - ASN.1 SET and UTCtime and CHOICE (hint for choice do it as a sep list and just use error codes to know when you got a hit)
- Start working towards making the bignum code plugable - Start working towards making the bignum code plugable
- Add OID for ciphers and PRNGs to their descriptors - Add OID for ciphers and PRNGs to their descriptors
- Document the ASN.1 a bit more verbosely ;-) - Document the ASN.1 a bit more verbosely ;-)
- Some ASN.1 demo programs [for now read the source code!] - Some ASN.1 demo programs [for now read the source code!]
- export ECC functions globally
- Look into other ECC point muls and consider a "precomp" interface - Look into other ECC point muls and consider a "precomp" interface

12
changes
View File

@ -1,3 +1,11 @@
June 15th, 2005
v1.04
-- Fixed off by one [bit] error in dsa_make_key() it was too high by one bit [not a security problem just inconsistent]
-- ECC-224 curve was wrong [it was an ok curve just not NIST, so no security flaw just interoperability].
-- Removed point compression since it slows down ECC ops to save a measly couple bytes.
This makes the ecc export format incompatible with 1.03 [it shouldn't change in the future]
-- Removed ECC-160 from timing and added the other curves
June 9th, 2005 June 9th, 2005
v1.03 v1.03
-- Users may want to note that on a P4/GCC3.4 platform "-fno-regmove" greatly accelerates the ciphers/hashes. -- Users may want to note that on a P4/GCC3.4 platform "-fno-regmove" greatly accelerates the ciphers/hashes.
@ -1300,6 +1308,6 @@ v0.02 -- Changed RC5 to only allow 12 to 24 rounds
v0.01 -- We will call this the first version. v0.01 -- We will call this the first version.
/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */ /* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
/* $Revision: 1.92 $ */ /* $Revision: 1.97 $ */
/* $Date: 2005/06/09 01:06:59 $ */ /* $Date: 2005/06/14 23:09:41 $ */

View File

@ -47,7 +47,7 @@
\def\gap{\vspace{0.5ex}} \def\gap{\vspace{0.5ex}}
\makeindex \makeindex
\begin{document} \begin{document}
\title{LibTomCrypt \\ Version 1.03} \title{LibTomCrypt \\ Version 1.04}
\author{Tom St Denis \\ \author{Tom St Denis \\
\\ \\
tomstdenis@gmail.com \\ tomstdenis@gmail.com \\
@ -3022,26 +3022,25 @@ than ideally simple manner. In the case of LibTomCrypt it is meant \textbf{sole
\begin{small} \begin{small}
\begin{verbatim} \begin{verbatim}
ECCPublicKey ::= SEQUENCE { ECCPublicKey ::= SEQUENCE {
flags BIT STRING(2), -- public/private flag (always zero), flags BIT STRING(1), -- public/private flag (always zero),
-- compressed point
keySize INTEGER, -- Curve size (in bits) divided by eight keySize INTEGER, -- Curve size (in bits) divided by eight
-- and rounded down, e.g. 521 => 65 -- and rounded down, e.g. 521 => 65
pubkey.x INTEGER, -- The X co-ordinate of the public key point pubkey.x INTEGER, -- The X co-ordinate of the public key point
pubkey.y INTEGER, -- The Y co-ordinate of the public key point
} }
ECCPrivateKey ::= SEQUENCE { ECCPrivateKey ::= SEQUENCE {
flags BIT STRING(2), -- public/private flag (always one), flags BIT STRING(1), -- public/private flag (always one),
-- compressed point
keySize INTEGER, -- Curve size (in bits) divided by eight keySize INTEGER, -- Curve size (in bits) divided by eight
-- and rounded down, e.g. 521 => 65 -- and rounded down, e.g. 521 => 65
pubkey.x INTEGER, -- The X co-ordinate of the public key point pubkey.x INTEGER, -- The X co-ordinate of the public key point
pubkey.y INTEGER, -- The Y co-ordinate of the public key point
secret.k INTEGER, -- The secret key scalar secret.k INTEGER, -- The secret key scalar
} }
\end{verbatim} \end{verbatim}
\end{small} \end{small}
The first flags bit denotes whether the key is public (zero) or private (one). The compressed point bit is equal to zero if $(x^3 - 3x + b)^{(p+1)/4} \mbox{ mod }p$ is The first flags bit denotes whether the key is public (zero) or private (one).
congruent to the keys $y$ co-ordinate. The bit is one if the $y$ co-ordinate is the negative of the computed square root.
\section{Core Functions} \section{Core Functions}
@ -4492,5 +4491,5 @@ but should at least maintain the same level of state entropy.
\end{document} \end{document}
% $Source: /cvs/libtom/libtomcrypt/crypt.tex,v $ % $Source: /cvs/libtom/libtomcrypt/crypt.tex,v $
% $Revision: 1.32 $ % $Revision: 1.33 $
% $Date: 2005/06/09 00:36:17 $ % $Date: 2005/06/14 22:53:24 $

Binary file not shown.

View File

@ -4,7 +4,7 @@
# Modified by Clay Culver # Modified by Clay Culver
# The version # The version
VERSION=1.03 VERSION=1.04
# Compiler and Linker Names # Compiler and Linker Names
#CC=gcc #CC=gcc
@ -321,5 +321,5 @@ zipup: no_oops docs
# $Source: /cvs/libtom/libtomcrypt/makefile,v $ # $Source: /cvs/libtom/libtomcrypt/makefile,v $
# $Revision: 1.67 $ # $Revision: 1.68 $
# $Date: 2005/06/09 00:39:26 $ # $Date: 2005/06/14 22:53:24 $

View File

@ -6,7 +6,7 @@
# Tom St Denis # Tom St Denis
# The version # The version
VERSION=0:103 VERSION=0:104
# Compiler and Linker Names # Compiler and Linker Names
CC=libtool --mode=compile gcc CC=libtool --mode=compile gcc
@ -222,5 +222,5 @@ timing: library $(LIBTEST) $(TIMINGS)
gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(MPISHARED) gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
# $Source: /cvs/libtom/libtomcrypt/makefile.shared,v $ # $Source: /cvs/libtom/libtomcrypt/makefile.shared,v $
# $Revision: 1.16 $ # $Revision: 1.17 $
# $Date: 2005/06/08 23:37:40 $ # $Date: 2005/06/14 22:53:25 $

View File

@ -16,8 +16,8 @@ extern "C" {
#endif #endif
/* version */ /* version */
#define CRYPT 0x0103 #define CRYPT 0x0104
#define SCRYPT "1.03" #define SCRYPT "1.04"
/* 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

View File

@ -70,15 +70,15 @@ int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size,
} }
/* force magnitude */ /* force magnitude */
buf[0] = 1; buf[0] |= 0xC0;
/* force even */ /* force even */
buf[modulus_size - group_size] &= ~1; buf[modulus_size - group_size - 1] &= ~1;
if ((err = mp_read_unsigned_bin(&tmp2, buf, modulus_size - group_size+1)) != MP_OKAY) { goto error; } if ((err = mp_read_unsigned_bin(&tmp2, buf, modulus_size - group_size)) != MP_OKAY) { goto error; }
if ((err = mp_mul(&key->q, &tmp2, &key->p)) != MP_OKAY) { goto error; } if ((err = mp_mul(&key->q, &tmp2, &key->p)) != MP_OKAY) { goto error; }
if ((err = mp_add_d(&key->p, 1, &key->p)) != MP_OKAY) { goto error; } if ((err = mp_add_d(&key->p, 1, &key->p)) != MP_OKAY) { goto error; }
/* now loop until p is prime */ /* now loop until p is prime */
for (;;) { for (;;) {
if ((err = is_prime(&key->p, &res)) != CRYPT_OK) { goto LBL_ERR; } if ((err = is_prime(&key->p, &res)) != CRYPT_OK) { goto LBL_ERR; }

View File

@ -60,19 +60,20 @@ static const struct {
"ECC-224", "ECC-224",
/* prime */ /* prime */
"400000000000000000000000000000000000BV", "3/////////////////////0000000000000001",
/* B */ /* B */
"21HkWGL2CxJIp", "2q1Gg530Ipg/L1CbPGHB2trx/OkYSBEKCZLV+q",
/* order */ /* order */
"4000000000000000000Kxnixk9t8MLzMiV264/", "3//////////////////nQYuBZmFXFTAKLSN2ez",
/* Gx */ /* Gx */
"jpqOf1BHus6Yd/pyhyVpP", "2t3WozQxI/Vp8JaBbA0y7JLi8H8ZGoWDOHN1qX",
/* Gy */ /* Gy */
"3FCtyo2yHA5SFjkCGbYxbOvNeChwS+j6wSIwck", "2zDsE8jVSZ+qmYt+RDGtMWMWT7P4JLWPc507uq",
}, },
#endif #endif
#ifdef ECC256 #ifdef ECC256
@ -819,89 +820,6 @@ void ecc_free(ecc_key *key)
mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL); mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL);
} }
static int compress_y_point(ecc_point *pt, int idx, int *result)
{
mp_int tmp, tmp2, p;
int err;
LTC_ARGCHK(pt != NULL);
LTC_ARGCHK(result != NULL);
if ((err = mp_init_multi(&tmp, &tmp2, &p, NULL)) != MP_OKAY) {
return mpi_to_ltc_error(err);
}
/* get x^3 - 3x + b */
if ((err = mp_read_radix(&p, (char *)sets[idx].B, 64)) != MP_OKAY) { goto error; } /* p = B */
if ((err = mp_expt_d(&pt->x, 3, &tmp)) != MP_OKAY) { goto error; } /* tmp = pX^3 */
if ((err = mp_mul_d(&pt->x, 3, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = 3*pX^3 */
if ((err = mp_sub(&tmp, &tmp2, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp - tmp2 */
if ((err = mp_add(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp + p */
if ((err = mp_read_radix(&p, (char *)sets[idx].prime, 64)) != MP_OKAY) { goto error; } /* p = prime */
if ((err = mp_mod(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp mod p */
/* now find square root */
if ((err = mp_add_d(&p, 1, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = p + 1 */
if ((err = mp_div_2d(&tmp2, 2, &tmp2, NULL)) != MP_OKAY) { goto error; } /* tmp2 = (p+1)/4 */
if ((err = mp_exptmod(&tmp, &tmp2, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = (x^3 - 3x + b)^((p+1)/4) mod p */
/* if tmp equals the y point give a 0, otherwise 1 */
if (mp_cmp(&tmp, &pt->y) == 0) {
*result = 0;
} else {
*result = 1;
}
err = CRYPT_OK;
goto done;
error:
err = mpi_to_ltc_error(err);
done:
mp_clear_multi(&p, &tmp, &tmp2, NULL);
return err;
}
static int expand_y_point(ecc_point *pt, int idx, int result)
{
mp_int tmp, tmp2, p;
int err;
LTC_ARGCHK(pt != NULL);
if ((err = mp_init_multi(&tmp, &tmp2, &p, NULL)) != MP_OKAY) {
return CRYPT_MEM;
}
/* get x^3 - 3x + b */
if ((err = mp_read_radix(&p, (char *)sets[idx].B, 64)) != MP_OKAY) { goto error; } /* p = B */
if ((err = mp_expt_d(&pt->x, 3, &tmp)) != MP_OKAY) { goto error; } /* tmp = pX^3 */
if ((err = mp_mul_d(&pt->x, 3, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = 3*pX^3 */
if ((err = mp_sub(&tmp, &tmp2, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp - tmp2 */
if ((err = mp_add(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp + p */
if ((err = mp_read_radix(&p, (char *)sets[idx].prime, 64)) != MP_OKAY) { goto error; } /* p = prime */
if ((err = mp_mod(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp mod p */
/* now find square root */
if ((err = mp_add_d(&p, 1, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = p + 1 */
if ((err = mp_div_2d(&tmp2, 2, &tmp2, NULL)) != MP_OKAY) { goto error; } /* tmp2 = (p+1)/4 */
if ((err = mp_exptmod(&tmp, &tmp2, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = (x^3 - 3x + b)^((p+1)/4) mod p */
/* if result==0, then y==tmp, otherwise y==p-tmp */
if (result == 0) {
if ((err = mp_copy(&tmp, &pt->y) != MP_OKAY)) { goto error; }
} else {
if ((err = mp_sub(&p, &tmp, &pt->y) != MP_OKAY)) { goto error; }
}
err = CRYPT_OK;
goto done;
error:
err = mpi_to_ltc_error(err);
done:
mp_clear_multi(&p, &tmp, &tmp2, NULL);
return err;
}
/** /**
Export an ECC key as a binary packet Export an ECC key as a binary packet
@param out [out] Destination for the key @param out [out] Destination for the key
@ -912,8 +830,8 @@ done:
*/ */
int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key) int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key)
{ {
int cp, err; int err;
unsigned char flags[2]; unsigned char flags[1];
unsigned long key_size; unsigned long key_size;
LTC_ARGCHK(out != NULL); LTC_ARGCHK(out != NULL);
@ -929,29 +847,25 @@ int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key
return CRYPT_INVALID_ARG; return CRYPT_INVALID_ARG;
} }
/* compress the y part */
if ((err = compress_y_point(&key->pubkey, key->idx, &cp)) != CRYPT_OK) {
return err;
}
flags[1] = cp;
/* we store the NIST byte size */ /* we store the NIST byte size */
key_size = sets[key->idx].size; key_size = sets[key->idx].size;
if (type == PK_PRIVATE) { if (type == PK_PRIVATE) {
flags[0] = 1; flags[0] = 1;
err = der_encode_sequence_multi(out, outlen, err = der_encode_sequence_multi(out, outlen,
LTC_ASN1_BIT_STRING, 2UL, flags, LTC_ASN1_BIT_STRING, 1UL, flags,
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size, LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x, LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
LTC_ASN1_INTEGER, 1UL, &key->k, LTC_ASN1_INTEGER, 1UL, &key->k,
LTC_ASN1_EOL, 0UL, NULL); LTC_ASN1_EOL, 0UL, NULL);
} else { } else {
flags[0] = 0; flags[0] = 0;
err = der_encode_sequence_multi(out, outlen, err = der_encode_sequence_multi(out, outlen,
LTC_ASN1_BIT_STRING, 2UL, flags, LTC_ASN1_BIT_STRING, 1UL, flags,
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size, LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x, LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
LTC_ASN1_EOL, 0UL, NULL); LTC_ASN1_EOL, 0UL, NULL);
} }
@ -968,7 +882,7 @@ int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key) int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
{ {
unsigned long key_size; unsigned long key_size;
unsigned char flags[2]; unsigned char flags[1];
int err; int err;
LTC_ARGCHK(in != NULL); LTC_ARGCHK(in != NULL);
@ -981,7 +895,7 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
/* find out what type of key it is */ /* find out what type of key it is */
if ((err = der_decode_sequence_multi(in, inlen, if ((err = der_decode_sequence_multi(in, inlen,
LTC_ASN1_BIT_STRING, 2UL, &flags, LTC_ASN1_BIT_STRING, 1UL, &flags,
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
goto error; goto error;
} }
@ -991,9 +905,10 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
/* private key */ /* private key */
key->type = PK_PRIVATE; key->type = PK_PRIVATE;
if ((err = der_decode_sequence_multi(in, inlen, if ((err = der_decode_sequence_multi(in, inlen,
LTC_ASN1_BIT_STRING, 2UL, flags, LTC_ASN1_BIT_STRING, 1UL, flags,
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size, LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x, LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
LTC_ASN1_INTEGER, 1UL, &key->k, LTC_ASN1_INTEGER, 1UL, &key->k,
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
goto error; goto error;
@ -1003,9 +918,10 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
/* private key */ /* private key */
key->type = PK_PUBLIC; key->type = PK_PUBLIC;
if ((err = der_decode_sequence_multi(in, inlen, if ((err = der_decode_sequence_multi(in, inlen,
LTC_ASN1_BIT_STRING, 2UL, flags, LTC_ASN1_BIT_STRING, 1UL, flags,
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size, LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x, LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
goto error; goto error;
} }
@ -1018,11 +934,6 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
goto error; goto error;
} }
/* compute y */
if ((err = expand_y_point(&key->pubkey, key->idx, flags[1])) != CRYPT_OK) {
goto error;
}
/* set z */ /* set z */
mp_set(&key->pubkey.z, 1); mp_set(&key->pubkey.z, 1);

View File

@ -67,7 +67,7 @@ int ecc_tests (void)
return 1; return 1;
} }
if (memcmp (buf[0], buf[2], x)) { if (memcmp (buf[0], buf[2], x)) {
fprintf(stderr, "Failed. Content didn't match."); fprintf(stderr, "Failed. Contents didn't match.");
return 1; return 1;
} }
ecc_free (&usera); ecc_free (&usera);

View File

@ -724,7 +724,7 @@ void time_ecc(void)
unsigned char buf[2][4096]; unsigned char buf[2][4096];
unsigned long i, x, y, z; unsigned long i, x, y, z;
int err; int err;
static unsigned long sizes[] = {160/8, 256/8, 521/8, 100000}; static unsigned long sizes[] = {192/8, 256/8, 384/8, 521/8, 100000};
for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
t2 = 0; t2 = 0;