lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210126170359.363969-4-stefanb@linux.vnet.ibm.com>
Date:   Tue, 26 Jan 2021 12:03:59 -0500
From:   Stefan Berger <stefanb@...ux.vnet.ibm.com>
To:     dhowells@...hat.com, keyrings@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org, herbert@...dor.apana.org.au,
        davem@...emloft.net, linux-crypto@...r.kernel.org,
        patrick@...terwijk.org, Stefan Berger <stefanb@...ux.ibm.com>
Subject: [PATCH 3/3] x509: Detect sm2 keys by their parameters OID

From: Stefan Berger <stefanb@...ux.ibm.com>

Detect whether a key is a sm2 type of key by its OID in the parameters
array.

Signed-off-by: Stefan Berger <stefanb@...ux.ibm.com>
---
 crypto/asymmetric_keys/x509_cert_parser.c | 27 +++++++++++++----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
index 720cc7977077..82e331da5041 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -485,6 +485,7 @@ int x509_extract_key_data(void *context, size_t hdrlen,
 			  const void *value, size_t vlen)
 {
 	struct x509_parse_context *ctx = context;
+	enum OID oid;
 
 	ctx->key_algo = ctx->last_oid;
 	switch (ctx->last_oid) {
@@ -496,18 +497,20 @@ int x509_extract_key_data(void *context, size_t hdrlen,
 		ctx->cert->pub->pkey_algo = "ecrdsa";
 		break;
 	case OID_id_ecPublicKey:
-		ctx->cert->pub->pkey_algo = "sm2";
-		if (ctx->params_size > 2) {
-			enum OID oid = look_up_OID(ctx->params + 2,
-						   ctx->params_size - 2);
-			switch (oid) {
-			case OID_id_prime192v1:
-			case OID_id_prime256v1:
-				ctx->cert->pub->pkey_algo = "ecdsa";
-				break;
-			default:
-				break;
-			}
+		if (ctx->params_size < 2)
+			return -ENOPKG;
+
+		oid = look_up_OID(ctx->params + 2, ctx->params_size - 2);
+		switch (oid) {
+		case OID_id_prime192v1:
+		case OID_id_prime256v1:
+			ctx->cert->pub->pkey_algo = "ecdsa";
+			break;
+		case OID_sm2:
+			ctx->cert->pub->pkey_algo = "sm2";
+			break;
+		default:
+			return -ENOPKG;
 		}
 		break;
 	default:
-- 
2.25.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