Skip to content

Commit 9da48eb

Browse files
Tom St Denissjaeckel
authored andcommitted
added libtomcrypt-1.04
1 parent 3964a65 commit 9da48eb

12 files changed

Lines changed: 54 additions & 135 deletions

File tree

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PROJECT_NAME = LibTomCrypt
2323
# This could be handy for archiving the generated documentation or
2424
# if some version control system is used.
2525

26-
PROJECT_NUMBER = 1.03
26+
PROJECT_NUMBER = 1.04
2727

2828
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
2929
# base path where the generated documentation will be put.

TODO

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
Things ideal for 1.04
1+
Things ideal for 1.05
22

3-
- ASN.1 SET and UTCtime
3+
- 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)
44
- Start working towards making the bignum code plugable
55
- Add OID for ciphers and PRNGs to their descriptors
66
- Document the ASN.1 a bit more verbosely ;-)
77
- Some ASN.1 demo programs [for now read the source code!]
8+
- export ECC functions globally
89
- Look into other ECC point muls and consider a "precomp" interface
910

changes

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
June 15th, 2005
2+
v1.04
3+
-- Fixed off by one [bit] error in dsa_make_key() it was too high by one bit [not a security problem just inconsistent]
4+
-- ECC-224 curve was wrong [it was an ok curve just not NIST, so no security flaw just interoperability].
5+
-- Removed point compression since it slows down ECC ops to save a measly couple bytes.
6+
This makes the ecc export format incompatible with 1.03 [it shouldn't change in the future]
7+
-- Removed ECC-160 from timing and added the other curves
8+
19
June 9th, 2005
210
v1.03
311
-- 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
13001308
v0.01 -- We will call this the first version.
13011309

13021310
/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
1303-
/* $Revision: 1.92 $ */
1304-
/* $Date: 2005/06/09 01:06:59 $ */
1311+
/* $Revision: 1.97 $ */
1312+
/* $Date: 2005/06/14 23:09:41 $ */
13051313

crypt.tex

Lines changed: 8 additions & 9 deletions
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{LibTomCrypt \\ Version 1.03}
50+
\title{LibTomCrypt \\ Version 1.04}
5151
\author{Tom St Denis \\
5252
\\
5353
tomstdenis@gmail.com \\
@@ -3022,26 +3022,25 @@ \section{Key Format}
30223022
\begin{small}
30233023
\begin{verbatim}
30243024
ECCPublicKey ::= SEQUENCE {
3025-
flags BIT STRING(2), -- public/private flag (always zero),
3026-
-- compressed point
3025+
flags BIT STRING(1), -- public/private flag (always zero),
30273026
keySize INTEGER, -- Curve size (in bits) divided by eight
30283027
-- and rounded down, e.g. 521 => 65
30293028
pubkey.x INTEGER, -- The X co-ordinate of the public key point
3029+
pubkey.y INTEGER, -- The Y co-ordinate of the public key point
30303030
}
30313031
30323032
ECCPrivateKey ::= SEQUENCE {
3033-
flags BIT STRING(2), -- public/private flag (always one),
3034-
-- compressed point
3033+
flags BIT STRING(1), -- public/private flag (always one),
30353034
keySize INTEGER, -- Curve size (in bits) divided by eight
30363035
-- and rounded down, e.g. 521 => 65
30373036
pubkey.x INTEGER, -- The X co-ordinate of the public key point
3037+
pubkey.y INTEGER, -- The Y co-ordinate of the public key point
30383038
secret.k INTEGER, -- The secret key scalar
30393039
}
30403040
\end{verbatim}
30413041
\end{small}
30423042

3043-
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
3044-
congruent to the keys $y$ co-ordinate. The bit is one if the $y$ co-ordinate is the negative of the computed square root.
3043+
The first flags bit denotes whether the key is public (zero) or private (one).
30453044

30463045
\section{Core Functions}
30473046

@@ -4492,5 +4491,5 @@ \subsection{Exporting and Importing}
44924491
\end{document}
44934492
44944493
% $Source: /cvs/libtom/libtomcrypt/crypt.tex,v $
4495-
% $Revision: 1.32 $
4496-
% $Date: 2005/06/09 00:36:17 $
4494+
% $Revision: 1.33 $
4495+
% $Date: 2005/06/14 22:53:24 $

doc/crypt.pdf

-894 Bytes
Binary file not shown.

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Modified by Clay Culver
55

66
# The version
7-
VERSION=1.03
7+
VERSION=1.04
88

99
# Compiler and Linker Names
1010
#CC=gcc
@@ -321,5 +321,5 @@ zipup: no_oops docs
321321

322322

323323
# $Source: /cvs/libtom/libtomcrypt/makefile,v $
324-
# $Revision: 1.67 $
325-
# $Date: 2005/06/09 00:39:26 $
324+
# $Revision: 1.68 $
325+
# $Date: 2005/06/14 22:53:24 $

makefile.shared

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Tom St Denis
77

88
# The version
9-
VERSION=0:103
9+
VERSION=0:104
1010

1111
# Compiler and Linker Names
1212
CC=libtool --mode=compile gcc
@@ -222,5 +222,5 @@ timing: library $(LIBTEST) $(TIMINGS)
222222
gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
223223

224224
# $Source: /cvs/libtom/libtomcrypt/makefile.shared,v $
225-
# $Revision: 1.16 $
226-
# $Date: 2005/06/08 23:37:40 $
225+
# $Revision: 1.17 $
226+
# $Date: 2005/06/14 22:53:25 $

src/headers/tomcrypt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ extern "C" {
1616
#endif
1717

1818
/* version */
19-
#define CRYPT 0x0103
20-
#define SCRYPT "1.03"
19+
#define CRYPT 0x0104
20+
#define SCRYPT "1.04"
2121

2222
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
2323
#define MAXBLOCKSIZE 128

src/pk/dsa/dsa_make_key.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size,
7070
}
7171

7272
/* force magnitude */
73-
buf[0] = 1;
73+
buf[0] |= 0xC0;
7474

7575
/* force even */
76-
buf[modulus_size - group_size] &= ~1;
76+
buf[modulus_size - group_size - 1] &= ~1;
7777

78-
if ((err = mp_read_unsigned_bin(&tmp2, buf, modulus_size - group_size+1)) != MP_OKAY) { goto error; }
78+
if ((err = mp_read_unsigned_bin(&tmp2, buf, modulus_size - group_size)) != MP_OKAY) { goto error; }
7979
if ((err = mp_mul(&key->q, &tmp2, &key->p)) != MP_OKAY) { goto error; }
8080
if ((err = mp_add_d(&key->p, 1, &key->p)) != MP_OKAY) { goto error; }
81-
81+
8282
/* now loop until p is prime */
8383
for (;;) {
8484
if ((err = is_prime(&key->p, &res)) != CRYPT_OK) { goto LBL_ERR; }

src/pk/ecc/ecc.c

Lines changed: 18 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,20 @@ static const struct {
6060
"ECC-224",
6161

6262
/* prime */
63-
"400000000000000000000000000000000000BV",
63+
"3/////////////////////0000000000000001",
6464

6565
/* B */
66-
"21HkWGL2CxJIp",
66+
"2q1Gg530Ipg/L1CbPGHB2trx/OkYSBEKCZLV+q",
6767

6868
/* order */
69-
"4000000000000000000Kxnixk9t8MLzMiV264/",
69+
"3//////////////////nQYuBZmFXFTAKLSN2ez",
7070

7171
/* Gx */
72-
"jpqOf1BHus6Yd/pyhyVpP",
72+
"2t3WozQxI/Vp8JaBbA0y7JLi8H8ZGoWDOHN1qX",
73+
7374

7475
/* Gy */
75-
"3FCtyo2yHA5SFjkCGbYxbOvNeChwS+j6wSIwck",
76+
"2zDsE8jVSZ+qmYt+RDGtMWMWT7P4JLWPc507uq",
7677
},
7778
#endif
7879
#ifdef ECC256
@@ -819,89 +820,6 @@ void ecc_free(ecc_key *key)
819820
mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL);
820821
}
821822

822-
static int compress_y_point(ecc_point *pt, int idx, int *result)
823-
{
824-
mp_int tmp, tmp2, p;
825-
int err;
826-
827-
LTC_ARGCHK(pt != NULL);
828-
LTC_ARGCHK(result != NULL);
829-
830-
if ((err = mp_init_multi(&tmp, &tmp2, &p, NULL)) != MP_OKAY) {
831-
return mpi_to_ltc_error(err);
832-
}
833-
834-
/* get x^3 - 3x + b */
835-
if ((err = mp_read_radix(&p, (char *)sets[idx].B, 64)) != MP_OKAY) { goto error; } /* p = B */
836-
if ((err = mp_expt_d(&pt->x, 3, &tmp)) != MP_OKAY) { goto error; } /* tmp = pX^3 */
837-
if ((err = mp_mul_d(&pt->x, 3, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = 3*pX^3 */
838-
if ((err = mp_sub(&tmp, &tmp2, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp - tmp2 */
839-
if ((err = mp_add(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp + p */
840-
if ((err = mp_read_radix(&p, (char *)sets[idx].prime, 64)) != MP_OKAY) { goto error; } /* p = prime */
841-
if ((err = mp_mod(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp mod p */
842-
843-
/* now find square root */
844-
if ((err = mp_add_d(&p, 1, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = p + 1 */
845-
if ((err = mp_div_2d(&tmp2, 2, &tmp2, NULL)) != MP_OKAY) { goto error; } /* tmp2 = (p+1)/4 */
846-
if ((err = mp_exptmod(&tmp, &tmp2, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = (x^3 - 3x + b)^((p+1)/4) mod p */
847-
848-
/* if tmp equals the y point give a 0, otherwise 1 */
849-
if (mp_cmp(&tmp, &pt->y) == 0) {
850-
*result = 0;
851-
} else {
852-
*result = 1;
853-
}
854-
855-
err = CRYPT_OK;
856-
goto done;
857-
error:
858-
err = mpi_to_ltc_error(err);
859-
done:
860-
mp_clear_multi(&p, &tmp, &tmp2, NULL);
861-
return err;
862-
}
863-
864-
static int expand_y_point(ecc_point *pt, int idx, int result)
865-
{
866-
mp_int tmp, tmp2, p;
867-
int err;
868-
869-
LTC_ARGCHK(pt != NULL);
870-
871-
if ((err = mp_init_multi(&tmp, &tmp2, &p, NULL)) != MP_OKAY) {
872-
return CRYPT_MEM;
873-
}
874-
875-
/* get x^3 - 3x + b */
876-
if ((err = mp_read_radix(&p, (char *)sets[idx].B, 64)) != MP_OKAY) { goto error; } /* p = B */
877-
if ((err = mp_expt_d(&pt->x, 3, &tmp)) != MP_OKAY) { goto error; } /* tmp = pX^3 */
878-
if ((err = mp_mul_d(&pt->x, 3, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = 3*pX^3 */
879-
if ((err = mp_sub(&tmp, &tmp2, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp - tmp2 */
880-
if ((err = mp_add(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp + p */
881-
if ((err = mp_read_radix(&p, (char *)sets[idx].prime, 64)) != MP_OKAY) { goto error; } /* p = prime */
882-
if ((err = mp_mod(&tmp, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = tmp mod p */
883-
884-
/* now find square root */
885-
if ((err = mp_add_d(&p, 1, &tmp2)) != MP_OKAY) { goto error; } /* tmp2 = p + 1 */
886-
if ((err = mp_div_2d(&tmp2, 2, &tmp2, NULL)) != MP_OKAY) { goto error; } /* tmp2 = (p+1)/4 */
887-
if ((err = mp_exptmod(&tmp, &tmp2, &p, &tmp)) != MP_OKAY) { goto error; } /* tmp = (x^3 - 3x + b)^((p+1)/4) mod p */
888-
889-
/* if result==0, then y==tmp, otherwise y==p-tmp */
890-
if (result == 0) {
891-
if ((err = mp_copy(&tmp, &pt->y) != MP_OKAY)) { goto error; }
892-
} else {
893-
if ((err = mp_sub(&p, &tmp, &pt->y) != MP_OKAY)) { goto error; }
894-
}
895-
896-
err = CRYPT_OK;
897-
goto done;
898-
error:
899-
err = mpi_to_ltc_error(err);
900-
done:
901-
mp_clear_multi(&p, &tmp, &tmp2, NULL);
902-
return err;
903-
}
904-
905823
/**
906824
Export an ECC key as a binary packet
907825
@param out [out] Destination for the key
@@ -912,8 +830,8 @@ static int expand_y_point(ecc_point *pt, int idx, int result)
912830
*/
913831
int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key)
914832
{
915-
int cp, err;
916-
unsigned char flags[2];
833+
int err;
834+
unsigned char flags[1];
917835
unsigned long key_size;
918836

919837
LTC_ARGCHK(out != NULL);
@@ -929,29 +847,25 @@ int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key
929847
return CRYPT_INVALID_ARG;
930848
}
931849

932-
/* compress the y part */
933-
if ((err = compress_y_point(&key->pubkey, key->idx, &cp)) != CRYPT_OK) {
934-
return err;
935-
}
936-
flags[1] = cp;
937-
938850
/* we store the NIST byte size */
939851
key_size = sets[key->idx].size;
940852

941853
if (type == PK_PRIVATE) {
942854
flags[0] = 1;
943855
err = der_encode_sequence_multi(out, outlen,
944-
LTC_ASN1_BIT_STRING, 2UL, flags,
856+
LTC_ASN1_BIT_STRING, 1UL, flags,
945857
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
946858
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
859+
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
947860
LTC_ASN1_INTEGER, 1UL, &key->k,
948861
LTC_ASN1_EOL, 0UL, NULL);
949862
} else {
950863
flags[0] = 0;
951864
err = der_encode_sequence_multi(out, outlen,
952-
LTC_ASN1_BIT_STRING, 2UL, flags,
865+
LTC_ASN1_BIT_STRING, 1UL, flags,
953866
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
954867
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
868+
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
955869
LTC_ASN1_EOL, 0UL, NULL);
956870
}
957871

@@ -968,7 +882,7 @@ int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key
968882
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
969883
{
970884
unsigned long key_size;
971-
unsigned char flags[2];
885+
unsigned char flags[1];
972886
int err;
973887

974888
LTC_ARGCHK(in != NULL);
@@ -981,7 +895,7 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
981895

982896
/* find out what type of key it is */
983897
if ((err = der_decode_sequence_multi(in, inlen,
984-
LTC_ASN1_BIT_STRING, 2UL, &flags,
898+
LTC_ASN1_BIT_STRING, 1UL, &flags,
985899
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
986900
goto error;
987901
}
@@ -991,9 +905,10 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
991905
/* private key */
992906
key->type = PK_PRIVATE;
993907
if ((err = der_decode_sequence_multi(in, inlen,
994-
LTC_ASN1_BIT_STRING, 2UL, flags,
908+
LTC_ASN1_BIT_STRING, 1UL, flags,
995909
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
996910
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
911+
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
997912
LTC_ASN1_INTEGER, 1UL, &key->k,
998913
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
999914
goto error;
@@ -1003,9 +918,10 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
1003918
/* private key */
1004919
key->type = PK_PUBLIC;
1005920
if ((err = der_decode_sequence_multi(in, inlen,
1006-
LTC_ASN1_BIT_STRING, 2UL, flags,
921+
LTC_ASN1_BIT_STRING, 1UL, flags,
1007922
LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
1008923
LTC_ASN1_INTEGER, 1UL, &key->pubkey.x,
924+
LTC_ASN1_INTEGER, 1UL, &key->pubkey.y,
1009925
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
1010926
goto error;
1011927
}
@@ -1018,11 +934,6 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
1018934
goto error;
1019935
}
1020936

1021-
/* compute y */
1022-
if ((err = expand_y_point(&key->pubkey, key->idx, flags[1])) != CRYPT_OK) {
1023-
goto error;
1024-
}
1025-
1026937
/* set z */
1027938
mp_set(&key->pubkey.z, 1);
1028939

0 commit comments

Comments
 (0)