Skip to content

Commit 6238b63

Browse files
authored
Merge pull request #187 from libtom/pr/ecc-asn1-part
ECC-step3: extra import/export (ASN.1 related)
2 parents d11a1a7 + 4f36e03 commit 6238b63

File tree

12 files changed

+889
-20
lines changed

12 files changed

+889
-20
lines changed

libtomcrypt_VS2008.vcproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,10 @@
22782278
RelativePath="src\pk\ecc\ecc_export.c"
22792279
>
22802280
</File>
2281+
<File
2282+
RelativePath="src\pk\ecc\ecc_export_openssl.c"
2283+
>
2284+
</File>
22812285
<File
22822286
RelativePath="src\pk\ecc\ecc_free.c"
22832287
>
@@ -2302,6 +2306,14 @@
23022306
RelativePath="src\pk\ecc\ecc_import.c"
23032307
>
23042308
</File>
2309+
<File
2310+
RelativePath="src\pk\ecc\ecc_import_openssl.c"
2311+
>
2312+
</File>
2313+
<File
2314+
RelativePath="src\pk\ecc\ecc_import_x509.c"
2315+
>
2316+
</File>
23052317
<File
23062318
RelativePath="src\pk\ecc\ecc_make_key.c"
23072319
>

makefile.mingw

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,12 @@ src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o
177177
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
178178
src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
179179
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
180-
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_curve.o src/pk/ecc/ecc_get_key.o \
181-
src/pk/ecc/ecc_get_oid_str.o src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o \
182-
src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_set_dp.o src/pk/ecc/ecc_set_dp_internal.o \
183-
src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
184-
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
180+
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o src/pk/ecc/ecc_free.o \
181+
src/pk/ecc/ecc_get_curve.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o \
182+
src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o \
183+
src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_set_dp.o \
184+
src/pk/ecc/ecc_set_dp_internal.o src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o \
185+
src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
185186
src/pk/ecc/ltc_ecc_export_point.o src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
186187
src/pk/ecc/ltc_ecc_is_point_at_infinity.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
187188
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \

makefile.msvc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ src/pk/dsa/dsa_make_key.obj src/pk/dsa/dsa_set.obj src/pk/dsa/dsa_set_pqg_dsapar
170170
src/pk/dsa/dsa_shared_secret.obj src/pk/dsa/dsa_sign_hash.obj src/pk/dsa/dsa_verify_hash.obj \
171171
src/pk/dsa/dsa_verify_key.obj src/pk/ecc/ecc.obj src/pk/ecc/ecc_ansi_x963_export.obj \
172172
src/pk/ecc/ecc_ansi_x963_import.obj src/pk/ecc/ecc_decrypt_key.obj src/pk/ecc/ecc_encrypt_key.obj \
173-
src/pk/ecc/ecc_export.obj src/pk/ecc/ecc_free.obj src/pk/ecc/ecc_get_curve.obj src/pk/ecc/ecc_get_key.obj \
174-
src/pk/ecc/ecc_get_oid_str.obj src/pk/ecc/ecc_get_size.obj src/pk/ecc/ecc_import.obj \
175-
src/pk/ecc/ecc_make_key.obj src/pk/ecc/ecc_set_dp.obj src/pk/ecc/ecc_set_dp_internal.obj \
176-
src/pk/ecc/ecc_set_key.obj src/pk/ecc/ecc_shared_secret.obj src/pk/ecc/ecc_sign_hash.obj \
177-
src/pk/ecc/ecc_sizes.obj src/pk/ecc/ecc_test.obj src/pk/ecc/ecc_verify_hash.obj \
173+
src/pk/ecc/ecc_export.obj src/pk/ecc/ecc_export_openssl.obj src/pk/ecc/ecc_free.obj \
174+
src/pk/ecc/ecc_get_curve.obj src/pk/ecc/ecc_get_key.obj src/pk/ecc/ecc_get_oid_str.obj \
175+
src/pk/ecc/ecc_get_size.obj src/pk/ecc/ecc_import.obj src/pk/ecc/ecc_import_openssl.obj \
176+
src/pk/ecc/ecc_import_x509.obj src/pk/ecc/ecc_make_key.obj src/pk/ecc/ecc_set_dp.obj \
177+
src/pk/ecc/ecc_set_dp_internal.obj src/pk/ecc/ecc_set_key.obj src/pk/ecc/ecc_shared_secret.obj \
178+
src/pk/ecc/ecc_sign_hash.obj src/pk/ecc/ecc_sizes.obj src/pk/ecc/ecc_test.obj src/pk/ecc/ecc_verify_hash.obj \
178179
src/pk/ecc/ltc_ecc_export_point.obj src/pk/ecc/ltc_ecc_import_point.obj src/pk/ecc/ltc_ecc_is_point.obj \
179180
src/pk/ecc/ltc_ecc_is_point_at_infinity.obj src/pk/ecc/ltc_ecc_map.obj src/pk/ecc/ltc_ecc_mul2add.obj \
180181
src/pk/ecc/ltc_ecc_mulmod.obj src/pk/ecc/ltc_ecc_mulmod_timing.obj src/pk/ecc/ltc_ecc_points.obj \

makefile.unix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o
187187
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
188188
src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
189189
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
190-
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_curve.o src/pk/ecc/ecc_get_key.o \
191-
src/pk/ecc/ecc_get_oid_str.o src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o \
192-
src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_set_dp.o src/pk/ecc/ecc_set_dp_internal.o \
193-
src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
194-
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
190+
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o src/pk/ecc/ecc_free.o \
191+
src/pk/ecc/ecc_get_curve.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o \
192+
src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o \
193+
src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_set_dp.o \
194+
src/pk/ecc/ecc_set_dp_internal.o src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o \
195+
src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
195196
src/pk/ecc/ltc_ecc_export_point.o src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
196197
src/pk/ecc/ltc_ecc_is_point_at_infinity.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
197198
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \

makefile_include.mk

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,12 @@ src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o
347347
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
348348
src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
349349
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
350-
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_curve.o src/pk/ecc/ecc_get_key.o \
351-
src/pk/ecc/ecc_get_oid_str.o src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o \
352-
src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_set_dp.o src/pk/ecc/ecc_set_dp_internal.o \
353-
src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
354-
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
350+
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_export_openssl.o src/pk/ecc/ecc_free.o \
351+
src/pk/ecc/ecc_get_curve.o src/pk/ecc/ecc_get_key.o src/pk/ecc/ecc_get_oid_str.o \
352+
src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o src/pk/ecc/ecc_import_openssl.o \
353+
src/pk/ecc/ecc_import_x509.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_set_dp.o \
354+
src/pk/ecc/ecc_set_dp_internal.o src/pk/ecc/ecc_set_key.o src/pk/ecc/ecc_shared_secret.o \
355+
src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
355356
src/pk/ecc/ltc_ecc_export_point.o src/pk/ecc/ltc_ecc_import_point.o src/pk/ecc/ltc_ecc_is_point.o \
356357
src/pk/ecc/ltc_ecc_is_point_at_infinity.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
357358
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \

src/headers/tomcrypt_pk.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ int ecc_ansi_x963_export(const ecc_key *key, unsigned char *out, unsigned long *
270270
int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
271271
int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu);
272272

273+
int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
274+
int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *key);
275+
int ecc_import_x509(const unsigned char *in, unsigned long inlen, ecc_key *key);
276+
273277
int ecc_shared_secret(const ecc_key *private_key, const ecc_key *public_key,
274278
unsigned char *out, unsigned long *outlen);
275279

src/headers/tomcrypt_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ int dh_check_pubkey(const dh_key *key);
195195
int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key);
196196
int ecc_copy_dp(const ecc_key *srckey, ecc_key *key);
197197
int ecc_set_dp_by_size(int size, ecc_key *key);
198+
int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long inlen, ecc_key *key);
198199

199200
/* low level functions */
200201
ecc_point *ltc_ecc_new_point(void);

src/misc/pk_get_oid.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ static const oid_st dsa_oid = {
1919
6,
2020
};
2121

22+
static const oid_st ec_oid = {
23+
{ 1, 2, 840, 10045, 2, 1 },
24+
6,
25+
};
26+
27+
static const oid_st ec_primef = {
28+
{ 1, 2, 840, 10045, 1, 1 },
29+
6,
30+
};
31+
2232
/*
2333
Returns the OID of the public key algorithm.
2434
@return CRYPT_OK if valid
@@ -32,6 +42,12 @@ int pk_get_oid(int pk, oid_st *st)
3242
case PKA_DSA:
3343
XMEMCPY(st, &dsa_oid, sizeof(*st));
3444
break;
45+
case PKA_EC:
46+
XMEMCPY(st, &ec_oid, sizeof(*st));
47+
break;
48+
case PKA_EC_PRIMEF:
49+
XMEMCPY(st, &ec_primef, sizeof(*st));
50+
break;
3551
default:
3652
return CRYPT_INVALID_ARG;
3753
}

src/pk/ecc/ecc_export_openssl.c

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* guarantee it works.
8+
*/
9+
10+
#include "tomcrypt_private.h"
11+
12+
#ifdef LTC_MECC
13+
14+
/**
15+
Export an ECC key as a binary packet
16+
@param out [out] Destination for the key
17+
@param outlen [in/out] Max size and resulting size of the exported key
18+
@param type The type of key you want to export (PK_PRIVATE or PK_PUBLIC)
19+
@param key The key to export
20+
@return CRYPT_OK if successful
21+
*/
22+
23+
int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key)
24+
{
25+
int err;
26+
void *prime, *order, *a, *b, *gx, *gy;
27+
unsigned char bin_a[256], bin_b[256], bin_k[256], bin_g[512], bin_xy[512];
28+
unsigned long len_a, len_b, len_k, len_g, len_xy;
29+
unsigned long cofactor, one = 1;
30+
oid_st oid;
31+
ltc_asn1_list seq_fieldid[2], seq_curve[2], seq_ecparams[6], seq_priv[4], pub_xy, ecparams;
32+
int flag_oid = type & PK_CURVEOID ? 1 : 0;
33+
int flag_com = type & PK_COMPRESSED ? 1 : 0;
34+
int flag_pri = type & PK_PRIVATE ? 1 : 0;
35+
36+
LTC_ARGCHK(out != NULL);
37+
LTC_ARGCHK(outlen != NULL);
38+
LTC_ARGCHK(key != NULL);
39+
40+
if (key->type != PK_PRIVATE && flag_pri) return CRYPT_PK_TYPE_MISMATCH;
41+
42+
prime = key->dp.prime;
43+
order = key->dp.order;
44+
b = key->dp.B;
45+
a = key->dp.A;
46+
gx = key->dp.base.x;
47+
gy = key->dp.base.y;
48+
49+
/* curve param a */
50+
len_a = mp_unsigned_bin_size(a);
51+
if (len_a > sizeof(bin_a)) { err = CRYPT_BUFFER_OVERFLOW; goto error; }
52+
if ((err = mp_to_unsigned_bin(a, bin_a)) != CRYPT_OK) { goto error; }
53+
if (len_a == 0) { len_a = 1; bin_a[0] = 0; } /* handle case a == 0 */
54+
55+
/* curve param b */
56+
len_b = mp_unsigned_bin_size(b);
57+
if (len_b > sizeof(bin_b)) { err = CRYPT_BUFFER_OVERFLOW; goto error; }
58+
if ((err = mp_to_unsigned_bin(b, bin_b)) != CRYPT_OK) { goto error; }
59+
if (len_b == 0) { len_b = 1; bin_b[0] = 0; } /* handle case b == 0 */
60+
61+
/* base point - (un)compressed based on flag_com */
62+
len_g = sizeof(bin_g);
63+
err = ltc_ecc_export_point(bin_g, &len_g, gx, gy, key->dp.size, flag_com);
64+
if (err != CRYPT_OK) { goto error; }
65+
66+
/* public key - (un)compressed based on flag_com */
67+
len_xy = sizeof(bin_xy);
68+
err = ltc_ecc_export_point(bin_xy, &len_xy, key->pubkey.x, key->pubkey.y, key->dp.size, flag_com);
69+
if (err != CRYPT_OK) { goto error; }
70+
71+
/* co-factor */
72+
cofactor = key->dp.cofactor;
73+
74+
/* we support only prime-field EC */
75+
if ((err = pk_get_oid(PKA_EC_PRIMEF, &oid)) != CRYPT_OK) { goto error; }
76+
77+
if (flag_oid) {
78+
/* http://tools.ietf.org/html/rfc5912
79+
ECParameters ::= CHOICE {
80+
namedCurve CURVE.&id({NamedCurve}) # OBJECT
81+
}
82+
*/
83+
if (key->dp.oidlen == 0) { err = CRYPT_INVALID_ARG; goto error; }
84+
LTC_SET_ASN1(&ecparams, 0, LTC_ASN1_OBJECT_IDENTIFIER, key->dp.oid, key->dp.oidlen);
85+
}
86+
else {
87+
/* http://tools.ietf.org/html/rfc3279
88+
ECParameters ::= SEQUENCE { # SEQUENCE
89+
version INTEGER { ecpVer1(1) } (ecpVer1) # INTEGER :01
90+
FieldID ::= SEQUENCE { # SEQUENCE
91+
fieldType FIELD-ID.&id({IOSet}), # OBJECT :prime-field
92+
parameters FIELD-ID.&Type({IOSet}{@fieldType}) # INTEGER
93+
}
94+
Curve ::= SEQUENCE { # SEQUENCE
95+
a FieldElement ::= OCTET STRING # OCTET STRING
96+
b FieldElement ::= OCTET STRING # OCTET STRING
97+
seed BIT STRING OPTIONAL
98+
}
99+
base ECPoint ::= OCTET STRING # OCTET STRING
100+
order INTEGER, # INTEGER
101+
cofactor INTEGER OPTIONAL # INTEGER
102+
}
103+
*/
104+
105+
/* FieldID SEQUENCE */
106+
LTC_SET_ASN1(seq_fieldid, 0, LTC_ASN1_OBJECT_IDENTIFIER, oid.OID, oid.OIDlen);
107+
LTC_SET_ASN1(seq_fieldid, 1, LTC_ASN1_INTEGER, prime, 1UL);
108+
109+
/* Curve SEQUENCE */
110+
LTC_SET_ASN1(seq_curve, 0, LTC_ASN1_OCTET_STRING, bin_a, len_a);
111+
LTC_SET_ASN1(seq_curve, 1, LTC_ASN1_OCTET_STRING, bin_b, len_b);
112+
113+
/* ECParameters SEQUENCE */
114+
LTC_SET_ASN1(seq_ecparams, 0, LTC_ASN1_SHORT_INTEGER, &one, 1UL);
115+
LTC_SET_ASN1(seq_ecparams, 1, LTC_ASN1_SEQUENCE, seq_fieldid, 2UL);
116+
LTC_SET_ASN1(seq_ecparams, 2, LTC_ASN1_SEQUENCE, seq_curve, 2UL);
117+
LTC_SET_ASN1(seq_ecparams, 3, LTC_ASN1_OCTET_STRING, bin_g, len_g);
118+
LTC_SET_ASN1(seq_ecparams, 4, LTC_ASN1_INTEGER, order, 1UL);
119+
LTC_SET_ASN1(seq_ecparams, 5, LTC_ASN1_SHORT_INTEGER, &cofactor, 1UL);
120+
121+
/* ECParameters used by ECPrivateKey or SubjectPublicKeyInfo below */
122+
LTC_SET_ASN1(&ecparams, 0, LTC_ASN1_SEQUENCE, seq_ecparams, 6UL);
123+
}
124+
125+
if (flag_pri) {
126+
/* http://tools.ietf.org/html/rfc5915
127+
ECPrivateKey ::= SEQUENCE { # SEQUENCE
128+
version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1) # INTEGER :01
129+
privateKey OCTET STRING, # OCTET STRING
130+
[0] ECParameters # see above
131+
[1] publicKey # BIT STRING
132+
}
133+
*/
134+
135+
/* private key */
136+
len_k = mp_unsigned_bin_size(key->k);
137+
if (len_k > sizeof(bin_k)) { err = CRYPT_BUFFER_OVERFLOW; goto error; }
138+
if ((err = mp_to_unsigned_bin(key->k, bin_k)) != CRYPT_OK) { goto error; }
139+
140+
LTC_SET_ASN1(&pub_xy, 0, LTC_ASN1_RAW_BIT_STRING, bin_xy, 8*len_xy);
141+
LTC_SET_ASN1(seq_priv, 0, LTC_ASN1_SHORT_INTEGER, &one, 1);
142+
LTC_SET_ASN1(seq_priv, 1, LTC_ASN1_OCTET_STRING, bin_k, len_k);
143+
LTC_SET_ASN1_CUSTOM_CONSTRUCTED(seq_priv, 2, LTC_ASN1_CL_CONTEXT_SPECIFIC, 0, &ecparams); /* context specific 0 */
144+
LTC_SET_ASN1_CUSTOM_CONSTRUCTED(seq_priv, 3, LTC_ASN1_CL_CONTEXT_SPECIFIC, 1, &pub_xy); /* context specific 1 */
145+
146+
err = der_encode_sequence(seq_priv, 4, out, outlen);
147+
}
148+
else {
149+
/* http://tools.ietf.org/html/rfc5480
150+
SubjectPublicKeyInfo ::= SEQUENCE { # SEQUENCE
151+
AlgorithmIdentifier ::= SEQUENCE { # SEQUENCE
152+
algorithm OBJECT IDENTIFIER # OBJECT :id-ecPublicKey
153+
ECParameters # see above
154+
}
155+
subjectPublicKey BIT STRING # BIT STRING
156+
}
157+
*/
158+
err = x509_encode_subject_public_key_info( out, outlen, PKA_EC, bin_xy, len_xy,
159+
ecparams.type, ecparams.data, ecparams.size );
160+
}
161+
162+
error:
163+
return err;
164+
}
165+
166+
#endif
167+
168+
/* ref: $Format:%D$ */
169+
/* git commit: $Format:%H$ */
170+
/* commit time: $Format:%ai$ */

0 commit comments

Comments
 (0)