[PATCH 3/3] x509: Detect sm2 keys by their parameters OID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Stefan Berger <stefanb@xxxxxxxxxxxxx>

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

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux