Browse Source

Finish up RFC6979 ECDSA keygen

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 4 months ago
parent
commit
46fa363f2c

+ 9 - 2
doc/crypt.tex

@@ -5816,6 +5816,7 @@ is important to check yourself before using the signatures.
 To sign a message digest (hash) use the following function:
 To sign a message digest (hash) use the following function:
 
 
 \index{ecc\_sign\_hash()}
 \index{ecc\_sign\_hash()}
+\index{ECC\_SET\_RFC6979\_HASH\_ALG()}
 \begin{verbatim}
 \begin{verbatim}
 int ecc_sign_hash(const unsigned char *in,
 int ecc_sign_hash(const unsigned char *in,
                         unsigned long  inlen,
                         unsigned long  inlen,
@@ -5830,8 +5831,14 @@ This function will \textit{ECDSA} sign the message digest stored in the array po
 will be stored in the array pointed to by \code{out} of length \code{outlen} octets.  The function requires that the \textit{ECC}
 will be stored in the array pointed to by \code{out} of length \code{outlen} octets.  The function requires that the \textit{ECC}
 \code{key} provided must be a private key.
 \code{key} provided must be a private key.
 
 
-It requires a properly seeded \textit{PRNG} for standard \textit{ECDSA}, or if \code{prng} is NULL and/or \code{wprng} is less than zero,
-the private key and the message itself will be used to create a deterministic signature according to \textit{RFC6979}.
+In order to execute standard \textit{ECDSA} it requires a properly seeded \textit{PRNG}  which gets passed via \code{prng} and \code{wprng}.
+
+The deterministic signature mechanism according to \textit{RFC6979} is also supported. This does not require a \textit{PRNG}, but
+instead a valid hash function shall be set via the macro
+
+\code{ECC\_SET\_RFC6979\_HASH\_ALG(key, hash\_alg)}
+
+The expected types of the arguments to that macro are \code{(ecc\_key*, const char*)}.
 
 
 \index{ecc\_sign\_hash\_rfc7518()}
 \index{ecc\_sign\_hash\_rfc7518()}
 \begin{verbatim}
 \begin{verbatim}

+ 10 - 1
src/headers/tomcrypt_pk.h

@@ -281,8 +281,18 @@ typedef struct {
 
 
     /** The private key */
     /** The private key */
     void *k;
     void *k;
+
+    /** The hash algorithm to use when creating a signature.
+     *  Setting this will enable RFC6979 compatible signature generation.
+     *  The macro ECC_SET_RFC6979_HASH_ALG() is provided as a helper
+     *  to set this.*/
+    const char *rfc6979_hash_alg;
 } ecc_key;
 } ecc_key;
 
 
+#define ECC_SET_RFC6979_HASH_ALG(key, alg) do { \
+   (key)->rfc6979_hash_alg = (alg);             \
+} while(0)
+
 /** Formats of ECC signatures */
 /** Formats of ECC signatures */
 typedef enum ecc_signature_type_ {
 typedef enum ecc_signature_type_ {
    /* ASN.1 encoded, ANSI X9.62 */
    /* ASN.1 encoded, ANSI X9.62 */
@@ -304,7 +314,6 @@ int  ecc_get_size(const ecc_key *key);
 int  ecc_find_curve(const char* name_or_oid, const ltc_ecc_curve** cu);
 int  ecc_find_curve(const char* name_or_oid, const ltc_ecc_curve** cu);
 int  ecc_set_curve(const ltc_ecc_curve *cu, ecc_key *key);
 int  ecc_set_curve(const ltc_ecc_curve *cu, ecc_key *key);
 int  ecc_generate_key(prng_state *prng, int wprng, ecc_key *key);
 int  ecc_generate_key(prng_state *prng, int wprng, ecc_key *key);
-int  ecc_rfc6979_key(const ecc_key *priv, const unsigned char *in, int inlen, ecc_key *key);
 int  ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key *key);
 int  ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key *key);
 int  ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
 int  ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
 int  ecc_get_oid_str(char *out, unsigned long *outlen, const ecc_key *key);
 int  ecc_get_oid_str(char *out, unsigned long *outlen, const ecc_key *key);

+ 2 - 0
src/headers/tomcrypt_private.h

@@ -441,6 +441,8 @@ int ecc_verify_hash_internal(void *r, void *s,
                              const unsigned char *hash, unsigned long hashlen,
                              const unsigned char *hash, unsigned long hashlen,
                              int *stat, const ecc_key *key);
                              int *stat, const ecc_key *key);
 
 
+int ecc_rfc6979_key(const ecc_key *priv, const unsigned char *in, unsigned long inlen, ecc_key *key);
+
 #ifdef LTC_SSH
 #ifdef LTC_SSH
 int ecc_ssh_ecdsa_encode_name(char *buffer, unsigned long *buflen, const ecc_key *key);
 int ecc_ssh_ecdsa_encode_name(char *buffer, unsigned long *buflen, const ecc_key *key);
 #endif
 #endif

+ 1 - 0
src/pk/ecc/ecc_make_key.c

@@ -59,6 +59,7 @@ int ecc_generate_key(prng_state *prng, int wprng, ecc_key *key)
       goto error;
       goto error;
    }
    }
    key->type = PK_PRIVATE;
    key->type = PK_PRIVATE;
+   key->rfc6979_hash_alg = NULL;
 
 
    /* success */
    /* success */
    err = CRYPT_OK;
    err = CRYPT_OK;

+ 86 - 67
src/pk/ecc/ecc_rfc6979_key.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 #include "tomcrypt_private.h"
 #include "tomcrypt_private.h"
 
 
@@ -25,99 +19,127 @@
   @param key          [out] Newly created deterministic key
   @param key          [out] Newly created deterministic key
   @return CRYPT_OK if successful, upon error all allocated memory will be freed
   @return CRYPT_OK if successful, upon error all allocated memory will be freed
 */
 */
-int ecc_rfc6979_key(const ecc_key *priv, const unsigned char *in, int inlen, ecc_key *key)
+int ecc_rfc6979_key(const ecc_key *priv, const unsigned char *in, unsigned long inlen, ecc_key *key)
 {
 {
-   int            err, hash, i;
-   unsigned char  v[32], k[32], digest[32]; /* No way to determine hash so always use SHA256 */
-   unsigned char  buffer[256];
-   unsigned long  outlen, buflen, qlen;
+   int            err, hash = -1;
+   unsigned char  v[MAXBLOCKSIZE], k[MAXBLOCKSIZE];
+   unsigned char  buffer[256], sep[1], privkey[128];
+   unsigned long  order_bits, len_diff, pk_len, zero_extend, outlen, klen, vlen, buflen, qlen, hashsize;
+   void *r, *d;
 
 
    LTC_ARGCHK(ltc_mp.name != NULL);
    LTC_ARGCHK(ltc_mp.name != NULL);
+   LTC_ARGCHK(priv        != NULL);
    LTC_ARGCHK(key         != NULL);
    LTC_ARGCHK(key         != NULL);
    LTC_ARGCHK(key->dp.size > 0);
    LTC_ARGCHK(key->dp.size > 0);
 
 
-   hash = find_hash("sha256");
-   if (hash == -1) {err = CRYPT_ERROR; goto error;}
+   if (priv->rfc6979_hash_alg == NULL) {
+      return CRYPT_INVALID_ARG;
+   }
+   hash = find_hash(priv->rfc6979_hash_alg);
+   if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+      return err;
+   }
+
+   hashsize = hash_descriptor[hash].hashsize;
+
+   if ((err = ltc_mp_init_multi(&r, &d, NULL)) != CRYPT_OK) {
+      return err;
+   }
 
 
    /* Length, in bytes, of key */
    /* Length, in bytes, of key */
-   i = mp_count_bits(key->dp.order);
-   qlen = (i+7) >> 3;
+   order_bits = ltc_mp_count_bits(key->dp.order);
+   qlen = (order_bits+7) >> 3;
+   len_diff = qlen > inlen ? qlen - inlen : 0;
+   pk_len = (ltc_mp_count_bits(priv->k)+7) >> 3;
+   zero_extend = qlen - pk_len;
+   XMEMSET(buffer, 0x00, len_diff + zero_extend);
 
 
    /* RFC6979 3.2b, set V */
    /* RFC6979 3.2b, set V */
-   for (i=0; i<32; i++) v[i] = 0x01;
+   XMEMSET(v, 0x01, hashsize);
 
 
    /* RFC6979 3.2c, set K */
    /* RFC6979 3.2c, set K */
-   for (i=0; i<32; i++) k[i] = 0x00;
+   XMEMSET(k, 0x00, hashsize);
 
 
+   if ((err = ltc_mp_to_unsigned_bin(priv->k, privkey) != CRYPT_OK))                                     { goto error; }
    /* RFC6979 3.2d, set K to HMAC_K(V::0x00::priv::in) */
    /* RFC6979 3.2d, set K to HMAC_K(V::0x00::priv::in) */
-   XMEMCPY(&buffer[0], v, 32);
-   buffer[32] = 0x00;
-   if ((err = mp_to_unsigned_bin(priv->k, &buffer[33]) != CRYPT_OK))                                   { goto error; }
-   XMEMCPY(&buffer[33+qlen], in, inlen);
-   buflen = 32 + 1 + qlen + inlen;
-   outlen = sizeof(digest);
-   if((err = hmac_memory(hash, k, 32, buffer, buflen, digest, &outlen)) != CRYPT_OK)                   { goto error; }
-   XMEMCPY(k, digest, 32);
+   sep[0] = 0;
+   klen = sizeof(k);
+   if((err = hmac_memory_multi(hash,
+                               k, hashsize,
+                               k, &klen,
+                               v, hashsize,
+                               sep, 1,
+                               buffer, zero_extend,
+                               privkey, qlen - zero_extend,
+                               buffer, len_diff,
+                               in, qlen - len_diff,
+                               LTC_NULL)) != CRYPT_OK)                                                   { goto error; }
 
 
    /* RFC6979 3.2e, set V = HMAC_K(V) */
    /* RFC6979 3.2e, set V = HMAC_K(V) */
-   outlen = sizeof(digest);
-   if((err = hmac_memory(hash, k, 32, v, 32, digest, &outlen)) != CRYPT_OK)                            { goto error; }
-   XMEMCPY(v, digest, 32);
+   vlen = sizeof(v);
+   if((err = hmac_memory(hash, k, klen, v, hashsize, v, &vlen)) != CRYPT_OK)                             { goto error; }
 
 
    /* RFC6979 3.2f, set K to HMAC_K(V::0x01::priv::in) */
    /* RFC6979 3.2f, set K to HMAC_K(V::0x01::priv::in) */
-   XMEMCPY(&buffer[0], v, 32);
-   buffer[32] = 0x01;
-   if ((err = mp_to_unsigned_bin(priv->k, &buffer[33]) != CRYPT_OK))                                   { goto error; }
-   XMEMCPY(&buffer[33+qlen], in, inlen);
-   buflen = 32 + 1 + qlen + inlen;
-   outlen = sizeof(digest);
-   if((err = hmac_memory(hash, k, 32, buffer, buflen, digest, &outlen)) != CRYPT_OK)                   { goto error; }
-   XMEMCPY(k, digest, 32);
+   sep[0] = 0x01;
+   outlen = sizeof(k);
+   if((err = hmac_memory_multi(hash,
+                               k, klen,
+                               k, &klen,
+                               v, hashsize,
+                               sep, 1,
+                               buffer, zero_extend,
+                               privkey, qlen - zero_extend,
+                               buffer, len_diff,
+                               in, qlen - len_diff,
+                               LTC_NULL)) != CRYPT_OK)                                                   { goto error; }
 
 
    /* RFC6979 3.2g, set V = HMAC_K(V) */
    /* RFC6979 3.2g, set V = HMAC_K(V) */
-   outlen = sizeof(digest);
-   if((err = hmac_memory(hash, k, 32, v, 32, digest, &outlen)) != CRYPT_OK)                            { goto error; }
-   XMEMCPY(v, digest, 32);
+   outlen = sizeof(v);
+   if((err = hmac_memory(hash, k, klen, v, hashsize, v, &outlen)) != CRYPT_OK)                           { goto error; }
 
 
    /* RFC6979 3.2h, generate and check key */
    /* RFC6979 3.2h, generate and check key */
    do {
    do {
       /* concatenate hash bits into T */
       /* concatenate hash bits into T */
       buflen = 0;
       buflen = 0;
       while (buflen < qlen) {
       while (buflen < qlen) {
-         outlen = sizeof(digest);
-         if((err = hmac_memory(hash, k, 32, v, 32, digest, &outlen)) != CRYPT_OK)                      { goto error; }
-         XMEMCPY(v, digest, 32);
-         XMEMCPY(&buffer[buflen], v, 32);
-         buflen += 32;
+         if (buflen + hashsize >= sizeof(buffer) || buflen + hashsize < buflen) {
+            err = CRYPT_BUFFER_OVERFLOW;
+            goto error;
+         }
+         outlen = sizeof(v);
+         if((err = hmac_memory(hash, k, klen, v, hashsize, v, &outlen)) != CRYPT_OK)                     { goto error; }
+         XMEMCPY(&buffer[buflen], v, hashsize);
+         buflen += hashsize;
       }
       }
 
 
       /* key->k = bits2int(T) */
       /* key->k = bits2int(T) */
-      if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)buffer, qlen)) != CRYPT_OK)             { goto error; }
-
-      /* make the public key */
-      if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, key->dp.A, key->dp.prime, 1)) != CRYPT_OK) {
-         goto error;
+      if ((err = ltc_mp_read_unsigned_bin(r, buffer, qlen)) != CRYPT_OK)                                 { goto error; }
+      if ((qlen * 8) > order_bits) {
+         if ((err = ltc_mp_2expt(d, (qlen * 8) - order_bits)) != CRYPT_OK)                               { goto error; }
+         if ((err = ltc_mp_div(r, d, r, NULL)) != CRYPT_OK)                                              { goto error; }
+         if ((err = ltc_mp_to_unsigned_bin(r, buffer)) != CRYPT_OK)                                      { goto error; }
+         qlen = ltc_mp_unsigned_bin_size(r);
       }
       }
 
 
