@@ -297,20 +297,10 @@ typedef struct {
297297
298298 /** The private key */
299299 void * k ;
300-
301- /** The hash algorithm to use when creating a signature.
302- * Setting this will enable RFC6979 compatible signature generation.
303- * The macro ECC_SET_RFC6979_HASH_ALG() is provided as a helper
304- * to set this.*/
305- const char * rfc6979_hash_alg ;
306300} ecc_key ;
307301
308- #define ECC_SET_RFC6979_HASH_ALG (key , alg ) do { \
309- (key)->rfc6979_hash_alg = (alg); \
310- } while(0)
311-
312302/** Formats of ECC signatures */
313- typedef enum ecc_signature_type_ {
303+ typedef enum ecc_signature_type {
314304 /* ASN.1 encoded, ANSI X9.62 */
315305 LTC_ECCSIG_ANSIX962 = 0x0 ,
316306 /* raw R, S values */
@@ -321,6 +311,28 @@ typedef enum ecc_signature_type_ {
321311 LTC_ECCSIG_RFC5656 = 0x3 ,
322312} ecc_signature_type ;
323313
314+ typedef struct ltc_ecc_sig_opts {
315+ /** Signature type */
316+ ecc_signature_type type ;
317+ /** The PRNG to use.
318+ * This must be set in case deterministic signature generation
319+ * according to RFC6979 is not enabled.
320+ */
321+ prng_state * prng ;
322+ int wprng ;
323+
324+ /** Enable generation of a recovery ID.
325+ * This must be set in case one requires the recovery ID of a
326+ * signature operation.
327+ */
328+ int * recid ;
329+
330+ /** The hash algorithm to use when creating a signature.
331+ * Setting this will enable RFC6979 compatible signature generation.
332+ */
333+ const char * rfc6979_hash_alg ;
334+ } ltc_ecc_sig_opts ;
335+
324336/** the ECC params provided */
325337extern const ltc_ecc_curve ltc_ecc_curves [];
326338
@@ -356,6 +368,21 @@ int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_k
356368int ecc_shared_secret (const ecc_key * private_key , const ecc_key * public_key ,
357369 unsigned char * out , unsigned long * outlen );
358370
371+ int ecc_sign_hash_v2 (const unsigned char * in ,
372+ unsigned long inlen ,
373+ unsigned char * out ,
374+ unsigned long * outlen ,
375+ ltc_ecc_sig_opts * opts ,
376+ const ecc_key * key );
377+
378+ int ecc_verify_hash_v2 (const unsigned char * sig ,
379+ unsigned long siglen ,
380+ const unsigned char * hash ,
381+ unsigned long hashlen ,
382+ ltc_ecc_sig_opts * opts ,
383+ int * stat ,
384+ const ecc_key * key );
385+
359386#if defined(LTC_DER )
360387int ecc_encrypt_key (const unsigned char * in , unsigned long inlen ,
361388 unsigned char * out , unsigned long * outlen ,
@@ -365,7 +392,42 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
365392int ecc_decrypt_key (const unsigned char * in , unsigned long inlen ,
366393 unsigned char * out , unsigned long * outlen ,
367394 const ecc_key * key );
368-
395+ #endif /* LTC_DER */
396+
397+ #define ltc_ecc_sign_hash (i , il , o , ol , p , wp , k ) \
398+ ecc_sign_hash_v2(i, il, o, ol, \
399+ &(ltc_ecc_sig_opts){ \
400+ .type = LTC_ECCSIG_ANSIX962, \
401+ .prng = p, \
402+ .wprng = wp, \
403+ }, k)
404+ #define ltc_ecc_sign_hash_rfc7518 (i , il , o , ol , p , wp , k ) \
405+ ecc_sign_hash_v2(i, il, o, ol, \
406+ &(ltc_ecc_sig_opts){ \
407+ .type = LTC_ECCSIG_RFC7518, \
408+ .prng = p, \
409+ .wprng = wp, \
410+ }, k)
411+
412+ #define ltc_ecc_verify_hash (s , sl , h , hl , st , k ) \
413+ ecc_verify_hash_v2(s, sl, h, hl, \
414+ &(ltc_ecc_sig_opts){ \
415+ .type = LTC_ECCSIG_ANSIX962, \
416+ }, st, k)
417+ #define ltc_ecc_verify_hash_rfc7518 (s , sl , h , hl , st , k ) \
418+ ecc_verify_hash_v2(s, sl, h, hl, \
419+ &(ltc_ecc_sig_opts){ \
420+ .type = LTC_ECCSIG_RFC7518, \
421+ }, st, k)
422+
423+ #ifdef LTC_NO_DEPRECATED_APIS
424+ #define ecc_sign_hash ltc_ecc_sign_hash
425+ #define ecc_verify_hash ltc_ecc_verify_hash
426+ #define ecc_sign_hash_rfc7518 ltc_ecc_sign_hash_rfc7518
427+ #define ecc_verify_hash_rfc7518 ltc_ecc_verify_hash_rfc7518
428+ #else /* LTC_NO_DEPRECATED_APIS */
429+ #if defined(LTC_DER )
430+ LTC_DEPRECATED (ecc_sign_hash_v2 )
369431int ecc_sign_hash (const unsigned char * in ,
370432 unsigned long inlen ,
371433 unsigned char * out ,
@@ -374,14 +436,16 @@ int ecc_sign_hash(const unsigned char *in,
374436 int wprng ,
375437 const ecc_key * key );
376438
439+ LTC_DEPRECATED (ecc_verify_hash_v2 )
377440int ecc_verify_hash (const unsigned char * sig ,
378441 unsigned long siglen ,
379442 const unsigned char * hash ,
380443 unsigned long hashlen ,
381444 int * stat ,
382445 const ecc_key * key );
383- #endif
446+ #endif /* LTC_DER */
384447
448+ LTC_DEPRECATED (ecc_sign_hash_v2 )
385449int ecc_sign_hash_rfc7518 (const unsigned char * in ,
386450 unsigned long inlen ,
387451 unsigned char * out ,
@@ -390,60 +454,20 @@ int ecc_sign_hash_rfc7518(const unsigned char *in,
390454 int wprng ,
391455 const ecc_key * key );
392456
393- int ecc_sign_hash_rfc7518_ex (const unsigned char * in ,
394- unsigned long inlen ,
395- unsigned char * out ,
396- unsigned long * outlen ,
397- prng_state * prng ,
398- int wprng ,
399- int * recid ,
400- const ecc_key * key );
401-
457+ LTC_DEPRECATED (ecc_verify_hash_v2 )
402458int ecc_verify_hash_rfc7518 (const unsigned char * sig ,
403459 unsigned long siglen ,
404460 const unsigned char * hash ,
405461 unsigned long hashlen ,
406462 int * stat ,
407463 const ecc_key * key );
408-
409- #if defined(LTC_SSH )
410- int ecc_sign_hash_rfc5656 (const unsigned char * in ,
411- unsigned long inlen ,
412- unsigned char * out ,
413- unsigned long * outlen ,
414- prng_state * prng ,
415- int wprng ,
416- const ecc_key * key );
417-
418- int ecc_verify_hash_rfc5656 (const unsigned char * sig ,
419- unsigned long siglen ,
420- const unsigned char * hash ,
421- unsigned long hashlen ,
422- int * stat ,
423- const ecc_key * key );
424- #endif
425-
426- int ecc_sign_hash_eth27 (const unsigned char * in ,
427- unsigned long inlen ,
428- unsigned char * out ,
429- unsigned long * outlen ,
430- prng_state * prng ,
431- int wprng ,
432- const ecc_key * key );
433-
434- int ecc_verify_hash_eth27 (const unsigned char * sig ,
435- unsigned long siglen ,
436- const unsigned char * hash ,
437- unsigned long hashlen ,
438- int * stat ,
439- const ecc_key * key );
464+ #endif /* LTC_NO_DEPRECATED_APIS */
440465
441466int ecc_recover_key (const unsigned char * sig ,
442467 unsigned long siglen ,
443468 const unsigned char * hash ,
444469 unsigned long hashlen ,
445- int recid ,
446- ecc_signature_type sigformat ,
470+ ltc_ecc_sig_opts * opts ,
447471 ecc_key * key );
448472
449473#endif
0 commit comments