Skip to content

Commit f7c4e06

Browse files
dhowellsJames Morris
authored andcommitted
KEYS: Allow the public_key struct to hold a private key [ver raspberrypi#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: David Howells <dhowells@redhat.com> Tested-by: Marcel Holtmann <marcel@holtmann.org> Reviewed-by: Marcel Holtmann <marcel@holtmann.org> Reviewed-by: Denis Kenzior <denkenz@gmail.com> Tested-by: Denis Kenzior <denkenz@gmail.com> Signed-off-by: James Morris <james.morris@microsoft.com>
1 parent 82f94f2 commit f7c4e06

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎crypto/asymmetric_keys/public_key.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ static int software_key_query(const struct kernel_pkey_params *params,
115115
if (IS_ERR(tfm))
116116
return PTR_ERR(tfm);
117117

118-
ret = crypto_akcipher_set_pub_key(tfm, pkey->key, pkey->keylen);
118+
if (pkey->key_is_private)
119+
ret = crypto_akcipher_set_priv_key(tfm,
120+
pkey->key, pkey->keylen);
121+
else
122+
ret = crypto_akcipher_set_pub_key(tfm,
123+
pkey->key, pkey->keylen);
119124
if (ret < 0)
120125
goto error_free_tfm;
121126

@@ -170,7 +175,12 @@ int public_key_verify_signature(const struct public_key *pkey,
170175
if (!req)
171176
goto error_free_tfm;
172177

173-
ret = crypto_akcipher_set_pub_key(tfm, pkey->key, pkey->keylen);
178+
if (pkey->key_is_private)
179+
ret = crypto_akcipher_set_priv_key(tfm,
180+
pkey->key, pkey->keylen);
181+
else
182+
ret = crypto_akcipher_set_pub_key(tfm,
183+
pkey->key, pkey->keylen);
174184
if (ret)
175185
goto error_free_req;
176186

‎include/crypto/public_key.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
struct public_key {
2626
void *key;
2727
u32 keylen;
28+
bool key_is_private;
2829
const char *id_type;
2930
const char *pkey_algo;
3031
};

0 commit comments

Comments
 (0)