2 * Copyright (C) 2010 IBM Corporation
3 * Copyright (C) 2010 Politecnico di Torino, Italy
4 * TORSEC group -- http://security.polito.it
7 * Mimi Zohar <zohar@us.ibm.com>
8 * Roberto Sassu <roberto.sassu@polito.it>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, version 2 of the License.
14 * See Documentation/security/keys-trusted-encrypted.txt
17 #include <linux/uaccess.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/slab.h>
21 #include <linux/parser.h>
22 #include <linux/string.h>
23 #include <linux/err.h>
24 #include <keys/user-type.h>
25 #include <keys/trusted-type.h>
26 #include <keys/encrypted-type.h>
27 #include <linux/key-type.h>
28 #include <linux/random.h>
29 #include <linux/rcupdate.h>
30 #include <linux/scatterlist.h>
31 #include <linux/crypto.h>
32 #include <crypto/hash.h>
33 #include <crypto/sha.h>
34 #include <crypto/aes.h>
36 #include "encrypted.h"
38 static const char KEY_TRUSTED_PREFIX[] = "trusted:";
39 static const char KEY_USER_PREFIX[] = "user:";
40 static const char hash_alg[] = "sha256";
41 static const char hmac_alg[] = "hmac(sha256)";
42 static const char blkcipher_alg[] = "cbc(aes)";
43 static const char key_format_default[] = "default";
44 static unsigned int ivsize;
47 #define KEY_TRUSTED_PREFIX_LEN (sizeof (KEY_TRUSTED_PREFIX) - 1)
48 #define KEY_USER_PREFIX_LEN (sizeof (KEY_USER_PREFIX) - 1)
49 #define HASH_SIZE SHA256_DIGEST_SIZE
50 #define MAX_DATA_SIZE 4096
51 #define MIN_DATA_SIZE 20
54 struct shash_desc shash;
58 static struct crypto_shash *hashalg;
59 static struct crypto_shash *hmacalg;
62 Opt_err = -1, Opt_new, Opt_load, Opt_update
66 Opt_error = -1, Opt_default
69 static const match_table_t key_format_tokens = {
70 {Opt_default, "default"},
74 static const match_table_t key_tokens = {
77 {Opt_update, "update"},
81 static int aes_get_sizes(void)
83 struct crypto_blkcipher *tfm;
85 tfm = crypto_alloc_blkcipher(blkcipher_alg, 0, CRYPTO_ALG_ASYNC);
87 pr_err("encrypted_key: failed to alloc_cipher (%ld)\n",
91 ivsize = crypto_blkcipher_ivsize(tfm);
92 blksize = crypto_blkcipher_blocksize(tfm);
93 crypto_free_blkcipher(tfm);
98 * valid_master_desc - verify the 'key-type:desc' of a new/updated master-key
100 * key-type:= "trusted:" | "user:"
101 * desc:= master-key description
103 * Verify that 'key-type' is valid and that 'desc' exists. On key update,
104 * only the master key description is permitted to change, not the key-type.
105 * The key-type remains constant.
107 * On success returns 0, otherwise -EINVAL.
109 static int valid_master_desc(const char *new_desc, const char *orig_desc)
111 if (!memcmp(new_desc, KEY_TRUSTED_PREFIX, KEY_TRUSTED_PREFIX_LEN)) {
112 if (strlen(new_desc) == KEY_TRUSTED_PREFIX_LEN)
115 if (memcmp(new_desc, orig_desc, KEY_TRUSTED_PREFIX_LEN))
117 } else if (!memcmp(new_desc, KEY_USER_PREFIX, KEY_USER_PREFIX_LEN)) {
118 if (strlen(new_desc) == KEY_USER_PREFIX_LEN)
121 if (memcmp(new_desc, orig_desc, KEY_USER_PREFIX_LEN))
131 * datablob_parse - parse the keyctl data
134 * new [<format>] <master-key name> <decrypted data length>
135 * load [<format>] <master-key name> <decrypted data length>
136 * <encrypted iv + data>
137 * update <new-master-key name>
139 * Tokenizes a copy of the keyctl data, returning a pointer to each token,
140 * which is null terminated.
142 * On success returns 0, otherwise -EINVAL.
144 static int datablob_parse(char *datablob, const char **format,
145 char **master_desc, char **decrypted_datalen,
146 char **hex_encoded_iv)
148 substring_t args[MAX_OPT_ARGS];
154 keyword = strsep(&datablob, " \t");
156 pr_info("encrypted_key: insufficient parameters specified\n");
159 key_cmd = match_token(keyword, key_tokens, args);
161 /* Get optional format: default */
162 p = strsep(&datablob, " \t");
164 pr_err("encrypted_key: insufficient parameters specified\n");
168 key_format = match_token(p, key_format_tokens, args);
169 switch (key_format) {
172 *master_desc = strsep(&datablob, " \t");
180 pr_info("encrypted_key: master key parameter is missing\n");
184 if (valid_master_desc(*master_desc, NULL) < 0) {
185 pr_info("encrypted_key: master key parameter \'%s\' "
186 "is invalid\n", *master_desc);
190 if (decrypted_datalen) {
191 *decrypted_datalen = strsep(&datablob, " \t");
192 if (!*decrypted_datalen) {
193 pr_info("encrypted_key: keylen parameter is missing\n");
200 if (!decrypted_datalen) {
201 pr_info("encrypted_key: keyword \'%s\' not allowed "
202 "when called from .update method\n", keyword);
208 if (!decrypted_datalen) {
209 pr_info("encrypted_key: keyword \'%s\' not allowed "
210 "when called from .update method\n", keyword);
213 *hex_encoded_iv = strsep(&datablob, " \t");
214 if (!*hex_encoded_iv) {
215 pr_info("encrypted_key: hex blob is missing\n");
221 if (decrypted_datalen) {
222 pr_info("encrypted_key: keyword \'%s\' not allowed "
223 "when called from .instantiate method\n",
230 pr_info("encrypted_key: keyword \'%s\' not recognized\n",
239 * datablob_format - format as an ascii string, before copying to userspace
241 static char *datablob_format(struct encrypted_key_payload *epayload,
242 size_t asciiblob_len)
244 char *ascii_buf, *bufp;
245 u8 *iv = epayload->iv;
249 ascii_buf = kmalloc(asciiblob_len + 1, GFP_KERNEL);
253 ascii_buf[asciiblob_len] = '\0';
255 /* copy datablob master_desc and datalen strings */
256 len = sprintf(ascii_buf, "%s %s %s ", epayload->format,
257 epayload->master_desc, epayload->datalen);
259 /* convert the hex encoded iv, encrypted-data and HMAC to ascii */
260 bufp = &ascii_buf[len];
261 for (i = 0; i < (asciiblob_len - len) / 2; i++)
262 bufp = pack_hex_byte(bufp, iv[i]);
268 * request_trusted_key - request the trusted key
270 * Trusted keys are sealed to PCRs and other metadata. Although userspace
271 * manages both trusted/encrypted key-types, like the encrypted key type
272 * data, trusted key type data is not visible decrypted from userspace.
274 static struct key *request_trusted_key(const char *trusted_desc,
275 u8 **master_key, size_t *master_keylen)
277 struct trusted_key_payload *tpayload;
280 tkey = request_key(&key_type_trusted, trusted_desc, NULL);
284 down_read(&tkey->sem);
285 tpayload = rcu_dereference(tkey->payload.data);
286 *master_key = tpayload->key;
287 *master_keylen = tpayload->key_len;
293 * request_user_key - request the user key
295 * Use a user provided key to encrypt/decrypt an encrypted-key.
297 static struct key *request_user_key(const char *master_desc, u8 **master_key,
298 size_t *master_keylen)
300 struct user_key_payload *upayload;
303 ukey = request_key(&key_type_user, master_desc, NULL);
307 down_read(&ukey->sem);
308 upayload = rcu_dereference(ukey->payload.data);
309 *master_key = upayload->data;
310 *master_keylen = upayload->datalen;
315 static struct sdesc *alloc_sdesc(struct crypto_shash *alg)
320 size = sizeof(struct shash_desc) + crypto_shash_descsize(alg);
321 sdesc = kmalloc(size, GFP_KERNEL);
323 return ERR_PTR(-ENOMEM);
324 sdesc->shash.tfm = alg;
325 sdesc->shash.flags = 0x0;
329 static int calc_hmac(u8 *digest, const u8 *key, unsigned int keylen,
330 const u8 *buf, unsigned int buflen)
335 sdesc = alloc_sdesc(hmacalg);
337 pr_info("encrypted_key: can't alloc %s\n", hmac_alg);
338 return PTR_ERR(sdesc);
341 ret = crypto_shash_setkey(hmacalg, key, keylen);
343 ret = crypto_shash_digest(&sdesc->shash, buf, buflen, digest);
348 static int calc_hash(u8 *digest, const u8 *buf, unsigned int buflen)
353 sdesc = alloc_sdesc(hashalg);
355 pr_info("encrypted_key: can't alloc %s\n", hash_alg);
356 return PTR_ERR(sdesc);
359 ret = crypto_shash_digest(&sdesc->shash, buf, buflen, digest);
364 enum derived_key_type { ENC_KEY, AUTH_KEY };
366 /* Derive authentication/encryption key from trusted key */
367 static int get_derived_key(u8 *derived_key, enum derived_key_type key_type,
368 const u8 *master_key, size_t master_keylen)
371 unsigned int derived_buf_len;
374 derived_buf_len = strlen("AUTH_KEY") + 1 + master_keylen;
375 if (derived_buf_len < HASH_SIZE)
376 derived_buf_len = HASH_SIZE;
378 derived_buf = kzalloc(derived_buf_len, GFP_KERNEL);
380 pr_err("encrypted_key: out of memory\n");
384 strcpy(derived_buf, "AUTH_KEY");
386 strcpy(derived_buf, "ENC_KEY");
388 memcpy(derived_buf + strlen(derived_buf) + 1, master_key,
390 ret = calc_hash(derived_key, derived_buf, derived_buf_len);
395 static int init_blkcipher_desc(struct blkcipher_desc *desc, const u8 *key,
396 unsigned int key_len, const u8 *iv,
401 desc->tfm = crypto_alloc_blkcipher(blkcipher_alg, 0, CRYPTO_ALG_ASYNC);
402 if (IS_ERR(desc->tfm)) {
403 pr_err("encrypted_key: failed to load %s transform (%ld)\n",
404 blkcipher_alg, PTR_ERR(desc->tfm));
405 return PTR_ERR(desc->tfm);
409 ret = crypto_blkcipher_setkey(desc->tfm, key, key_len);
411 pr_err("encrypted_key: failed to setkey (%d)\n", ret);
412 crypto_free_blkcipher(desc->tfm);
415 crypto_blkcipher_set_iv(desc->tfm, iv, ivsize);
419 static struct key *request_master_key(struct encrypted_key_payload *epayload,
420 u8 **master_key, size_t *master_keylen)
422 struct key *mkey = NULL;
424 if (!strncmp(epayload->master_desc, KEY_TRUSTED_PREFIX,
425 KEY_TRUSTED_PREFIX_LEN)) {
426 mkey = request_trusted_key(epayload->master_desc +
427 KEY_TRUSTED_PREFIX_LEN,
428 master_key, master_keylen);
429 } else if (!strncmp(epayload->master_desc, KEY_USER_PREFIX,
430 KEY_USER_PREFIX_LEN)) {
431 mkey = request_user_key(epayload->master_desc +
433 master_key, master_keylen);
438 pr_info("encrypted_key: key %s not found",
439 epayload->master_desc);
443 dump_master_key(*master_key, *master_keylen);
448 /* Before returning data to userspace, encrypt decrypted data. */
449 static int derived_key_encrypt(struct encrypted_key_payload *epayload,
450 const u8 *derived_key,
451 unsigned int derived_keylen)
453 struct scatterlist sg_in[2];
454 struct scatterlist sg_out[1];
455 struct blkcipher_desc desc;
456 unsigned int encrypted_datalen;
461 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize);
462 padlen = encrypted_datalen - epayload->decrypted_datalen;
464 ret = init_blkcipher_desc(&desc, derived_key, derived_keylen,
465 epayload->iv, ivsize);
468 dump_decrypted_data(epayload);
470 memset(pad, 0, sizeof pad);
471 sg_init_table(sg_in, 2);
472 sg_set_buf(&sg_in[0], epayload->decrypted_data,
473 epayload->decrypted_datalen);
474 sg_set_buf(&sg_in[1], pad, padlen);
476 sg_init_table(sg_out, 1);
477 sg_set_buf(sg_out, epayload->encrypted_data, encrypted_datalen);
479 ret = crypto_blkcipher_encrypt(&desc, sg_out, sg_in, encrypted_datalen);
480 crypto_free_blkcipher(desc.tfm);
482 pr_err("encrypted_key: failed to encrypt (%d)\n", ret);
484 dump_encrypted_data(epayload, encrypted_datalen);
489 static int datablob_hmac_append(struct encrypted_key_payload *epayload,
490 const u8 *master_key, size_t master_keylen)
492 u8 derived_key[HASH_SIZE];
496 ret = get_derived_key(derived_key, AUTH_KEY, master_key, master_keylen);
500 digest = epayload->format + epayload->datablob_len;
501 ret = calc_hmac(digest, derived_key, sizeof derived_key,
502 epayload->format, epayload->datablob_len);
504 dump_hmac(NULL, digest, HASH_SIZE);
509 /* verify HMAC before decrypting encrypted key */
510 static int datablob_hmac_verify(struct encrypted_key_payload *epayload,
511 const u8 *format, const u8 *master_key,
512 size_t master_keylen)
514 u8 derived_key[HASH_SIZE];
515 u8 digest[HASH_SIZE];
520 ret = get_derived_key(derived_key, AUTH_KEY, master_key, master_keylen);
524 len = epayload->datablob_len;
526 p = epayload->master_desc;
527 len -= strlen(epayload->format) + 1;
529 p = epayload->format;
531 ret = calc_hmac(digest, derived_key, sizeof derived_key, p, len);
534 ret = memcmp(digest, epayload->format + epayload->datablob_len,
538 dump_hmac("datablob",
539 epayload->format + epayload->datablob_len,
541 dump_hmac("calc", digest, HASH_SIZE);
547 static int derived_key_decrypt(struct encrypted_key_payload *epayload,
548 const u8 *derived_key,
549 unsigned int derived_keylen)
551 struct scatterlist sg_in[1];
552 struct scatterlist sg_out[2];
553 struct blkcipher_desc desc;
554 unsigned int encrypted_datalen;
558 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize);
559 ret = init_blkcipher_desc(&desc, derived_key, derived_keylen,
560 epayload->iv, ivsize);
563 dump_encrypted_data(epayload, encrypted_datalen);
565 memset(pad, 0, sizeof pad);
566 sg_init_table(sg_in, 1);
567 sg_init_table(sg_out, 2);
568 sg_set_buf(sg_in, epayload->encrypted_data, encrypted_datalen);
569 sg_set_buf(&sg_out[0], epayload->decrypted_data,
570 epayload->decrypted_datalen);
571 sg_set_buf(&sg_out[1], pad, sizeof pad);
573 ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in, encrypted_datalen);
574 crypto_free_blkcipher(desc.tfm);
577 dump_decrypted_data(epayload);
582 /* Allocate memory for decrypted key and datablob. */
583 static struct encrypted_key_payload *encrypted_key_alloc(struct key *key,
585 const char *master_desc,
588 struct encrypted_key_payload *epayload = NULL;
589 unsigned short datablob_len;
590 unsigned short decrypted_datalen;
591 unsigned short payload_datalen;
592 unsigned int encrypted_datalen;
593 unsigned int format_len;
597 ret = strict_strtol(datalen, 10, &dlen);
598 if (ret < 0 || dlen < MIN_DATA_SIZE || dlen > MAX_DATA_SIZE)
599 return ERR_PTR(-EINVAL);
601 format_len = (!format) ? strlen(key_format_default) : strlen(format);
602 decrypted_datalen = dlen;
603 payload_datalen = decrypted_datalen;
604 encrypted_datalen = roundup(decrypted_datalen, blksize);
606 datablob_len = format_len + 1 + strlen(master_desc) + 1
607 + strlen(datalen) + 1 + ivsize + 1 + encrypted_datalen;
609 ret = key_payload_reserve(key, payload_datalen + datablob_len
614 epayload = kzalloc(sizeof(*epayload) + payload_datalen +
615 datablob_len + HASH_SIZE + 1, GFP_KERNEL);
617 return ERR_PTR(-ENOMEM);
619 epayload->payload_datalen = payload_datalen;
620 epayload->decrypted_datalen = decrypted_datalen;
621 epayload->datablob_len = datablob_len;
625 static int encrypted_key_decrypt(struct encrypted_key_payload *epayload,
626 const char *format, const char *hex_encoded_iv)
629 u8 derived_key[HASH_SIZE];
632 const char *hex_encoded_data;
633 unsigned int encrypted_datalen;
634 size_t master_keylen;
638 encrypted_datalen = roundup(epayload->decrypted_datalen, blksize);
639 asciilen = (ivsize + 1 + encrypted_datalen + HASH_SIZE) * 2;
640 if (strlen(hex_encoded_iv) != asciilen)
643 hex_encoded_data = hex_encoded_iv + (2 * ivsize) + 2;
644 hex2bin(epayload->iv, hex_encoded_iv, ivsize);
645 hex2bin(epayload->encrypted_data, hex_encoded_data, encrypted_datalen);
647 hmac = epayload->format + epayload->datablob_len;
648 hex2bin(hmac, hex_encoded_data + (encrypted_datalen * 2), HASH_SIZE);
650 mkey = request_master_key(epayload, &master_key, &master_keylen);
652 return PTR_ERR(mkey);
654 ret = datablob_hmac_verify(epayload, format, master_key, master_keylen);
656 pr_err("encrypted_key: bad hmac (%d)\n", ret);
660 ret = get_derived_key(derived_key, ENC_KEY, master_key, master_keylen);
664 ret = derived_key_decrypt(epayload, derived_key, sizeof derived_key);
666 pr_err("encrypted_key: failed to decrypt key (%d)\n", ret);
673 static void __ekey_init(struct encrypted_key_payload *epayload,
674 const char *format, const char *master_desc,
677 unsigned int format_len;
679 format_len = (!format) ? strlen(key_format_default) : strlen(format);
680 epayload->format = epayload->payload_data + epayload->payload_datalen;
681 epayload->master_desc = epayload->format + format_len + 1;
682 epayload->datalen = epayload->master_desc + strlen(master_desc) + 1;
683 epayload->iv = epayload->datalen + strlen(datalen) + 1;
684 epayload->encrypted_data = epayload->iv + ivsize + 1;
685 epayload->decrypted_data = epayload->payload_data;
688 memcpy(epayload->format, key_format_default, format_len);
690 memcpy(epayload->format, format, format_len);
691 memcpy(epayload->master_desc, master_desc, strlen(master_desc));
692 memcpy(epayload->datalen, datalen, strlen(datalen));
696 * encrypted_init - initialize an encrypted key
698 * For a new key, use a random number for both the iv and data
699 * itself. For an old key, decrypt the hex encoded data.
701 static int encrypted_init(struct encrypted_key_payload *epayload,
702 const char *format, const char *master_desc,
703 const char *datalen, const char *hex_encoded_iv)
707 __ekey_init(epayload, format, master_desc, datalen);
708 if (!hex_encoded_iv) {
709 get_random_bytes(epayload->iv, ivsize);
711 get_random_bytes(epayload->decrypted_data,
712 epayload->decrypted_datalen);
714 ret = encrypted_key_decrypt(epayload, format, hex_encoded_iv);
719 * encrypted_instantiate - instantiate an encrypted key
721 * Decrypt an existing encrypted datablob or create a new encrypted key
722 * based on a kernel random number.
724 * On success, return 0. Otherwise return errno.
726 static int encrypted_instantiate(struct key *key, const void *data,
729 struct encrypted_key_payload *epayload = NULL;
730 char *datablob = NULL;
731 const char *format = NULL;
732 char *master_desc = NULL;
733 char *decrypted_datalen = NULL;
734 char *hex_encoded_iv = NULL;
737 if (datalen <= 0 || datalen > 32767 || !data)
740 datablob = kmalloc(datalen + 1, GFP_KERNEL);
743 datablob[datalen] = 0;
744 memcpy(datablob, data, datalen);
745 ret = datablob_parse(datablob, &format, &master_desc,
746 &decrypted_datalen, &hex_encoded_iv);
750 epayload = encrypted_key_alloc(key, format, master_desc,
752 if (IS_ERR(epayload)) {
753 ret = PTR_ERR(epayload);
756 ret = encrypted_init(epayload, format, master_desc, decrypted_datalen,
763 rcu_assign_pointer(key->payload.data, epayload);
769 static void encrypted_rcu_free(struct rcu_head *rcu)
771 struct encrypted_key_payload *epayload;
773 epayload = container_of(rcu, struct encrypted_key_payload, rcu);
774 memset(epayload->decrypted_data, 0, epayload->decrypted_datalen);
779 * encrypted_update - update the master key description
781 * Change the master key description for an existing encrypted key.
782 * The next read will return an encrypted datablob using the new
783 * master key description.
785 * On success, return 0. Otherwise return errno.
787 static int encrypted_update(struct key *key, const void *data, size_t datalen)
789 struct encrypted_key_payload *epayload = key->payload.data;
790 struct encrypted_key_payload *new_epayload;
792 char *new_master_desc = NULL;
793 const char *format = NULL;
796 if (datalen <= 0 || datalen > 32767 || !data)
799 buf = kmalloc(datalen + 1, GFP_KERNEL);
804 memcpy(buf, data, datalen);
805 ret = datablob_parse(buf, &format, &new_master_desc, NULL, NULL);
809 ret = valid_master_desc(new_master_desc, epayload->master_desc);
813 new_epayload = encrypted_key_alloc(key, epayload->format,
814 new_master_desc, epayload->datalen);
815 if (IS_ERR(new_epayload)) {
816 ret = PTR_ERR(new_epayload);
820 __ekey_init(new_epayload, epayload->format, new_master_desc,
823 memcpy(new_epayload->iv, epayload->iv, ivsize);
824 memcpy(new_epayload->payload_data, epayload->payload_data,
825 epayload->payload_datalen);
827 rcu_assign_pointer(key->payload.data, new_epayload);
828 call_rcu(&epayload->rcu, encrypted_rcu_free);
835 * encrypted_read - format and copy the encrypted data to userspace
837 * The resulting datablob format is:
838 * <master-key name> <decrypted data length> <encrypted iv> <encrypted data>
840 * On success, return to userspace the encrypted key datablob size.
842 static long encrypted_read(const struct key *key, char __user *buffer,
845 struct encrypted_key_payload *epayload;
848 size_t master_keylen;
849 char derived_key[HASH_SIZE];
851 size_t asciiblob_len;
854 epayload = rcu_dereference_key(key);
856 /* returns the hex encoded iv, encrypted-data, and hmac as ascii */
857 asciiblob_len = epayload->datablob_len + ivsize + 1
858 + roundup(epayload->decrypted_datalen, blksize)
861 if (!buffer || buflen < asciiblob_len)
862 return asciiblob_len;
864 mkey = request_master_key(epayload, &master_key, &master_keylen);
866 return PTR_ERR(mkey);
868 ret = get_derived_key(derived_key, ENC_KEY, master_key, master_keylen);
872 ret = derived_key_encrypt(epayload, derived_key, sizeof derived_key);
876 ret = datablob_hmac_append(epayload, master_key, master_keylen);
880 ascii_buf = datablob_format(epayload, asciiblob_len);
889 if (copy_to_user(buffer, ascii_buf, asciiblob_len) != 0)
893 return asciiblob_len;
901 * encrypted_destroy - before freeing the key, clear the decrypted data
903 * Before freeing the key, clear the memory containing the decrypted
906 static void encrypted_destroy(struct key *key)
908 struct encrypted_key_payload *epayload = key->payload.data;
913 memset(epayload->decrypted_data, 0, epayload->decrypted_datalen);
914 kfree(key->payload.data);
917 struct key_type key_type_encrypted = {
919 .instantiate = encrypted_instantiate,
920 .update = encrypted_update,
922 .destroy = encrypted_destroy,
923 .describe = user_describe,
924 .read = encrypted_read,
926 EXPORT_SYMBOL_GPL(key_type_encrypted);
928 static void encrypted_shash_release(void)
931 crypto_free_shash(hashalg);
933 crypto_free_shash(hmacalg);
936 static int __init encrypted_shash_alloc(void)
940 hmacalg = crypto_alloc_shash(hmac_alg, 0, CRYPTO_ALG_ASYNC);
941 if (IS_ERR(hmacalg)) {
942 pr_info("encrypted_key: could not allocate crypto %s\n",
944 return PTR_ERR(hmacalg);
947 hashalg = crypto_alloc_shash(hash_alg, 0, CRYPTO_ALG_ASYNC);
948 if (IS_ERR(hashalg)) {
949 pr_info("encrypted_key: could not allocate crypto %s\n",
951 ret = PTR_ERR(hashalg);
958 crypto_free_shash(hmacalg);
962 static int __init init_encrypted(void)
966 ret = encrypted_shash_alloc();
969 ret = register_key_type(&key_type_encrypted);
972 return aes_get_sizes();
974 encrypted_shash_release();
979 static void __exit cleanup_encrypted(void)
981 encrypted_shash_release();
982 unregister_key_type(&key_type_encrypted);
985 late_initcall(init_encrypted);
986 module_exit(cleanup_encrypted);
988 MODULE_LICENSE("GPL");