Add secp256k1 curve.
authorNIIBE Yutaka <gniibe@fsij.org>
Sun, 12 Jan 2014 12:54:57 +0000 (21:54 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Sun, 12 Jan 2014 12:54:57 +0000 (21:54 +0900)
* cipher/ecc-curves.c (curve_aliases): Add secp256k1 and its OID.
(domain_parms): Add secp256k1's domain paramerter.

* tests/basic.c (check_pubkey): Add a key of secp256k1.

* tests/curves.c (N_CURVES): Updated.

--

The key in check_pubkey is from "Test vector 1" of following page.
    https://en.bitcoin.it/wiki/BIP_0032_TestVectors

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
cipher/ecc-curves.c
tests/basic.c
tests/curves.c

index ed629fc..a4bce67 100644 (file)
@@ -73,6 +73,8 @@ static const struct
     { "brainpoolP384r1", "1.3.36.3.3.2.8.1.1.11"},
     { "brainpoolP512r1", "1.3.36.3.3.2.8.1.1.13"},
 
+    { "secp256k1", "1.3.132.0.10" },
+
     { NULL, NULL}
   };
 
@@ -297,6 +299,17 @@ static const ecc_domain_parms_t domain_parms[] =
       "c83ab156d77f1496bf7eb3351e1ee4e43dc1a18b91b24640b6dbb92cb1add371e",
     },
 
+    {
+      "secp256k1", 256, 0,
+      MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD,
+      "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F",
+      "0x0000000000000000000000000000000000000000000000000000000000000000",
+      "0x0000000000000000000000000000000000000000000000000000000000000007",
+      "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",
+      "0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",
+      "0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"
+    },
+
     { NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
   };
 
index 0eb8215..56328d1 100644 (file)
@@ -5901,6 +5901,28 @@ check_pubkey (void)
 
       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
       "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
+  },
+  { /* secp256k1 test 256 bit.  */
+    GCRY_PK_ECDSA, FLAG_SIGN,
+    {
+      "(private-key\n"
+      " (ecc\n"
+      "  (curve secp256k1)\n"
+      "  (q #0439A36013301597DAEF41FBE593A02CC513D0B55527EC2D"
+      "      F1050E2E8FF49C85C23CBE7DED0E7CE6A594896B8F62888F"
+      "      DBC5C8821305E2EA42BF01E37300116281#)\n"
+      "  (d #E8F32E723DECF4051AEFAC8E2C93C9C5B214313817CDB01A"
+      "      1494B917C8436B35#)))\n",
+
+      "(public-key\n"
+      " (ecc\n"
+      "  (curve secp256k1)\n"
+      "  (q #0439A36013301597DAEF41FBE593A02CC513D0B55527EC2D"
+      "      F1050E2E8FF49C85C23CBE7DED0E7CE6A594896B8F62888F"
+      "      DBC5C8821305E2EA42BF01E37300116281#)))\n"
+
+      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
     }
   };
   int i;
index 198693e..04e6bc9 100644 (file)
@@ -29,7 +29,7 @@
 #include "../src/gcrypt-int.h"
 
 /* Number of curves defined in ../cipger/ecc.c */
-#define N_CURVES 15
+#define N_CURVES 16
 
 /* A real world sample public key.  */
 static char const sample_key_1[] =