|
17 | 17 | static secp256k1_context* secp256k1_context_sign = NULL;
|
18 | 18 |
|
19 | 19 | /** These functions are taken from the libsecp256k1 distribution and are very ugly. */
|
| 20 | + |
| 21 | +/** |
| 22 | + * This parses a format loosely based on a DER encoding of the ECPrivateKey type from |
| 23 | + * section C.4 of SEC 1 <http://www.secg.org/sec1-v2.pdf>, with the following caveats: |
| 24 | + * |
| 25 | + * * The octet-length of the SEQUENCE must be encoded as 1 or 2 octets. It is not |
| 26 | + * required to be encoded as one octet if it is less than 256, as DER would require. |
| 27 | + * * The octet-length of the SEQUENCE must not be greater than the remaining |
| 28 | + * length of the key encoding, but need not match it (i.e. the encoding may contain |
| 29 | + * junk after the encoded SEQUENCE). |
| 30 | + * * The privateKey OCTET STRING is zero-filled on the left to 32 octets. |
| 31 | + * * Anything after the encoding of the privateKey OCTET STRING is ignored, whether |
| 32 | + * or not it is validly encoded DER. |
| 33 | + * |
| 34 | + * out32 must point to an output buffer of length at least 32 bytes. |
| 35 | + */ |
20 | 36 | static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *out32, const unsigned char *privkey, size_t privkeylen) {
|
21 | 37 | const unsigned char *end = privkey + privkeylen;
|
22 | 38 | size_t lenb = 0;
|
@@ -66,6 +82,13 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou
|
66 | 82 | return 1;
|
67 | 83 | }
|
68 | 84 |
|
| 85 | +/** |
| 86 | + * This serializes to a DER encoding of the ECPrivateKey type from section C.4 of SEC 1 |
| 87 | + * <http://www.secg.org/sec1-v2.pdf>. The optional parameters and publicKey fields are |
| 88 | + * included. |
| 89 | + * |
| 90 | + * key32 must point to a 32-byte raw private key. |
| 91 | + */ |
69 | 92 | static int ec_privkey_export_der(const secp256k1_context *ctx, unsigned char *privkey, size_t *privkeylen, const unsigned char *key32, int compressed) {
|
70 | 93 | secp256k1_pubkey pubkey;
|
71 | 94 | size_t pubkeylen = 0;
|
|
0 commit comments