aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-04-20 01:39:03 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-04-20 22:19:57 -0400
commitd0e83059a6c9b04f00264a74b8f6439948de4613 (patch)
tree18cce1bc75fad593b10995e50197f41d2a9ca267
parentf7c9bebe8bc79ddb8a50db441a53b59b61ae3ba8 (diff)
crypto: rng - Convert crypto_rng to new style crypto_type
This patch converts the top-level crypto_rng to the "new" style. It was the last algorithm type added before we switched over to the new way of doing things exemplified by shash. All users will automatically switch over to the new interface. Note that this patch does not touch the low-level interface to rng implementations. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/rng.c35
-rw-r--r--include/crypto/rng.h32
-rw-r--r--include/linux/crypto.h12
3 files changed, 33 insertions, 46 deletions
diff --git a/crypto/rng.c b/crypto/rng.c
index e0a25c2456de..87fa2f4933b0 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -24,11 +24,18 @@
24#include <linux/cryptouser.h> 24#include <linux/cryptouser.h>
25#include <net/netlink.h> 25#include <net/netlink.h>
26 26
27#include "internal.h"
28
27static DEFINE_MUTEX(crypto_default_rng_lock); 29static DEFINE_MUTEX(crypto_default_rng_lock);
28struct crypto_rng *crypto_default_rng; 30struct crypto_rng *crypto_default_rng;
29EXPORT_SYMBOL_GPL(crypto_default_rng); 31EXPORT_SYMBOL_GPL(crypto_default_rng);
30static int crypto_default_rng_refcnt; 32static int crypto_default_rng_refcnt;
31 33
34static inline struct crypto_rng *__crypto_rng_cast(struct crypto_tfm *tfm)
35{
36 return container_of(tfm, struct crypto_rng, base);
37}
38
32static int rngapi_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) 39static int rngapi_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
33{ 40{
34 u8 *buf = NULL; 41 u8 *buf = NULL;
@@ -49,13 +56,13 @@ static int rngapi_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
49 return err; 56 return err;
50} 57}
51 58
52static int crypto_init_rng_ops(struct crypto_tfm *tfm, u32 type, u32 mask) 59static int crypto_rng_init_tfm(struct crypto_tfm *tfm)
53{ 60{
61 struct crypto_rng *rng = __crypto_rng_cast(tfm);
54 struct rng_alg *alg = &tfm->__crt_alg->cra_rng; 62 struct rng_alg *alg = &tfm->__crt_alg->cra_rng;
55 struct rng_tfm *ops = &tfm->crt_rng;
56 63
57 ops->rng_gen_random = alg->rng_make_random; 64 rng->generate = alg->rng_make_random;
58 ops->rng_reset = rngapi_reset; 65 rng->seed = rngapi_reset;
59 66
60 return 0; 67 return 0;
61} 68}
@@ -92,22 +99,26 @@ static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
92 seq_printf(m, "seedsize : %u\n", alg->cra_rng.seedsize); 99 seq_printf(m, "seedsize : %u\n", alg->cra_rng.seedsize);
93} 100}
94 101
95static unsigned int crypto_rng_ctxsize(struct crypto_alg *alg, u32 type,
96 u32 mask)
97{
98 return alg->cra_ctxsize;
99}
100
101const struct crypto_type crypto_rng_type = { 102const struct crypto_type crypto_rng_type = {
102 .ctxsize = crypto_rng_ctxsize, 103 .extsize = crypto_alg_extsize,
103 .init = crypto_init_rng_ops, 104 .init_tfm = crypto_rng_init_tfm,
104#ifdef CONFIG_PROC_FS 105#ifdef CONFIG_PROC_FS
105 .show = crypto_rng_show, 106 .show = crypto_rng_show,
106#endif 107#endif
107 .report = crypto_rng_report, 108 .report = crypto_rng_report,
109 .maskclear = ~CRYPTO_ALG_TYPE_MASK,
110 .maskset = CRYPTO_ALG_TYPE_MASK,
111 .type = CRYPTO_ALG_TYPE_RNG,
112 .tfmsize = offsetof(struct crypto_rng, base),
108}; 113};
109EXPORT_SYMBOL_GPL(crypto_rng_type); 114EXPORT_SYMBOL_GPL(crypto_rng_type);
110 115
116struct crypto_rng *crypto_alloc_rng(const char *alg_name, u32 type, u32 mask)
117{
118 return crypto_alloc_tfm(alg_name, &crypto_rng_type, type, mask);
119}
120EXPORT_SYMBOL_GPL(crypto_alloc_rng);
121
111int crypto_get_default_rng(void) 122int crypto_get_default_rng(void)
112{ 123{
113 struct crypto_rng *rng; 124 struct crypto_rng *rng;
diff --git a/include/crypto/rng.h b/include/crypto/rng.h
index 6e28ea5be9f1..f13f3faca4d7 100644
--- a/include/crypto/rng.h
+++ b/include/crypto/rng.h
@@ -15,6 +15,12 @@
15 15
16#include <linux/crypto.h> 16#include <linux/crypto.h>
17 17
18struct crypto_rng {
19 int (*generate)(struct crypto_rng *tfm, u8 *rdata, unsigned int dlen);
20 int (*seed)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
21 struct crypto_tfm base;
22};
23
18extern struct crypto_rng *crypto_default_rng; 24extern struct crypto_rng *crypto_default_rng;
19 25
20int crypto_get_default_rng(void); 26int crypto_get_default_rng(void);
@@ -27,11 +33,6 @@ void crypto_put_default_rng(void);
27 * CRYPTO_ALG_TYPE_RNG (listed as type "rng" in /proc/crypto) 33 * CRYPTO_ALG_TYPE_RNG (listed as type "rng" in /proc/crypto)
28 */ 34 */
29 35
30static inline struct crypto_rng *__crypto_rng_cast(struct crypto_tfm *tfm)
31{
32 return (struct crypto_rng *)tfm;
33}
34
35/** 36/**
36 * crypto_alloc_rng() -- allocate RNG handle 37 * crypto_alloc_rng() -- allocate RNG handle
37 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the 38 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
@@ -52,15 +53,7 @@ static inline struct crypto_rng *__crypto_rng_cast(struct crypto_tfm *tfm)
52 * Return: allocated cipher handle in case of success; IS_ERR() is true in case 53 * Return: allocated cipher handle in case of success; IS_ERR() is true in case
53 * of an error, PTR_ERR() returns the error code. 54 * of an error, PTR_ERR() returns the error code.
54 */ 55 */
55static inline struct crypto_rng *crypto_alloc_rng(const char *alg_name, 56struct crypto_rng *crypto_alloc_rng(const char *alg_name, u32 type, u32 mask);
56 u32 type, u32 mask)
57{
58 type &= ~CRYPTO_ALG_TYPE_MASK;
59 type |= CRYPTO_ALG_TYPE_RNG;
60 mask |= CRYPTO_ALG_TYPE_MASK;
61
62 return __crypto_rng_cast(crypto_alloc_base(alg_name, type, mask));
63}
64 57
65static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm) 58static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm)
66{ 59{
@@ -80,18 +73,13 @@ static inline struct rng_alg *crypto_rng_alg(struct crypto_rng *tfm)
80 return &crypto_rng_tfm(tfm)->__crt_alg->cra_rng; 73 return &crypto_rng_tfm(tfm)->__crt_alg->cra_rng;
81} 74}
82 75
83static inline struct rng_tfm *crypto_rng_crt(struct crypto_rng *tfm)
84{
85 return &crypto_rng_tfm(tfm)->crt_rng;
86}
87
88/** 76/**
89 * crypto_free_rng() - zeroize and free RNG handle 77 * crypto_free_rng() - zeroize and free RNG handle
90 * @tfm: cipher handle to be freed 78 * @tfm: cipher handle to be freed
91 */ 79 */
92static inline void crypto_free_rng(struct crypto_rng *tfm) 80static inline void crypto_free_rng(struct crypto_rng *tfm)
93{ 81{
94 crypto_free_tfm(crypto_rng_tfm(tfm)); 82 crypto_destroy_tfm(tfm, crypto_rng_tfm(tfm));
95} 83}
96 84
97/** 85/**
@@ -108,7 +96,7 @@ static inline void crypto_free_rng(struct crypto_rng *tfm)
108static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, 96static inline int crypto_rng_get_bytes(struct crypto_rng *tfm,
109 u8 *rdata, unsigned int dlen) 97 u8 *rdata, unsigned int dlen)
110{ 98{
111 return crypto_rng_crt(tfm)->rng_gen_random(tfm, rdata, dlen); 99 return tfm->generate(tfm, rdata, dlen);
112} 100}
113 101
114/** 102/**
@@ -131,7 +119,7 @@ static inline int crypto_rng_get_bytes(struct crypto_rng *tfm,
131static inline int crypto_rng_reset(struct crypto_rng *tfm, 119static inline int crypto_rng_reset(struct crypto_rng *tfm,
132 u8 *seed, unsigned int slen) 120 u8 *seed, unsigned int slen)
133{ 121{
134 return crypto_rng_crt(tfm)->rng_reset(tfm, seed, slen); 122 return tfm->seed(tfm, seed, slen);
135} 123}
136 124
137/** 125/**
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 10df5d2d093a..781f7d546020 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -655,19 +655,12 @@ struct compress_tfm {
655 u8 *dst, unsigned int *dlen); 655 u8 *dst, unsigned int *dlen);
656}; 656};
657 657
658struct rng_tfm {
659 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
660 unsigned int dlen);
661 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
662};
663
664#define crt_ablkcipher crt_u.ablkcipher 658#define crt_ablkcipher crt_u.ablkcipher
665#define crt_aead crt_u.aead 659#define crt_aead crt_u.aead
666#define crt_blkcipher crt_u.blkcipher 660#define crt_blkcipher crt_u.blkcipher
667#define crt_cipher crt_u.cipher 661#define crt_cipher crt_u.cipher
668#define crt_hash crt_u.hash 662#define crt_hash crt_u.hash
669#define crt_compress crt_u.compress 663#define crt_compress crt_u.compress
670#define crt_rng crt_u.rng
671 664
672struct crypto_tfm { 665struct crypto_tfm {
673 666
@@ -680,7 +673,6 @@ struct crypto_tfm {
680 struct cipher_tfm cipher; 673 struct cipher_tfm cipher;
681 struct hash_tfm hash; 674 struct hash_tfm hash;
682 struct compress_tfm compress; 675 struct compress_tfm compress;
683 struct rng_tfm rng;
684 } crt_u; 676 } crt_u;
685 677
686 void (*exit)(struct crypto_tfm *tfm); 678 void (*exit)(struct crypto_tfm *tfm);
@@ -714,10 +706,6 @@ struct crypto_hash {
714 struct crypto_tfm base; 706 struct crypto_tfm base;
715}; 707};
716 708
717struct crypto_rng {
718 struct crypto_tfm base;
719};
720
721enum { 709enum {
722 CRYPTOA_UNSPEC, 710 CRYPTOA_UNSPEC,
723 CRYPTOA_ALG, 711 CRYPTOA_ALG,