Commit f7c4e06e authored by David Howells's avatar David Howells Committed by James Morris

KEYS: Allow the public_key struct to hold a private key [ver #2]

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: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Reviewed-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Reviewed-by: default avatarDenis Kenzior <denkenz@gmail.com>
Tested-by: default avatarDenis Kenzior <denkenz@gmail.com>
Signed-off-by: default avatarJames Morris <james.morris@microsoft.com>
parent 82f94f24
...@@ -115,7 +115,12 @@ static int software_key_query(const struct kernel_pkey_params *params, ...@@ -115,7 +115,12 @@ static int software_key_query(const struct kernel_pkey_params *params,
if (IS_ERR(tfm)) if (IS_ERR(tfm))
return PTR_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) if (ret < 0)
goto error_free_tfm; goto error_free_tfm;
...@@ -170,7 +175,12 @@ int public_key_verify_signature(const struct public_key *pkey, ...@@ -170,7 +175,12 @@ int public_key_verify_signature(const struct public_key *pkey,
if (!req) if (!req)
goto error_free_tfm; 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) if (ret)
goto error_free_req; goto error_free_req;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
struct public_key { struct public_key {
void *key; void *key;
u32 keylen; u32 keylen;
bool key_is_private;
const char *id_type; const char *id_type;
const char *pkey_algo; const char *pkey_algo;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment