Skip to contentSkip to conversation

ECDSA key parsing in crypto drivers

DISCUSSION Paul Louvel 2 participants 5 messages Aug 31 – Sep 3 Crypto API

lore
Share & tools
lore
#0 lore raw

Hi,

I am currently working on upstreaming the ECDSA part of a Public Key Accelerator.
I have a question regarding which ASN.1 schema should I use when decoding the buffer passed by the .set_pub_key() and .set_priv_key() callbacks in struct sig_alg.
The documentation only mentions that the callbacks should "know how to decode and interpret the BER encoded public key and parameters."

The kernel software implementation of ECDSA only supports verifying signatures, and thus only implements the .set_pub_key() callback. In this callback, the buffer should contain an ECC key as defined by RFC5480 section 2.2 [1].

In the downstream driver I am currently upstreaming, it expects a BER encoded ASN.1 schema of SubjectPublicKeyInfo as defined in RFC5480 section 2 [2]. The driver defines its own .asn1 file containing the ASN.1 schema of this sequence, and uses the kernel's ASN.1 compiler/decoder to decode the buffer.

Because the PKA can be used to sign messages, there is a .set_priv_key() callback that expects a BER encoded ASN.1 schema as defined in RFC5915 section 3 [3]. The same remark applies to the public key: a .asn1 file is present and defines the ASN.1 schema described by the RFC.

My question is: which ASN.1 schema should be used? Should a client of the crypto API know in advance which format the driver expects? Also, for RSA, there are helpers for parsing private and public keys: rsa_parse_priv_key() and rsa_parse_pub_key(). These helpers use the kernel's ASN.1 decoder. Would it make sense to have such helpers for ECDSA?

Thank you,

[1] RFC5480 Section 2.2 - ECC Key Format
https://tools.ietf.org/html/rfc5480#section-2.2

[2] RFC5480 Section 2 - SubjectPublicKeyInfo
https://tools.ietf.org/html/rfc5480#section-2

[3] RFC5915 Section 3 - Private Key Format
https://tools.ietf.org/html/rfc5915#section-3

Signature · 3 lines
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#1 lore raw

Adding Herbert Xu and David S. Miller as recipient.

Quoted 41 lines · Paul Louvel

Hi,

I am currently working on upstreaming the ECDSA part of a Public Key Accelerator.
I have a question regarding which ASN.1 schema should I use when decoding the buffer passed by the .set_pub_key() and .set_priv_key() callbacks in struct sig_alg.
The documentation only mentions that the callbacks should "know how to decode and interpret the BER encoded public key and parameters."

The kernel software implementation of ECDSA only supports verifying signatures, and thus only implements the .set_pub_key() callback. In this callback, the buffer should contain an ECC key as defined by RFC5480 section 2.2 [1].

In the downstream driver I am currently upstreaming, it expects a BER encoded ASN.1 schema of SubjectPublicKeyInfo as defined in RFC5480 section 2 [2]. The driver defines its own .asn1 file containing the ASN.1 schema of this sequence, and uses the kernel's ASN.1 compiler/decoder to decode the buffer.

Because the PKA can be used to sign messages, there is a .set_priv_key() callback that expects a BER encoded ASN.1 schema as defined in RFC5915 section 3 [3]. The same remark applies to the public key: a .asn1 file is present and defines the ASN.1 schema described by the RFC.

My question is: which ASN.1 schema should be used? Should a client of the crypto API know in advance which format the driver expects? Also, for RSA, there are helpers for parsing private and public keys: rsa_parse_priv_key() and rsa_parse_pub_key(). These helpers use the kernel's ASN.1 decoder. Would it make sense to have such helpers for ECDSA?

Thank you,

[1] RFC5480 Section 2.2 - ECC Key Format
https://tools.ietf.org/html/rfc5480#section-2.2

[2] RFC5480 Section 2 - SubjectPublicKeyInfo
https://tools.ietf.org/html/rfc5480#section-2

[3] RFC5915 Section 3 - Private Key Format
https://tools.ietf.org/html/rfc5915#section-3

Signature · 3 lines
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#2 lore raw
Quoted 6 lines · Paul Louvel
Quoted 6 lines

My question is: which ASN.1 schema should be used? Should a client of the crypto API know in advance which format the driver expects? Also, for RSA, there are helpers for parsing private and public keys: rsa_parse_priv_key() and rsa_parse_pub_key(). These helpers use the kernel's ASN.1 decoder. Would it make sense to have such helpers for ECDSA?

The driver needs to match the generic C implementation of the same algorithm.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw

Hi Herbert,

Quoted 10 lines · Herbert Xu
Quoted 5 lines · Paul Louvel
Quoted 5 lines

My question is: which ASN.1 schema should be used? Should a client of the crypto API know in advance which format the driver expects? Also, for RSA, there are helpers for parsing private and public keys: rsa_parse_priv_key() and rsa_parse_pub_key(). These helpers use the kernel's ASN.1 decoder. Would it make sense to have such helpers for ECDSA?

The driver needs to match the generic C implementation of the same algorithm.

Cheers,

By "generic C implementation", do you mean the implementation in ecdsa.c ? For verify operation, this is clear. But signing is not implemented, so there is no callback for setting the private key.

Best regards,

Signature · 3 lines
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#4 lore raw
Quoted 4 lines · Paul Louvel

By "generic C implementation", do you mean the implementation in ecdsa.c ? For verify operation, this is clear. But signing is not implemented, so there is no callback for setting the private key.

Right, in order for an algorithm/function to be added to the API, there has to be an in-kernel use-case. Right now there is no in-kernel user of signing so that's why this is not implemented in the generic code.

Until it's implemented in the generic code, drivers should not expose this function (at least not via the Crypto API) either.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt