diff mbox series

[04/22] KEYS: Make the X.509 and PKCS7 parsers supply the sig encoding type

Message ID 153618448451.7946.79126788153992612.stgit@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series KEYS: Support TPM-wrapped key and crypto ops | expand

Commit Message

David Howells Sept. 5, 2018, 9:54 p.m. UTC
Make the X.509 and PKCS7 parsers fill in the signature encoding type field
recently added to the public_key_signature struct.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 crypto/asymmetric_keys/pkcs7_parser.c     |    1 +
 crypto/asymmetric_keys/x509_cert_parser.c |   21 +++++++++------------
 2 files changed, 10 insertions(+), 12 deletions(-)

Comments

James Morris Oct. 3, 2018, 7:12 p.m. UTC | #1
On Wed, 5 Sep 2018, David Howells wrote:

> diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
> index b6cabac4b62b..991f4d735a4e 100644
> --- a/crypto/asymmetric_keys/x509_cert_parser.c
> +++ b/crypto/asymmetric_keys/x509_cert_parser.c
> @@ -199,35 +199,32 @@ int x509_note_pkey_algo(void *context, size_t hdrlen,
>  
>  	case OID_md4WithRSAEncryption:
>  		ctx->cert->sig->hash_algo = "md4";
> -		ctx->cert->sig->pkey_algo = "rsa";
> -		break;
> +		goto rsa_pkcs1;
>  
>  	case OID_sha1WithRSAEncryption:
>  		ctx->cert->sig->hash_algo = "sha1";
> -		ctx->cert->sig->pkey_algo = "rsa";
> -		break;
> +		goto rsa_pkcs1;
>  
>  	case OID_sha256WithRSAEncryption:
>  		ctx->cert->sig->hash_algo = "sha256";
> -		ctx->cert->sig->pkey_algo = "rsa";
> -		break;
> +		goto rsa_pkcs1;
>  
>  	case OID_sha384WithRSAEncryption:
>  		ctx->cert->sig->hash_algo = "sha384";
> -		ctx->cert->sig->pkey_algo = "rsa";
> -		break;
> +		goto rsa_pkcs1;
>  
>  	case OID_sha512WithRSAEncryption:
>  		ctx->cert->sig->hash_algo = "sha512";
> -		ctx->cert->sig->pkey_algo = "rsa";
> -		break;
> +		goto rsa_pkcs1;
>  
>  	case OID_sha224WithRSAEncryption:
>  		ctx->cert->sig->hash_algo = "sha224";
> -		ctx->cert->sig->pkey_algo = "rsa";
> -		break;
> +		goto rsa_pkcs1;
>  	}
>  
> +rsa_pkcs1:
> +	ctx->cert->sig->pkey_algo = "rsa";
> +	ctx->cert->sig->encoding = "pkcs1";
>  	ctx->algo_oid = ctx->last_oid;
>  	return 0;
>  }

Perhaps I'm missing something here but why do you need the gotos vs. just 
breaking to this code?
David Howells Oct. 5, 2018, 3:43 p.m. UTC | #2
James Morris <jmorris@namei.org> wrote:

> Perhaps I'm missing something here but why do you need the gotos vs. just 
> breaking to this code?

Because at some point we might add support for some other public key
algorithm, such as EC.  This makes it clearer that that piece of code is
specific to a certain set of algorithm identifiers.

David
diff mbox series

Patch

diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c
index 0f134162cef4..f0d56e1a8b7e 100644
--- a/crypto/asymmetric_keys/pkcs7_parser.c
+++ b/crypto/asymmetric_keys/pkcs7_parser.c
@@ -271,6 +271,7 @@  int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen,
 	switch (ctx->last_oid) {
 	case OID_rsaEncryption:
 		ctx->sinfo->sig->pkey_algo = "rsa";
+		ctx->sinfo->sig->encoding = "pkcs1";
 		break;
 	default:
 		printk("Unsupported pkey algo: %u\n", ctx->last_oid);
diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
index b6cabac4b62b..991f4d735a4e 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -199,35 +199,32 @@  int x509_note_pkey_algo(void *context, size_t hdrlen,
 
 	case OID_md4WithRSAEncryption:
 		ctx->cert->sig->hash_algo = "md4";
-		ctx->cert->sig->pkey_algo = "rsa";
-		break;
+		goto rsa_pkcs1;
 
 	case OID_sha1WithRSAEncryption:
 		ctx->cert->sig->hash_algo = "sha1";
-		ctx->cert->sig->pkey_algo = "rsa";
-		break;
+		goto rsa_pkcs1;
 
 	case OID_sha256WithRSAEncryption:
 		ctx->cert->sig->hash_algo = "sha256";
-		ctx->cert->sig->pkey_algo = "rsa";
-		break;
+		goto rsa_pkcs1;
 
 	case OID_sha384WithRSAEncryption:
 		ctx->cert->sig->hash_algo = "sha384";
-		ctx->cert->sig->pkey_algo = "rsa";
-		break;
+		goto rsa_pkcs1;
 
 	case OID_sha512WithRSAEncryption:
 		ctx->cert->sig->hash_algo = "sha512";
-		ctx->cert->sig->pkey_algo = "rsa";
-		break;
+		goto rsa_pkcs1;
 
 	case OID_sha224WithRSAEncryption:
 		ctx->cert->sig->hash_algo = "sha224";
-		ctx->cert->sig->pkey_algo = "rsa";
-		break;
+		goto rsa_pkcs1;
 	}
 
+rsa_pkcs1:
+	ctx->cert->sig->pkey_algo = "rsa";
+	ctx->cert->sig->encoding = "pkcs1";
 	ctx->algo_oid = ctx->last_oid;
 	return 0;
 }