aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys/big_key.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/keys/big_key.c')
-rw-r--r--security/keys/big_key.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index c0b3030b5634..835c1ab30d01 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -9,6 +9,7 @@
9 * 2 of the Licence, or (at your option) any later version. 9 * 2 of the Licence, or (at your option) any later version.
10 */ 10 */
11 11
12#define pr_fmt(fmt) "big_key: "fmt
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/seq_file.h> 14#include <linux/seq_file.h>
14#include <linux/file.h> 15#include <linux/file.h>
@@ -341,44 +342,48 @@ error:
341 */ 342 */
342static int __init big_key_init(void) 343static int __init big_key_init(void)
343{ 344{
344 return register_key_type(&key_type_big_key); 345 struct crypto_skcipher *cipher;
345} 346 struct crypto_rng *rng;
346 347 int ret;
347/*
348 * Initialize big_key crypto and RNG algorithms
349 */
350static int __init big_key_crypto_init(void)
351{
352 int ret = -EINVAL;
353 348
354 /* init RNG */ 349 rng = crypto_alloc_rng(big_key_rng_name, 0, 0);
355 big_key_rng = crypto_alloc_rng(big_key_rng_name, 0, 0); 350 if (IS_ERR(rng)) {
356 if (IS_ERR(big_key_rng)) { 351 pr_err("Can't alloc rng: %ld\n", PTR_ERR(rng));
357 big_key_rng = NULL; 352 return PTR_ERR(rng);
358 return -EFAULT;
359 } 353 }
360 354
355 big_key_rng = rng;
356
361 /* seed RNG */ 357 /* seed RNG */
362 ret = crypto_rng_reset(big_key_rng, NULL, crypto_rng_seedsize(big_key_rng)); 358 ret = crypto_rng_reset(rng, NULL, crypto_rng_seedsize(rng));
363 if (ret) 359 if (ret) {
364 goto error; 360 pr_err("Can't reset rng: %d\n", ret);
361 goto error_rng;
362 }
365 363
366 /* init block cipher */ 364 /* init block cipher */
367 big_key_skcipher = crypto_alloc_skcipher(big_key_alg_name, 365 cipher = crypto_alloc_skcipher(big_key_alg_name, 0, CRYPTO_ALG_ASYNC);
368 0, CRYPTO_ALG_ASYNC); 366 if (IS_ERR(cipher)) {
369 if (IS_ERR(big_key_skcipher)) { 367 ret = PTR_ERR(cipher);
370 big_key_skcipher = NULL; 368 pr_err("Can't alloc crypto: %d\n", ret);
371 ret = -EFAULT; 369 goto error_rng;
372 goto error; 370 }
371
372 big_key_skcipher = cipher;
373
374 ret = register_key_type(&key_type_big_key);
375 if (ret < 0) {
376 pr_err("Can't register type: %d\n", ret);
377 goto error_cipher;
373 } 378 }
374 379
375 return 0; 380 return 0;
376 381
377error: 382error_cipher:
383 crypto_free_skcipher(big_key_skcipher);
384error_rng:
378 crypto_free_rng(big_key_rng); 385 crypto_free_rng(big_key_rng);
379 big_key_rng = NULL;
380 return ret; 386 return ret;
381} 387}
382 388
383device_initcall(big_key_init); 389late_initcall(big_key_init);
384late_initcall(big_key_crypto_init);