From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: dhowells@redhat.com, keyrings@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, herbert@gondor.apana.org.au,
davem@davemloft.net, linux-crypto@vger.kernel.org,
patrick@puiterwijk.org, Stefan Berger <stefanb@linux.ibm.com>
Subject: [PATCH v3 3/3] x509: Add support for NIST p192 keys in certificates and akcipher
Date: Wed, 27 Jan 2021 07:33:50 -0500 [thread overview]
Message-ID: <20210127123350.817593-4-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <20210127123350.817593-1-stefanb@linux.vnet.ibm.com>
From: Stefan Berger <stefanb@linux.ibm.com>
Add support for NIST p192 keys in x509 certificates and support it in
'akcipher'.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
crypto/asymmetric_keys/public_key.c | 3 ++
crypto/asymmetric_keys/x509_cert_parser.c | 1 +
crypto/ecc.c | 36 ++++++++++++++++++++++-
include/linux/oid_registry.h | 1 +
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 0fcbaec0ded0..bb4a7cc0e3c8 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -98,6 +98,9 @@ int software_key_determine_akcipher(const char *encoding,
oid = look_up_OID(pkey->params + 2, pkey->paramlen - 2);
switch (oid) {
+ case OID_id_prime192v1:
+ strcpy(alg_name, "nist_p192");
+ return 0;
case OID_id_prime256v1:
strcpy(alg_name, "nist_p256");
return 0;
diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
index 50f6ecc70d8b..5ff891f8235d 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -505,6 +505,7 @@ int x509_extract_key_data(void *context, size_t hdrlen,
case OID_sm2:
ctx->cert->pub->pkey_algo = "sm2";
break;
+ case OID_id_prime192v1:
case OID_id_prime256v1:
ctx->cert->pub->pkey_algo = "ecdsa";
break;
diff --git a/crypto/ecc.c b/crypto/ecc.c
index 98577ed99aaf..0690c37f74e3 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1813,13 +1813,47 @@ static struct akcipher_alg ecc_nist_p256 = {
},
};
+static unsigned int ecc_nist_p192_max_size(struct crypto_akcipher *tfm)
+{
+ return NIST_P192_KEY_SIZE;
+}
+
+static int ecc_nist_p192_init_tfm(struct crypto_akcipher *tfm)
+{
+ struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm);
+
+ return ecc_ec_ctx_init(ctx, ECC_CURVE_NIST_P192);
+}
+
+static struct akcipher_alg ecc_nist_p192 = {
+ .verify = ecdsa_verify,
+ .set_pub_key = ecc_set_pub_key,
+ .max_size = ecc_nist_p192_max_size,
+ .init = ecc_nist_p192_init_tfm,
+ .exit = ecc_exit_tfm,
+ .base = {
+ .cra_name = "nist_p192",
+ .cra_driver_name = "ecc-nist-p192",
+ .cra_priority = 100,
+ .cra_module = THIS_MODULE,
+ .cra_ctxsize = sizeof(struct ecc_ctx),
+ },
+};
+
static int ecc_init(void)
{
- return crypto_register_akcipher(&ecc_nist_p256);
+ int ret;
+
+ ret = crypto_register_akcipher(&ecc_nist_p256);
+ if (ret)
+ return ret;
+
+ return crypto_register_akcipher(&ecc_nist_p192);
}
static void ecc_exit(void)
{
+ crypto_unregister_akcipher(&ecc_nist_p192);
crypto_unregister_akcipher(&ecc_nist_p256);
}
diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h
index 9060f19c80eb..e8071133d0e2 100644
--- a/include/linux/oid_registry.h
+++ b/include/linux/oid_registry.h
@@ -21,6 +21,7 @@ enum OID {
OID_id_dsa, /* 1.2.840.10040.4.1 */
OID_id_ecdsa_with_sha1, /* 1.2.840.10045.4.1 */
OID_id_ecPublicKey, /* 1.2.840.10045.2.1 */
+ OID_id_prime192v1, /* 1.2.840.10045.3.1.1 */
OID_id_prime256v1, /* 1.2.840.10045.3.1.7 */
OID_id_ecdsa_with_sha224, /* 1.2.840.10045.4.3.1 */
OID_id_ecdsa_with_sha256, /* 1.2.840.10045.4.3.2 */
--
2.25.4
next prev parent reply other threads:[~2021-01-27 12:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-27 12:33 [PATCH v3 0/3] Add support for x509 certs with NIST p256 and p192 keys Stefan Berger
2021-01-27 12:33 ` [PATCH v3 1/3] x509: Detect sm2 keys by their parameters OID Stefan Berger
2021-01-30 21:26 ` Jarkko Sakkinen
2021-01-31 2:57 ` Stefan Berger
2021-02-02 15:16 ` Jarkko Sakkinen
2021-01-27 12:33 ` [PATCH v3 2/3] x509: Add support for parsing x509 certs with NIST p256 keys Stefan Berger
2021-01-27 19:31 ` Herbert Xu
2021-01-27 22:39 ` Stefan Berger
2021-01-27 12:33 ` Stefan Berger [this message]
2021-01-27 13:05 ` [PATCH v3 0/3] Add support for x509 certs with NIST p256 and p192 keys David Howells
2021-01-27 14:22 ` David Howells
2021-01-27 19:32 ` Herbert Xu
2021-01-27 21:08 ` David Howells
2021-01-27 16:12 ` Nym Seddon
2021-01-27 22:42 ` Stefan Berger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210127123350.817593-4-stefanb@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patrick@puiterwijk.org \
--cc=stefanb@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®