Skip to content

Commit 3d3d052

Browse files
committed
pkcs15-pubkey.c explain problem with EC pubkeys as OCTET STRING vs BIT STRING
On branch X25519-improvements-2 Changes to be committed: modified: libopensc/pkcs15-pubkey.c
1 parent 1931bc1 commit 3d3d052

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libopensc/pkcs15-pubkey.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ static struct sc_asn1_entry c_asn1_gostr3410_pub_coefficients[C_ASN1_GOSTR3410_P
537537
{ NULL, 0, 0, 0, NULL, NULL }
538538
};
539539

540-
/* older incorrect implementation may have encoded as OCTET STRING */
540+
/* PKCS15 raw uses OCTET STRING, SPKI uses BIT STRING */
541541
/* accept either */
542542
#define C_ASN1_EC_POINTQ_SIZE 3
543543
static struct sc_asn1_entry c_asn1_ec_pointQ[C_ASN1_EC_POINTQ_SIZE] = {
@@ -684,7 +684,17 @@ sc_pkcs15_encode_pubkey_ec(sc_context_t *ctx, struct sc_pkcs15_pubkey_ec *key,
684684
{
685685
struct sc_asn1_entry asn1_ec_pointQ[C_ASN1_EC_POINTQ_SIZE];
686686
size_t key_len;
687-
volatile int gdb_test = 1; /* so can reset via gdb for testing new way */
687+
/*
688+
* PKCS15 uses RAW vs SPKI for pub key, and in raw uses OCTET STRING
689+
* PKCS11 does not define CKA_VALUE for a pub key
690+
* But some PKCS11 modules define a CKA_VALUE for a public key
691+
* and PKCS11 says ECPOINT is encoded as "DER-encoding of ANSI X9.62 ECPoint value Q"
692+
* But ANSI X9.62 (early draft at least) says encode as BIT STRING
693+
* IETF encodes in SubjectPublicKeyInfo (SPKI) in BIT STRING
694+
* PKCS11 V3 does add CKA_PUBLIC_KEY_INFO as SPKI
695+
* For now return as OCTET STRING.
696+
*/
697+
volatile int gdb_test = 0; /* 0 - OCTET STRING (PKCS15 RAW) 1 - BIT STRING (SPKI) */
688698

689699
LOG_FUNC_CALLED(ctx);
690700
sc_copy_asn1_entry(c_asn1_ec_pointQ, asn1_ec_pointQ);

0 commit comments

Comments
 (0)