@@ -281,20 +281,10 @@ typedef struct {
281281
282282 /** The private key */
283283 void * k ;
284-
285- /** The hash algorithm to use when creating a signature.
286- * Setting this will enable RFC6979 compatible signature generation.
287- * The macro ECC_SET_RFC6979_HASH_ALG() is provided as a helper
288- * to set this.*/
289- const char * rfc6979_hash_alg ;
290284} ecc_key ;
291285
292- #define ECC_SET_RFC6979_HASH_ALG (key , alg ) do { \
293- (key)->rfc6979_hash_alg = (alg); \
294- } while(0)
295-
296286/** Formats of ECC signatures */
297- typedef enum ecc_signature_type_ {
287+ typedef enum ecc_signature_type {
298288 /* ASN.1 encoded, ANSI X9.62 */
299289 LTC_ECCSIG_ANSIX962 = 0x0 ,
300290 /* raw R, S values */
@@ -305,6 +295,28 @@ typedef enum ecc_signature_type_ {
305295 LTC_ECCSIG_RFC5656 = 0x3 ,
306296} ecc_signature_type ;
307297
298+ typedef struct ltc_ecc_sig_opts {
299+ /** Signature type */
300+ ecc_signature_type type ;
301+ /** The PRNG to use.
302+ * This must be set in case deterministic signature generation
303+ * according to RFC6979 is not enabled.
304+ */
305+ prng_state * prng ;
306+ int wprng ;
307+
308+ /** Enable generation of a recovery ID.
309+ * This must be set in case one requires the recovery ID of a
310+ * signature operation.
311+ */
312+ int * recid ;
313+
314+ /** The hash algorithm to use when creating a signature.
315+ * Setting this will enable RFC6979 compatible signature generation.
316+ */
317+ const char * rfc6979_hash_alg ;
318+ } ltc_ecc_sig_opts ;
319+
308320/** the ECC params provided */
309321extern const ltc_ecc_curve ltc_ecc_curves [];
310322
@@ -340,6 +352,21 @@ int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_k
340352int ecc_shared_secret (const ecc_key * private_key , const ecc_key * public_key ,
341353 unsigned char * out , unsigned long * outlen );
342354
355+ int ecc_sign_hash_v2 (const unsigned char * in ,
356+ unsigned long inlen ,
357+ unsigned char * out ,
358+ unsigned long * outlen ,
359+ ltc_ecc_sig_opts * opts ,
360+ const ecc_key * key );
361+
362+ int ecc_verify_hash_v2 (const unsigned char * sig ,
363+ unsigned long siglen ,
364+ const unsigned char * hash ,
365+ unsigned long hashlen ,
366+ ltc_ecc_sig_opts * opts ,
367+ int * stat ,
368+ const ecc_key * key );
369+
343370#if defined(LTC_DER )
344371int ecc_encrypt_key (const unsigned char * in , unsigned long inlen ,
345372 unsigned char * out , unsigned long * outlen ,
@@ -349,7 +376,42 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
349376int ecc_decrypt_key (const unsigned char * in , unsigned long inlen ,
350377 unsigned char * out , unsigned long * outlen ,
351378 const ecc_key * key );
352-
379+ #endif /* LTC_DER */
380+
381+ #define ltc_ecc_sign_hash (i , il , o , ol , p , wp , k ) \
382+ ecc_sign_hash_v2(i, il, o, ol, \
383+ &(ltc_ecc_sig_opts){ \
384+ .type = LTC_ECCSIG_ANSIX962, \
385+ .prng = p, \
386+ .wprng = wp, \
387+ }, k)
388+ #define ltc_ecc_sign_hash_rfc7518 (i , il , o , ol , p , wp , k ) \
389+ ecc_sign_hash_v2(i, il, o, ol, \
390+ &(ltc_ecc_sig_opts){ \
391+ .type = LTC_ECCSIG_RFC7518, \
392+ .prng = p, \
393+ .wprng = wp, \
394+ }, k)
395+
396+ #define ltc_ecc_verify_hash (s , sl , h , hl , st , k ) \
397+ ecc_verify_hash_v2(s, sl, h, hl, \
398+ &(ltc_ecc_sig_opts){ \
399+ .type = LTC_ECCSIG_ANSIX962, \
400+ }, st, k)
401+ #define ltc_ecc_verify_hash_rfc7518 (s , sl , h , hl , st , k ) \
402+ ecc_verify_hash_v2(s, sl, h, hl, \
403+ &(ltc_ecc_sig_opts){ \
404+ .type = LTC_ECCSIG_RFC7518, \
405+ }, st, k)
406+
407+ #ifdef LTC_NO_DEPRECATED_APIS
408+ #define ecc_sign_hash ltc_ecc_sign_hash
409+ #define ecc_verify_hash ltc_ecc_verify_hash
410+ #define ecc_sign_hash_rfc7518 ltc_ecc_sign_hash_rfc7518
411+ #define ecc_verify_hash_rfc7518 ltc_ecc_verify_hash_rfc7518
412+ #else /* LTC_NO_DEPRECATED_APIS */
413+ #if defined(LTC_DER )
414+ LTC_DEPRECATED (ecc_sign_hash_v2 )
353415int ecc_sign_hash (const unsigned char * in ,
354416 unsigned long inlen ,
355417 unsigned char * out ,
@@ -358,14 +420,16 @@ int ecc_sign_hash(const unsigned char *in,
358420 int wprng ,
359421 const ecc_key * key );
360422
423+ LTC_DEPRECATED (ecc_verify_hash_v2 )
361424int ecc_verify_hash (const unsigned char * sig ,
362425 unsigned long siglen ,
363426 const unsigned char * hash ,
364427 unsigned long hashlen ,
365428 int * stat ,
366429 const ecc_key * key );
367- #endif
430+ #endif /* LTC_DER */
368431
432+ LTC_DEPRECATED (ecc_sign_hash_v2 )
369433int ecc_sign_hash_rfc7518 (const unsigned char * in ,
370434 unsigned long inlen ,
371435 unsigned char * out ,
@@ -374,60 +438,20 @@ int ecc_sign_hash_rfc7518(const unsigned char *in,
374438 int wprng ,
375439 const ecc_key * key );
376440
377- int ecc_sign_hash_rfc7518_ex (const unsigned char * in ,
378- unsigned long inlen ,
379- unsigned char * out ,
380- unsigned long * outlen ,
381- prng_state * prng ,
382- int wprng ,
383- int * recid ,
384- const ecc_key * key );
385-
441+ LTC_DEPRECATED (ecc_verify_hash_v2 )
386442int ecc_verify_hash_rfc7518 (const unsigned char * sig ,
387443 unsigned long siglen ,
388444 const unsigned char * hash ,
389445 unsigned long hashlen ,
390446 int * stat ,
391447 const ecc_key * key );
392-
393- #if defined(LTC_SSH )
394- int ecc_sign_hash_rfc5656 (const unsigned char * in ,
395- unsigned long inlen ,
396- unsigned char * out ,
397- unsigned long * outlen ,
398- prng_state * prng ,
399- int wprng ,
400- const ecc_key * key );
401-
402- int ecc_verify_hash_rfc5656 (const unsigned char * sig ,
403- unsigned long siglen ,
404- const unsigned char * hash ,
405- unsigned long hashlen ,
406- int * stat ,
407- const ecc_key * key );
408- #endif
409-
410- int ecc_sign_hash_eth27 (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_eth27 (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 );
448+ #endif /* LTC_NO_DEPRECATED_APIS */
424449
425450int ecc_recover_key (const unsigned char * sig ,
426451 unsigned long siglen ,
427452 const unsigned char * hash ,
428453 unsigned long hashlen ,
429- int recid ,
430- ecc_signature_type sigformat ,
454+ ltc_ecc_sig_opts * opts ,
431455 ecc_key * key );
432456
433457#endif
0 commit comments