aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
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 /crypto
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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/rng.c35
1 files changed, 23 insertions, 12 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;