12 #include <linux/kernel.h>
49 size_t digest_size, desc_size;
59 return (PTR_ERR(tfm) == -
ENOENT) ? ERR_PTR(-
ENOPKG) : ERR_CAST(tfm);
61 desc_size = crypto_shash_descsize(tfm) +
sizeof(*desc);
62 digest_size = crypto_shash_digestsize(tfm);
68 pks = kzalloc(digest_size +
sizeof(*pks) + desc_size,
GFP_KERNEL);
72 pks->pkey_hash_algo =
hash;
73 pks->
digest = (
u8 *)pks +
sizeof(*pks) + desc_size;
76 desc = (
void *)pks +
sizeof(*pks);
80 ret = crypto_shash_init(desc);
88 crypto_free_shash(tfm);
89 pr_devel(
"<==%s() = ok\n", __func__);
95 crypto_free_shash(tfm);
96 pr_devel(
"<==%s() = %d\n", __func__, ret);
108 const void *
data,
size_t len)
115 nbytes = ((
const u8 *)data)[0] << 8 | ((
const u8 *)data)[1];
132 static struct key *request_asymmetric_key(
const char *signer,
size_t signer_len,
133 const u8 *
key_id,
size_t key_id_len)
139 pr_devel(
"==>%s(,%zu,,%zu)\n", __func__, signer_len, key_id_len);
146 memcpy(
id, signer, signer_len);
151 for (i = 0; i < key_id_len; i++) {
153 *q++ =
hex_asc[*key_id++ & 0x0f];
163 pr_warn(
"Request for unknown module key '%s' err %ld\n",
168 switch (PTR_ERR(key)) {
175 return ERR_CAST(key);
179 pr_devel(
"<==%s() = 0 [%x]\n", __func__, key_serial(key_ref_to_ptr(key)));
180 return key_ref_to_ptr(key);
192 size_t modlen = *_modlen, sig_len;
195 pr_devel(
"==>%s(,%zu)\n", __func__, modlen);
197 if (modlen <=
sizeof(ms))
200 memcpy(&ms, mod + (modlen -
sizeof(ms)),
sizeof(ms));
201 modlen -=
sizeof(
ms);
204 if (sig_len >= modlen)
223 key = request_asymmetric_key(sig, ms.
signer_len,
228 pks = mod_make_digest(ms.
hash, mod, modlen);
240 pr_devel(
"verify_signature() = %d\n", ret);
247 pr_devel(
"<==%s() = %d\n", __func__, ret);