KEYS: Allow the public_key struct to hold a private key
authorDavid Howells <dhowells@redhat.com>
Thu, 1 Sep 2016 10:13:13 +0000 (11:13 +0100)
committerDavid Howells <dhowells@redhat.com>
Thu, 1 Sep 2016 10:13:13 +0000 (11:13 +0100)
Put a flag in the public_key struct to indicate if the structure is holding
a private key.  The private key must be held ASN.1 encoded in the format
specified in RFC 3447 A.1.2.  This is the form required by crypto/rsa.c.

The software encryption subtype's verification and query functions then
need to select the appropriate crypto function to set the key.

Signed-off-by: David Howells <dhowells@redhat.com>
crypto/asymmetric_keys/public_key.c
include/crypto/public_key.h

index a48a47a1dff0a10c9461d9bd0dc9ea4fec111bc0..a29ca01a41a086cd976e0a55b77ad3971ae44951 100644 (file)
@@ -113,7 +113,12 @@ static int software_key_query(const struct kernel_pkey_params *params,
        if (IS_ERR(tfm))
                return PTR_ERR(tfm);
 
-       ret = crypto_akcipher_set_pub_key(tfm, pkey->key, pkey->keylen);
+       if (pkey->key_is_private)
+               ret = crypto_akcipher_set_priv_key(tfm,
+                                                  pkey->key, pkey->keylen);
+       else
+               ret = crypto_akcipher_set_pub_key(tfm,
+                                                 pkey->key, pkey->keylen);
        if (ret < 0)
                goto error_free_tfm;
 
@@ -184,7 +189,12 @@ int public_key_verify_signature(const struct public_key *pkey,
        if (!req)
                goto error_free_tfm;
 
-       ret = crypto_akcipher_set_pub_key(tfm, pkey->key, pkey->keylen);
+       if (pkey->key_is_private)
+               ret = crypto_akcipher_set_priv_key(tfm,
+                                                  pkey->key, pkey->keylen);
+       else
+               ret = crypto_akcipher_set_pub_key(tfm,
+                                                 pkey->key, pkey->keylen);
        if (ret)
                goto error_free_req;
 
index c46140d3729c91507ce07b14cedd6f1ed65a06f8..c5e569b2a73e1f379d72abe555d076d962a20cae 100644 (file)
@@ -25,6 +25,7 @@
 struct public_key {
        void *key;
        u32 keylen;
+       bool key_is_private;
        const char *id_type;
        const char *pkey_algo;
 };
This page took 0.026001 seconds and 5 git commands to generate.