+      if ((err = ecc_set_key(buffer, qlen, PK_PRIVATE, key))!= CRYPT_OK)                                 { goto error; }
+
       /* check that k is in range [1,q-1] */
       /* check that k is in range [1,q-1] */
-      if (mp_cmp_d(key->k, 0) == LTC_MP_GT && mp_cmp(key->k, key->dp.order) == LTC_MP_LT) {
-         /* TODO: Check that pubkey.x != 0 (mod p) */
+      if (ltc_mp_cmp_d(key->k, 0) == LTC_MP_GT && ltc_mp_cmp(key->k, key->dp.order) == LTC_MP_LT) {
+         /* Check that pubkey.x != 0 (mod p) */
+         if ((err = ltc_mp_mod(key->pubkey.x, key->dp.order, r)) != CRYPT_OK)                            { goto error; }
 
 
          /* if we have a valid key, exit loop */
          /* if we have a valid key, exit loop */
-         break;
+         if (ltc_mp_iszero(r) == LTC_MP_NO)
+            break;
       } else {
       } else {
          /* K = HMAC_K(V::0x00) */
          /* K = HMAC_K(V::0x00) */
-         XMEMCPY(&buffer[0], v, 32);
-         buffer[32] = 0x00;
-         buflen = 32 + 1;
-         outlen = sizeof(digest);
-         if((err = hmac_memory(hash, k, 32, buffer, buflen, digest, &outlen)) != CRYPT_OK)             { goto error; }
-         XMEMCPY(k, digest, 32);
+         buffer[0] = 0x0;
+         outlen = sizeof(k);
+         if((err = hmac_memory_multi(hash, k, klen, k, &klen, v, hashsize, buffer, 1, LTC_NULL)) != CRYPT_OK)  { goto error; }
 
 
          /* V = HMAC_K(V) */
          /* V = HMAC_K(V) */
-         outlen = sizeof(digest);
-         if((err = hmac_memory(hash, k, 32, v, 32, digest, &outlen)) != CRYPT_OK)                      { goto error; }
-         XMEMCPY(v, digest, 32);
+         outlen = sizeof(v);
+         if((err = hmac_memory(hash, k, klen, v, hashsize, v, &outlen)) != CRYPT_OK)                           { goto error; }
 
 
          /* ... and try again! */
          /* ... and try again! */
       }
       }
@@ -132,12 +154,9 @@ int ecc_rfc6979_key(const ecc_key *priv, const unsigned char *in, int inlen, ecc
 error:
 error:
    ecc_free(key);
    ecc_free(key);
 cleanup:
 cleanup:
+   ltc_mp_cleanup_multi(&d, &r, NULL);
    return err;
    return err;
 }
 }
 
 
 #endif
 #endif
 #endif
 #endif
-/* ref:         $Format:%D$ */
-/* git commit:  $Format:%H$ */
-/* commit time: $Format:%ai$ */
-

+ 2 - 0
src/pk/ecc/ecc_set_curve.c

@@ -19,6 +19,8 @@ int ecc_set_curve(const ltc_ecc_curve *cu, ecc_key *key)
       return err;
       return err;
    }
    }
 
 
+   key->rfc6979_hash_alg = NULL;
+
    /* A, B, order, prime, Gx, Gy */
    /* A, B, order, prime, Gx, Gy */
    if ((err = ltc_mp_read_radix(key->dp.prime, cu->prime, 16)) != CRYPT_OK) { goto error; }
    if ((err = ltc_mp_read_radix(key->dp.prime, cu->prime, 16)) != CRYPT_OK) { goto error; }
    if ((err = ltc_mp_read_radix(key->dp.order, cu->order, 16)) != CRYPT_OK) { goto error; }
    if ((err = ltc_mp_read_radix(key->dp.order, cu->order, 16)) != CRYPT_OK) { goto error; }

+ 2 - 1
src/pk/ecc/ecc_set_key.c

@@ -33,7 +33,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
    else if (type == PK_PUBLIC) {
    else if (type == PK_PUBLIC) {
       /* load public key */
       /* load public key */
       if ((err = ltc_ecc_import_point(in, inlen, prime, a, b, key->pubkey.x, key->pubkey.y)) != CRYPT_OK) { goto error; }
       if ((err = ltc_ecc_import_point(in, inlen, prime, a, b, key->pubkey.x, key->pubkey.y)) != CRYPT_OK) { goto error; }
-      if ((err = ltc_mp_set(key->pubkey.z, 1)) != CRYPT_OK)                                                   { goto error; }
+      if ((err = ltc_mp_set(key->pubkey.z, 1)) != CRYPT_OK)                                               { goto error; }
    }
    }
    else {
    else {
       err = CRYPT_INVALID_PACKET;
       err = CRYPT_INVALID_PACKET;
@@ -46,6 +46,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
    }
    }
 
 
    key->type = type;
    key->type = type;
+   key->rfc6979_hash_alg = NULL;
    return CRYPT_OK;
    return CRYPT_OK;
 
 
 error:
 error:

+ 2 - 4
src/pk/ecc/ecc_sign_hash.c

@@ -11,10 +11,8 @@
   @param inlen     The length of the digest
   @param inlen     The length of the digest
   @param out       [out] The destination for the signature
   @param out       [out] The destination for the signature
   @param outlen    [in/out] The max size and resulting size of the signature
   @param outlen    [in/out] The max size and resulting size of the signature
-  @param prng      An active PRNG state, NULL for RFC6979 deterministic signatures
-  @param wprng     The index of the PRNG you wish to use, -1 for RFC6979 deterministic signatures
-  @param sigformat The format of the signature to generate (ecc_signature_type)
-  @param recid     [out] The recovery ID for this signature (optional)
+  @param prng      An active PRNG state
+  @param wprng     The index of the PRNG you wish to use
   @param key       A private ECC key
   @param key       A private ECC key
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */

+ 7 - 3
src/pk/ecc/ecc_sign_hash_internal.c

@@ -57,8 +57,12 @@ int ecc_sign_hash_internal(const unsigned char *in,  unsigned long inlen,
 
 
    /* make up a key and export the public copy */
    /* make up a key and export the public copy */
    do {
    do {
-      if ((err = ecc_copy_curve(key, &pubkey)) != CRYPT_OK)                { goto errnokey; }
-      if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK)      { goto errnokey; }
+      if ((err = ecc_copy_curve(key, &pubkey)) != CRYPT_OK)                    { goto errnokey; }
+      if (key->rfc6979_hash_alg != NULL) {
+         if ((err = ecc_rfc6979_key(key, in, inlen, &pubkey)) != CRYPT_OK)     { goto errnokey; }
+      } else {
+         if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK)       { goto errnokey; }
+      }
 
 
       /* find r = x1 mod n */
       /* find r = x1 mod n */
       if ((err = ltc_mp_mod(pubkey.pubkey.x, p, r)) != CRYPT_OK)               { goto error; }
       if ((err = ltc_mp_mod(pubkey.pubkey.x, p, r)) != CRYPT_OK)               { goto error; }
@@ -78,7 +82,7 @@ int ecc_sign_hash_internal(const unsigned char *in,  unsigned long inlen,
       if (ltc_mp_iszero(r) == LTC_MP_YES) {
       if (ltc_mp_iszero(r) == LTC_MP_YES) {
          ecc_free(&pubkey);
          ecc_free(&pubkey);
       } else {
       } else {
-         if ((err = rand_bn_upto(b, p, prng, wprng)) != CRYPT_OK)          { goto error; } /* b = blinding value */
+         if ((err = rand_bn_upto(b, p, prng, wprng)) != CRYPT_OK)              { goto error; } /* b = blinding value */
          /* find s = (e + xr)/k */
          /* find s = (e + xr)/k */
          if ((err = ltc_mp_mulmod(pubkey.k, b, p, pubkey.k)) != CRYPT_OK)      { goto error; } /* k = kb */
          if ((err = ltc_mp_mulmod(pubkey.k, b, p, pubkey.k)) != CRYPT_OK)      { goto error; } /* k = kb */
          if ((err = ltc_mp_invmod(pubkey.k, p, pubkey.k)) != CRYPT_OK)         { goto error; } /* k = 1/kb */
          if ((err = ltc_mp_invmod(pubkey.k, p, pubkey.k)) != CRYPT_OK)         { goto error; } /* k = 1/kb */

+ 383 - 9
tests/ecc_test.c

@@ -642,15 +642,6 @@ static int s_ecc_new_api(void)
       }
       }
 #endif
 #endif
 
 
-#ifdef LTC_SHA256
-      /* test RFC6979 signature */
-      len = sizeof(buf);
-      DO(ecc_sign_hash(data16, 16, buf, &len, NULL, -1, &privkey));
-      stat = 0;
-      DO(ecc_verify_hash(buf, len, data16, 16, &stat, &pubkey));
-      if (stat != 1) return CRYPT_FAIL_TESTVECTOR;
-#endif
-
       /* test encryption */
       /* test encryption */
       len = sizeof(buf);
       len = sizeof(buf);
       DO(ecc_encrypt_key(data16, 16, buf, &len, &yarrow_prng, find_prng("yarrow"), find_hash("sha256"), &pubkey));
       DO(ecc_encrypt_key(data16, 16, buf, &len, &yarrow_prng, find_prng("yarrow"), find_hash("sha256"), &pubkey));
@@ -667,6 +658,388 @@ static int s_ecc_new_api(void)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+static int s_ecc_rfc6979(void)
+{
+   const struct {
+      const char *curve, *x, *Ux, *Uy;
+      struct {
+         const char *k, *r, *s;
+      } signatures[11];
+   } tests[] = {
+                {
+                 "P-192",
+                 "6FAB034934E4C0FC9AE67F5B5659A9D7D1FEFD187EE09FD4",
+                 "AC2C77F529F91689FEA0EA5EFEC7F210D8EEA0B9E047ED56",
+                 "3BC723E57670BD4887EBC732C523063D0A7C957BC97C1C43",
+                 {
+                  {
+                   "37D7CA00D2C7B0E5E412AC03BD44BA837FDD5B28CD3B0021",
+                   "98C6BD12B23EAF5E2A2045132086BE3EB8EBD62ABF6698FF",
+                   "57A22B07DEA9530F8DE9471B1DC6624472E8E2844BC25B64",
+                  },
+                  {
+                   "4381526B3FC1E7128F202E194505592F01D5FF4C5AF015D8",
+                   "A1F00DAD97AEEC91C95585F36200C65F3C01812AA60378F5",
+                   "E07EC1304C7C6C9DEBBE980B9692668F81D4DE7922A0F97A",
+                  },
+                  {
+                   "32B1B6D7D42A05CB449065727A84804FB1A3E34D8F261496",
+                   "4B0B8CE98A92866A2820E20AA6B75B56382E0F9BFD5ECB55",
+                   "CCDB006926EA9565CBADC840829D8C384E06DE1F1E381B85",
+                  },
+                  {
+                   "4730005C4FCB01834C063A7B6760096DBE284B8252EF4311",
+                   "DA63BF0B9ABCF948FBB1E9167F136145F7A20426DCC287D5",
+                   "C3AA2C960972BD7A2003A57E1C4C77F0578F8AE95E31EC5E",
+                  },
+                  {
+                   "A2AC7AB055E4F20692D49209544C203A7D1F2C0BFBC75DB1",
+                   "4D60C5AB1996BD848343B31C00850205E2EA6922DAC2E4B8",
+                   "3F6E837448F027A1BF4B34E796E32A811CBB4050908D8F67",
+                  },
+                  {
+                   "D9CF9C3D3297D3260773A1DA7418DB5537AB8DD93DE7FA25",
+                   "0F2141A0EBBC44D2E1AF90A50EBCFCE5E197B3B7D4DE036D",
+                   "EB18BC9E1F3D7387500CB99CF5F7C157070A8961E38700B7",
+                  },
+                  {
+                   "F5DC805F76EF851800700CCE82E7B98D8911B7D510059FBE",
+                   "6945A1C1D1B2206B8145548F633BB61CEF04891BAF26ED34",
+                   "B7FB7FDFC339C0B9BD61A9F5A8EAF9BE58FC5CBA2CB15293",
+                  },
+                  {
+                   "5C4CE89CF56D9E7C77C8585339B006B97B5F0680B4306C6C",
+                   "3A718BD8B4926C3B52EE6BBE67EF79B18CB6EB62B1AD97AE",
+                   "5662E6848A4A19B1F1AE2F72ACD4B8BBE50F1EAC65D9124F",
+                  },
+                  {
+                   "5AFEFB5D3393261B828DB6C91FBC68C230727B030C975693",
+                   "B234B60B4DB75A733E19280A7A6034BD6B1EE88AF5332367",
+                   "7994090B2D59BB782BE57E74A44C9A1C700413F8ABEFE77A",
+                  },
+                  {
+                   "0758753A5254759C7CFBAD2E2D9B0792EEE44136C9480527",
+                   "FE4F4AE86A58B6507946715934FE2D8FF9D95B6B098FE739",
+                   "74CF5605C98FBA0E1EF34D4B5A1577A7DCF59457CAE52290",
+                  },
+                  {
+                   NULL, NULL, NULL
+                  }
+                 }
+                },
+                {
+                 "P-224",
+                 "F220266E1105BFE3083E03EC7A3A654651F45E37167E88600BF257C1",
+                 "CF08DA5AD719E42707FA431292DEA11244D64FC51610D94B130D6C",
+                 "EEAB6F3DEBE455E3DBF85416F7030CBD94F34F2D6F232C69F3C1385A",
+                 {
+                  {
+                   "7EEFADD91110D8DE6C2C470831387C50D3357F7F4D477054B8B426BC",
+                   "22226F9D40A96E19C4A301CE5B74B115303C0F3A4FD30FC257FB57AC",
+                   "66D1CDD83E3AF75605DD6E2FEFF196D30AA7ED7A2EDF7AF475403D69",
+                  },
+                  {
+                   "C1D1F2F10881088301880506805FEB4825FE09ACB6816C36991AA06D",
+                   "1CDFE6662DDE1E4A1EC4CDEDF6A1F5A2FB7FBD9145C12113E6ABFD3E",
+                   "A6694FD7718A21053F225D3F46197CA699D45006C06F871808F43EBC",
+                  },
+                  {
+                   "AD3029E0278F80643DE33917CE6908C70A8FF50A411F06E41DEDFCDC",
+                   "61AA3DA010E8E8406C656BC477A7A7189895E7E840CDFE8FF42307BA",
+                   "BC814050DAB5D23770879494F9E0A680DC1AF7161991BDE692B10101",
+                  },
+                  {
+                   "52B40F5A9D3D13040F494E83D3906C6079F29981035C7BD51E5CAC40",
+                   "0B115E5E36F0F9EC81F1325A5952878D745E19D7BB3EABFABA77E953",
+                   "830F34CCDFE826CCFDC81EB4129772E20E122348A2BBD889A1B1AF1D",
+                  },
+                  {
+                   "9DB103FFEDEDF9CFDBA05184F925400C1653B8501BAB89CEA0FBEC14",
+                   "074BD1D979D5F32BF958DDC61E4FB4872ADCAFEB2256497CDAC30397",
+                   "A4CECA196C3D5A1FF31027B33185DC8EE43F288B21AB342E5D8EB084",
+                  },
+                  {
+                   "2519178F82C3F0E4F87ED5883A4E114E5B7A6E374043D8EFD329C253",
+                   "DEAA646EC2AF2EA8AD53ED66B2E2DDAA49A12EFD8356561451F3E21C",
+                   "95987796F6CF2062AB8135271DE56AE55366C045F6D9593F53787BD2",
+                  },
+                  {
+                   "DF8B38D40DCA3E077D0AC520BF56B6D565134D9B5F2EAE0D34900524",
+                   "C441CE8E261DED634E4CF84910E4C5D1D22C5CF3B732BB204DBEF019",
+                   "902F42847A63BDC5F6046ADA114953120F99442D76510150F372A3F4",
+                  },
+                  {
+                   "FF86F57924DA248D6E44E8154EB69F0AE2AEBAEE9931D0B5A969F904",
+                   "AD04DDE87B84747A243A631EA47A1BA6D1FAA059149AD2440DE6FBA6",
+                   "178D49B1AE90E3D8B629BE3DB5683915F4E8C99FDF6E666CF37ADCFD",
+                  },
+                  {
+                   "7046742B839478C1B5BD31DB2E862AD868E1A45C863585B5F22BDC2D",
+                   "389B92682E399B26518A95506B52C03BC9379A9DADF3391A21FB0EA4",
+                   "414A718ED3249FF6DBC5B50C27F71F01F070944DA22AB1F78F559AAB",
+                  },
+                  {
+                   "E39C2AA4EA6BE2306C72126D40ED77BF9739BB4D6EF2BBB1DCB6169D",
+                   "049F050477C5ADD858CAC56208394B5A55BAEBBE887FDF765047C17C",
+                   "077EB13E7005929CEFA3CD0403C7CDCC077ADF4E44F3C41B2F60ECFF",
+                  },
+                  {
+                   NULL, NULL, NULL
+                  }
+                 }
+                },
+                {
+                 "P-256",
+                 "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721",
+                 "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6",
+                 "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299",
+                 {
+                  {
+                   "882905F1227FD620FBF2ABF21244F0BA83D0DC3A9103DBBEE43A1FB858109DB4",
+                   "61340C88C3AAEBEB4F6D667F672CA9759A6CCAA9FA8811313039EE4A35471D32",
+                   "6D7F147DAC089441BB2E2FE8F7A3FA264B9C475098FDCF6E00D7C996E1B8B7EB",
+                  },
+                  {
+                   "103F90EE9DC52E5E7FB5132B7033C63066D194321491862059967C715985D473",
+                   "53B2FFF5D1752B2C689DF257C04C40A587FABABB3F6FC2702F1343AF7CA9AA3F",
+                   "B9AFB64FDC03DC1A131C7D2386D11E349F070AA432A4ACC918BEA988BF75C74C",
+                  },
+                  {
+                   "A6E3C57DD01ABE90086538398355DD4C3B17AA873382B0F24D6129493D8AAD60",
+                   "EFD48B2AACB6A8FD1140DD9CD45E81D69D2C877B56AAF991C34D0EA84EAF3716",
+                   "F7CB1C942D657C41D436C7A1B6E29F65F3E900DBB9AFF4064DC4AB2F843ACDA8",
+                  },
+                  {
+                   "09F634B188CEFD98E7EC88B1AA9852D734D0BC272F7D2A47DECC6EBEB375AAD4",
+                   "0EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719",
+                   "4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954",
+                  },
+                  {
+                   "5FA81C63109BADB88C1F367B47DA606DA28CAD69AA22C4FE6AD7DF73A7173AA5",
+                   "8496A60B5E9B47C825488827E0495B0E3FA109EC4568FD3F8D1097678EB97F00",
+                   "2362AB1ADBE2B8ADF9CB9EDAB740EA6049C028114F2460F96554F61FAE3302FE",
+                  },
+                  {
+                   "8C9520267C55D6B980DF741E56B4ADEE114D84FBFA2E62137954164028632A2E",
+                   "0CBCC86FD6ABD1D99E703E1EC50069EE5C0B4BA4B9AC60E409E8EC5910D81A89",
+                   "01B9D7B73DFAA60D5651EC4591A0136F87653E0FD780C3B1BC872FFDEAE479B1",
+                  },
+                  {
+                   "669F4426F2688B8BE0DB3A6BD1989BDAEFFF84B649EEB84F3DD26080F667FAA7",
+                   "C37EDB6F0AE79D47C3C27E962FA269BB4F441770357E114EE511F662EC34A692",
+                   "C820053A05791E521FCAAD6042D40AEA1D6B1A540138558F47D0719800E18F2D",
+                  },
+                  {
+                   "D16B6AE827F17175E040871A1C7EC3500192C4C92677336EC2537ACAEE0008E0",
+                   "F1ABB023518351CD71D881567B1EA663ED3EFCF6C5132B354F28D3B0B7D38367",
+                   "019F4113742A2B14BD25926B49C649155F267E60D3814B4C0CC84250E46F0083",
+                  },
+                  {
+                   "16AEFFA357260B04B1DD199693960740066C1A8F3E8EDD79070AA914D361B3B8",
+                   "83910E8B48BB0C74244EBDF7F07A1C5413D61472BD941EF3920E623FBCCEBEB6",
+                   "8DDBEC54CF8CD5874883841D712142A56A8D0F218F5003CB0296B6B509619F2C",
+                  },
+                  {
+                   "6915D11632ACA3C40D5D51C08DAF9C555933819548784480E93499000D9F0B7F",
+                   "461D93F31B6540894788FD206C07CFA0CC35F46FA3C91816FFF1040AD1581A04",
+                   "39AF9F15DE0DB8D97E72719C74820D304CE5226E32DEDAE67519E840D1194E55",
+                  },
+                  {
+                   NULL, NULL, NULL
+                  }
+                 }
+                },
+                {
+                 "P-384",
+                 "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D896D5724E4C70A825F872C9EA60D2EDF5",
+                 "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64DEF8F0EA9055866064A254515480BC13",
+                 "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1288B231C3AE0D4FE7344FD2533264720",
+                 {
+                  {
+                   "4471EF7518BB2C7C20F62EAE1C387AD0C5E8E470995DB4ACF694466E6AB096630F29E5938D25106C3C340045A2DB01A7",
+                   "EC748D839243D6FBEF4FC5C4859A7DFFD7F3ABDDF72014540C16D73309834FA37B9BA002899F6FDA3A4A9386790D4EB2",
+                   "A3BCFA947BEEF4732BF247AC17F71676CB31A847B9FF0CBC9C9ED4C1A5B3FACF26F49CA031D4857570CCB5CA4424A443",
+                  },
+                  {
+                   "A4E4D2F0E729EB786B31FC20AD5D849E304450E0AE8E3E341134A5C1AFA03CAB8083EE4E3C45B06A5899EA56C51B5879",
+                   "42356E76B55A6D9B4631C865445DBE54E056D3B3431766D0509244793C3F9366450F76EE3DE43F5A125333A6BE060122",
+                   "9DA0C81787064021E78DF658F2FBB0B042BF304665DB721F077A4298B095E4834C082C03D83028EFBF93A3C23940CA8D",
+                  },
+                  {
+                   "180AE9F9AEC5438A44BC159A1FCB277C7BE54FA20E7CF404B490650A8ACC414E375572342863C899F9F2EDF9747A9B60",
+                   "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33BDE1E888E63355D92FA2B3C36D8FB2CD",
+                   "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEBEFDC63ECCD1AC42EC0CB8668A4FA0AB0",
+                  },
+                  {
+                   "94ED910D1A099DAD3254E9242AE85ABDE4BA15168EAF0CA87A555FD56D10FBCA2907E3E83BA95368623B8C4686915CF9",
+                   "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C81A648152E44ACF96E36DD1E80FABE46",
+                   "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94FA329C145786E679E7B82C71A38628AC8",
+                  },
+                  {
+                   "92FC3C7183A883E24216D1141F1A8976C5B0DD797DFA597E3D7B32198BD35331A4E966532593A52980D0E3AAA5E10EC3",
+                   "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799CFE30F35CC900056D7C99CD7882433709",
+                   "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112DC7CC3EF3446DEFCEB01A45C2667FDD5",
+                  },
+                  {
+                   "66CC2C8F4D303FC962E5FF6A27BD79F84EC812DDAE58CF5243B64A4AD8094D47EC3727F3A3C186C15054492E30698497",
+                   "4BC35D3A50EF4E30576F58CD96CE6BF638025EE624004A1F7789A8B8E43D0678ACD9D29876DAF46638645F7F404B11C7",
+                   "D5A6326C494ED3FF614703878961C0FDE7B2C278F9A65FD8C4B7186201A2991695BA1C84541327E966FA7B50F7382282",
+                  },
+                  {
+                   "18FA39DB95AA5F561F30FA3591DC59C0FA3653A80DAFFA0B48D1A4C6DFCBFF6E3D33BE4DC5EB8886A8ECD093F2935726",
+                   "E8C9D0B6EA72A0E7837FEA1D14A1A9557F29FAA45D3E7EE888FC5BF954B5E62464A9A817C47FF78B8C11066B24080E72",
+                   "07041D4A7A0379AC7232FF72E6F77B6DDB8F09B16CCE0EC3286B2BD43FA8C6141C53EA5ABEF0D8231077A04540A96B66",
+                  },
+                  {
+                   "0CFAC37587532347DC3389FDC98286BBA8C73807285B184C83E62E26C401C0FAA48DD070BA79921A3457ABFF2D630AD7",
+                   "6D6DEFAC9AB64DABAFE36C6BF510352A4CC27001263638E5B16D9BB51D451559F918EEDAF2293BE5B475CC8F0188636B",
+                   "2D46F3BECBCC523D5F1A1256BF0C9B024D879BA9E838144C8BA6BAEB4B53B47D51AB373F9845C0514EEFB14024787265",
+                  },
+                  {
+                   "015EE46A5BF88773ED9123A5AB0807962D193719503C527B031B4C2D225092ADA71F4A459BC0DA98ADB95837DB8312EA",
+                   "8203B63D3C853E8D77227FB377BCF7B7B772E97892A80F36AB775D509D7A5FEB0542A7F0812998DA8F1DD3CA3CF023DB",
+                   "DDD0760448D42D8A43AF45AF836FCE4DE8BE06B485E9B61B827C2F13173923E06A739F040649A667BF3B828246BAA5A5",
+                  },
+                  {
+                   "3780C4F67CB15518B6ACAE34C9F83568D2E12E47DEAB6C50A4E4EE5319D1E8CE0E2CC8A136036DC4B9C00E6888F66B6C",
+                   "A0D5D090C9980FAF3C2CE57B7AE951D31977DD11C775D314AF55F76C676447D06FB6495CD21B4B6E340FC236584FB277",
+                   "976984E59B4C77B0E8E4460DCA3D9F20E07B9BB1F63BEEFAF576F6B2E8B224634A2092CD3792E0159AD9CEE37659C736",
+                  },
+                  {
+                   NULL, NULL, NULL
+                  }
+                 }
+                },
+                {
+                 "P-521",
+                 "00FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75CAA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83538",
+                 "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD371123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F5023A4",
+                 "493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A28A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDFCF5",
+                 {
+                  {
+                   "89C071B419E1C2820962321787258469511958E80582E95D8378E0C2CCDB3CB42BEDE42F50E3FA3C71F5A76724281D31D9C89F0F91FC1BE4918DB1C03A5838D0F9",
+                   "00343B6EC45728975EA5CBA6659BBB6062A5FF89EEA58BE3C80B619F322C87910FE092F7D45BB0F8EEE01ED3F20BABEC079D202AE677B243AB40B5431D497C55D75D",
+                   "00E7B0E675A9B24413D448B8CC119D2BF7B2D2DF032741C096634D6D65D0DBE3D5694625FB9E8104D3B842C1B0E2D0B98BEA19341E8676AEF66AE4EBA3D5475D5D16",
+                  },
+                  {
+                   "0121415EC2CD7726330A61F7F3FA5DE14BE9436019C4DB8CB4041F3B54CF31BE0493EE3F427FB906393D895A19C9523F3A1D54BB8702BD4AA9C99DAB2597B92113F3",
+                   "01776331CFCDF927D666E032E00CF776187BC9FDD8E69D0DABB4109FFE1B5E2A30715F4CC923A4A5E94D2503E9ACFED92857B7F31D7152E0F8C00C15FF3D87E2ED2E",
+                   "0050CB5265417FE2320BBB5A122B8E1A32BD699089851128E360E620A30C7E17BA41A666AF126CE100E5799B153B60528D5300D08489CA9178FB610A2006C254B41F",
+                  },
+                  {
+                   "EDF38AFCAAECAB4383358B34D67C9F2216C8382AAEA44A3DAD5FDC9C32575761793FEF24EB0FC276DFC4F6E3EC476752F043CF01415387470BCBD8678ED2C7E1A0",
+                   "01511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E1A7",
+                   "004A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7ECFC",
+                  },
+                  {
+                   "01546A108BC23A15D6F21872F7DED661FA8431DDBD922D0DCDB77CC878C8553FFAD064C95A920A750AC9137E527390D2D92F153E66196966EA554D9ADFCB109C4211",
+                   "01EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67451",
+                   "01F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65D61",
+                  },
+                  {
+                   "01DAE2EA071F8110DC26882D4D5EAE0621A3256FC8847FB9022E2B7D28E6F10198B1574FDD03A9053C08A1854A168AA5A57470EC97DD5CE090124EF52A2F7ECBFFD3",
+                   "00C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F174E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E377FA",
+                   "00617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF282623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A67A",
+                  },
+                  {
+                   "00BB9F2BF4FE1038CCF4DABD7139A56F6FD8BB1386561BD3C6A4FC818B20DF5DDBA80795A947107A1AB9D12DAA615B1ADE4F7A9DC05E8E6311150F47F5C57CE8B222",
+                   "013BAD9F29ABE20DE37EBEB823C252CA0F63361284015A3BF430A46AAA80B87B0693F0694BD88AFE4E661FC33B094CD3B7963BED5A727ED8BD6A3A202ABE009D0367",
+                   "01E9BB81FF7944CA409AD138DBBEE228E1AFCC0C890FC78EC8604639CB0DBDC90F717A99EAD9D272855D00162EE9527567DD6A92CBD629805C0445282BBC916797FF",
+                  },
+                  {
+                   "0040D09FCF3C8A5F62CF4FB223CBBB2B9937F6B0577C27020A99602C25A01136987E452988781484EDBBCF1C47E554E7FC901BC3085E5206D9F619CFF07E73D6F706",
+                   "01C7ED902E123E6815546065A2C4AF977B22AA8EADDB68B2C1110E7EA44D42086BFE4A34B67DDC0E17E96536E358219B23A706C6A6E16BA77B65E1C595D43CAE17FB",
+                   "0177336676304FCB343CE028B38E7B4FBA76C1C1B277DA18CAD2A8478B2A9A9F5BEC0F3BA04F35DB3E4263569EC6AADE8C92746E4C82F8299AE1B8F1739F8FD519A4",
+                  },
+                  {
+                   "001DE74955EFAABC4C4F17F8E84D881D1310B5392D7700275F82F145C61E843841AF09035BF7A6210F5A431A6A9E81C9323354A9E69135D44EBD2FCAA7731B909258",
+                   "000E871C4A14F993C6C7369501900C4BC1E9C7B0B4BA44E04868B30B41D8071042EB28C4C250411D0CE08CD197E4188EA4876F279F90B3D8D74A3C76E6F1E4656AA8",
+                   "00CD52DBAA33B063C3A6CD8058A1FB0A46A4754B034FCC644766CA14DA8CA5CA9FDE00E88C1AD60CCBA759025299079D7A427EC3CC5B619BFBC828E7769BCD694E86",
+                  },
+                  {
+                   "01F1FC4A349A7DA9A9E116BFDD055DC08E78252FF8E23AC276AC88B1770AE0B5DCEB1ED14A4916B769A523CE1E90BA22846AF11DF8B300C38818F713DADD85DE0C88",
+                   "014BEE21A18B6D8B3C93FAB08D43E739707953244FDBE924FA926D76669E7AC8C89DF62ED8975C2D8397A65A49DCC09F6B0AC62272741924D479354D74FF6075578C",
+                   "0133330865C067A0EAF72362A65E2D7BC4E461E8C8995C3B6226A21BD1AA78F0ED94FE536A0DCA35534F0CD1510C41525D163FE9D74D134881E35141ED5E8E95B979",
+                  },
+                  {
+                   "016200813020EC986863BEDFC1B121F605C1215645018AEA1A7B215A564DE9EB1B38A67AA1128B80CE391C4FB71187654AAA3431027BFC7F395766CA988C964DC56D",
+                   "013E99020ABF5CEE7525D16B69B229652AB6BDF2AFFCAEF38773B4B7D08725F10CDB93482FDCC54EDCEE91ECA4166B2A7C6265EF0CE2BD7051B7CEF945BABD47EE6D",
+                   "01FBD0013C674AA79CB39849527916CE301C66EA7CE8B80682786AD60F98F7E78A19CA69EFF5C57400E3B3A0AD66CE0978214D13BAF4E9AC60752F7B155E2DE4DCE3",
+                  },
+                  {
+                   NULL, NULL, NULL
+                  }
+                 }
+                },
+                {
+                 NULL
+                }
+   };
+
+   const void *inputs[] = {
+                           "sample",
+                           "test"
+   };
+   const char hashes[][7] = {
+                           "sha1",
+                           "sha224",
+                           "sha256",
+                           "sha384",
+                           "sha512"
+   };
+   const ltc_ecc_curve* dp;
+   ecc_key key;
+   unsigned char pk[MAXBLOCKSIZE], hash[MAXBLOCKSIZE], sig[512], should[512];
+   char name[128], tmp[MAXBLOCKSIZE];
+   unsigned int t, s, i, h;
+   unsigned long pklen, hashlen, curvelen, inputlen, siglen, shouldlen, shouldlen2;
+   for (t = 0; tests[t].curve; ++t) {
+      curvelen = XSTRLEN(tests[t].curve);
+      XMEMCPY(name, tests[t].curve, curvelen);
+      name[curvelen++] = '-';
+      DOX(ecc_find_curve(tests[t].curve, &dp), tests[t].curve);
+      pklen = sizeof(pk);
+      DOX(base16_decode(tests[t].x, XSTRLEN(tests[t].x), pk, &pklen), tests[t].curve);
+      DOX(ecc_set_curve(dp, &key), tests[t].curve);
+      DOX(ecc_set_key(pk, pklen, PK_PRIVATE, &key), tests[t].curve);
+      name[curvelen] = 'U';
+      name[curvelen + 1] = 'x';
+      name[curvelen + 2] = '\0';
+      ltc_mp.write_radix(key.pubkey.x, tmp, 16);
+      COMPARE_TESTVECTOR(tmp, XSTRLEN(tmp), tests[t].Ux, XSTRLEN(tests[t].Ux), name, t * 1000);
+      name[curvelen + 1] = 'y';
+      ltc_mp.write_radix(key.pubkey.y, tmp, 16);
+      COMPARE_TESTVECTOR(tmp, XSTRLEN(tmp), tests[t].Uy, XSTRLEN(tests[t].Uy), name, t * 1000);
+      i = h = 0;
+      for (s = 0; tests[t].signatures[s].k; ++s) {
+         if (h == 0) {
+            inputlen = XSTRLEN(inputs[i]);
+            XMEMCPY(&name[curvelen], inputs[i], inputlen);
+            name[curvelen + inputlen++] = '-';
+         }
+         XMEMCPY(&name[curvelen + inputlen], hashes[h], 7);
+         hashlen = sizeof(hash);
+         DOX(hash_memory(find_hash(hashes[h]), inputs[i], XSTRLEN(inputs[i]), hash, &hashlen), name);
+         ECC_SET_RFC6979_HASH_ALG(&key, hashes[h]);
+         siglen = sizeof(sig);
+         DOX(ecc_sign_hash_rfc7518(hash, hashlen, sig, &siglen, &yarrow_prng, find_prng ("yarrow"), &key), name);
+         XMEMSET(should, 0, sizeof(should));
+         shouldlen = sizeof(should);
+         DOX(base16_decode(tests[t].signatures[s].r, XSTRLEN(tests[t].signatures[s].r), should, &shouldlen), name);
+         shouldlen2 = sizeof(should) - shouldlen;
+         DOX(base16_decode(tests[t].signatures[s].s, XSTRLEN(tests[t].signatures[s].s), should + shouldlen, &shouldlen2), name);
+         COMPARE_TESTVECTOR(sig, siglen, should, shouldlen + shouldlen2, name, (t * 1000 | s * 100 | i * 10 | h));
+         h++;
+         if (h == 5) {
+            h = 0;
+            i++;
+         }
+      }
+      ecc_free(&key);
+   }
+   return CRYPT_OK;
+}
+
 
 
 static int password_get(void **p, unsigned long *l, void *u)
 static int password_get(void **p, unsigned long *l, void *u)
 {
 {
@@ -1667,6 +2040,7 @@ int ecc_test(void)
 {
 {
    if (ltc_mp.name == NULL) return CRYPT_NOP;
    if (ltc_mp.name == NULL) return CRYPT_NOP;
 
 
+   DO(s_ecc_rfc6979());
    DO(s_ecc_old_api()); /* up to 1.18 */
    DO(s_ecc_old_api()); /* up to 1.18 */
    DO(s_ecc_new_api());
    DO(s_ecc_new_api());
    DO(s_ecc_import_export());
    DO(s_ecc_import_export());