1111
1212enum {
1313 PK_PUBLIC = 0 ,
14- PK_PRIVATE = 1
14+ PK_PRIVATE = 1 ,
15+ PK_PUBLIC_COMPRESSED = 2 /* used only when exporting public ECC key */
1516};
1617
1718/* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */
@@ -248,7 +249,7 @@ int dh_check_pubkey(dh_key *key);
248249/* max private key size */
249250#define ECC_MAXSIZE 66
250251
251- /** Structure defines a NIST GF(p) curve */
252+ /** Structure defines a GF(p) curve */
252253typedef struct {
253254 /** The size of the curve in octets */
254255 int size ;
@@ -259,6 +260,9 @@ typedef struct {
259260 /** The prime that defines the field the curve is in (encoded in hex) */
260261 const char * prime ;
261262
263+ /** The fields A param (hex) */
264+ const char * A ;
265+
262266 /** The fields B param (hex) */
263267 const char * B ;
264268
@@ -270,6 +274,12 @@ typedef struct {
270274
271275 /** The y co-ordinate of the base point on the curve (hex) */
272276 const char * Gy ;
277+
278+ /** The co-factor */
279+ unsigned long cofactor ;
280+
281+ /** The OID stucture */
282+ oid_st oid ;
273283} ltc_ecc_set_type ;
274284
275285/** A point on a ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpretted as affine */
@@ -284,18 +294,35 @@ typedef struct {
284294 void * z ;
285295} ecc_point ;
286296
297+ /** ECC key's domain parameters */
298+ typedef struct {
299+ /** The size of the curve in octets */
300+ int size ;
301+ /** The prime that defines the field the curve is in */
302+ void * prime ;
303+ /** The fields A param */
304+ void * A ;
305+ /** The fields B param */
306+ void * B ;
307+ /** The order of the curve */
308+ void * order ;
309+ /** The base point G on the curve */
310+ ecc_point base ;
311+ /** The co-factor */
312+ unsigned long cofactor ;
313+ /** The OID structure */
314+ oid_st oid ;
315+ } ltc_ecc_dp ;
316+
287317/** An ECC key */
288318typedef struct {
289319 /** Type of key, PK_PRIVATE or PK_PUBLIC */
290320 int type ;
291321
292- /** Index into the ltc_ecc_sets[] for the parameters of this curve; if -1, then this key is using user supplied curve in dp */
293- int idx ;
294-
295- /** pointer to domain parameters; either points to NIST curves (identified by idx >= 0) or user supplied curve */
296- const ltc_ecc_set_type * dp ;
322+ /** Structure with domain parameters */
323+ ltc_ecc_dp dp ;
297324
298- /** The public key */
325+ /** Structure with the public key */
299326 ecc_point pubkey ;
300327
301328 /** The private key */
@@ -309,6 +336,12 @@ int ecc_test(void);
309336void ecc_sizes (int * low , int * high );
310337int ecc_get_size (ecc_key * key );
311338
339+ int ecc_get_set_by_name (const char * name , const ltc_ecc_set_type * * dp );
340+ int ecc_set_dp (const ltc_ecc_set_type * set , ecc_key * key );
341+ int ecc_generate_key (prng_state * prng , int wprng , ecc_key * key );
342+ int ecc_set_key (const unsigned char * in , unsigned long inlen , int type , ecc_key * key );
343+ int ecc_get_key (unsigned char * out , unsigned long * outlen , int type , ecc_key * key );
344+
312345int ecc_make_key (prng_state * prng , int wprng , int keysize , ecc_key * key );
313346int ecc_make_key_ex (prng_state * prng , int wprng , ecc_key * key , const ltc_ecc_set_type * dp );
314347void ecc_free (ecc_key * key );
@@ -319,7 +352,7 @@ int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, c
319352
320353int ecc_ansi_x963_export (ecc_key * key , unsigned char * out , unsigned long * outlen );
321354int ecc_ansi_x963_import (const unsigned char * in , unsigned long inlen , ecc_key * key );
322- int ecc_ansi_x963_import_ex (const unsigned char * in , unsigned long inlen , ecc_key * key , ltc_ecc_set_type * dp );
355+ int ecc_ansi_x963_import_ex (const unsigned char * in , unsigned long inlen , ecc_key * key , const ltc_ecc_set_type * dp );
323356
324357int ecc_shared_secret (ecc_key * private_key , ecc_key * public_key ,
325358 unsigned char * out , unsigned long * outlen );
@@ -349,23 +382,36 @@ int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
349382 const unsigned char * hash , unsigned long hashlen ,
350383 int * stat , ecc_key * key );
351384
385+
386+ #ifdef LTC_SOURCE
387+ /* INTERNAL ONLY - it should be later moved to src/headers/tomcrypt_internal.h */
388+
389+ int ecc_set_dp_bn (void * a , void * b , void * prime , void * order , void * gx , void * gy , unsigned long cofactor , ecc_key * key );
390+ int ecc_set_dp_oid (unsigned long * oid , unsigned long oidsize , ecc_key * key );
391+ int ecc_set_dp_copy (ecc_key * srckey , ecc_key * key );
392+ int ecc_set_dp_size (int size , ecc_key * key );
393+
352394/* low level functions */
353395ecc_point * ltc_ecc_new_point (void );
354396void ltc_ecc_del_point (ecc_point * p );
355- int ltc_ecc_is_valid_idx (int n );
397+ int ltc_ecc_is_point (const ltc_ecc_dp * dp , void * x , void * y );
398+ int ltc_ecc_is_point_at_infinity (const ecc_point * p , void * modulus );
399+ int ltc_ecc_import_point (const unsigned char * in , unsigned long inlen , void * prime , void * a , void * b , void * x , void * y );
400+ int ltc_ecc_export_point (unsigned char * out , unsigned long * outlen , void * x , void * y , unsigned long size , int compressed );
401+ int ltc_ecc_verify_key (ecc_key * key );
356402
357403/* point ops (mp == montgomery digit) */
358404#if !defined(LTC_MECC_ACCEL ) || defined(LTM_DESC ) || defined(GMP_DESC )
359405/* R = 2P */
360- int ltc_ecc_projective_dbl_point (ecc_point * P , ecc_point * R , void * modulus , void * mp );
406+ int ltc_ecc_projective_dbl_point (const ecc_point * P , ecc_point * R , void * a , void * modulus , void * mp );
361407
362408/* R = P + Q */
363- int ltc_ecc_projective_add_point (ecc_point * P , ecc_point * Q , ecc_point * R , void * modulus , void * mp );
409+ int ltc_ecc_projective_add_point (const ecc_point * P , const ecc_point * Q , ecc_point * R , void * a , void * modulus , void * mp );
364410#endif
365411
366412#if defined(LTC_MECC_FP )
367413/* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */
368- int ltc_ecc_fp_mulmod (void * k , ecc_point * G , ecc_point * R , void * modulus , int map );
414+ int ltc_ecc_fp_mulmod (void * k , ecc_point * G , ecc_point * R , void * a , void * modulus , int map );
369415
370416/* functions for saving/loading/freeing/adding to fixed point cache */
371417int ltc_ecc_fp_save_state (unsigned char * * out , unsigned long * outlen );
@@ -378,20 +424,23 @@ void ltc_ecc_fp_tablelock(int lock);
378424#endif
379425
380426/* R = kG */
381- int ltc_ecc_mulmod (void * k , ecc_point * G , ecc_point * R , void * modulus , int map );
427+ int ltc_ecc_mulmod (void * k , const ecc_point * G , ecc_point * R , void * a , void * modulus , int map );
382428
383429#ifdef LTC_ECC_SHAMIR
384430/* kA*A + kB*B = C */
385- int ltc_ecc_mul2add (ecc_point * A , void * kA ,
386- ecc_point * B , void * kB ,
387- ecc_point * C ,
388- void * modulus );
431+ int ltc_ecc_mul2add (const ecc_point * A , void * kA ,
432+ const ecc_point * B , void * kB ,
433+ ecc_point * C ,
434+ void * a ,
435+ void * modulus );
389436
390437#ifdef LTC_MECC_FP
391438/* Shamir's trick with optimized point multiplication using fixed point cache */
392- int ltc_ecc_fp_mul2add (ecc_point * A , void * kA ,
393- ecc_point * B , void * kB ,
394- ecc_point * C , void * modulus );
439+ int ltc_ecc_fp_mul2add (const ecc_point * A , void * kA ,
440+ const ecc_point * B , void * kB ,
441+ ecc_point * C ,
442+ void * a ,
443+ void * modulus );
395444#endif
396445
397446#endif
@@ -400,6 +449,8 @@ int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
400449/* map P to affine from projective */
401450int ltc_ecc_map (ecc_point * P , void * modulus , void * mp );
402451
452+ #endif /* LTC_SOURCE */
453+
403454#endif
404455
405456#ifdef LTC_MDSA
0 commit comments