summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-04-21 05:46:38 +0300
committerHerbert Xu <herbert@gondor.apana.org.au>2015-04-22 04:30:14 +0300
commitacec27ff35af9caf34d76d16ee17ff3b292e7d83 (patch)
treecbbadbe7b3b8ed91da58850cd147145c944b359c /include
parent3c5d8fa9f56ad0928e7a1f06003e5034f5eedb52 (diff)
downloadlinux-acec27ff35af9caf34d76d16ee17ff3b292e7d83.tar.xz
crypto: rng - Convert low-level crypto_rng to new style
This patch converts the low-level crypto_rng interface to the "new" style. This allows existing implementations to be converted over one- by-one. Once that is complete we can then remove the old rng interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/internal/rng.h3
-rw-r--r--include/crypto/rng.h42
-rw-r--r--include/linux/crypto.h6
3 files changed, 46 insertions, 5 deletions
diff --git a/include/crypto/internal/rng.h b/include/crypto/internal/rng.h
index 896973369573..76f3c9519ba5 100644
--- a/include/crypto/internal/rng.h
+++ b/include/crypto/internal/rng.h
@@ -18,6 +18,9 @@
extern const struct crypto_type crypto_rng_type;
+int crypto_register_rng(struct rng_alg *alg);
+void crypto_unregister_rng(struct rng_alg *alg);
+
static inline void *crypto_rng_ctx(struct crypto_rng *tfm)
{
return crypto_tfm_ctx(&tfm->base);
diff --git a/include/crypto/rng.h b/include/crypto/rng.h
index 7fca37144b59..133f0441ad3e 100644
--- a/include/crypto/rng.h
+++ b/include/crypto/rng.h
@@ -15,11 +15,48 @@
#include <linux/crypto.h>
+struct crypto_rng;
+
+/**
+ * struct rng_alg - random number generator definition
+ *
+ * @generate: The function defined by this variable obtains a
+ * random number. The random number generator transform
+ * must generate the random number out of the context
+ * provided with this call, plus any additional data
+ * if provided to the call.
+ * @seed: Seed or reseed the random number generator. With the
+ * invocation of this function call, the random number
+ * generator shall become ready fo generation. If the
+ * random number generator requires a seed for setting
+ * up a new state, the seed must be provided by the
+ * consumer while invoking this function. The required
+ * size of the seed is defined with @seedsize .
+ * @seedsize: The seed size required for a random number generator
+ * initialization defined with this variable. Some
+ * random number generators does not require a seed
+ * as the seeding is implemented internally without
+ * the need of support by the consumer. In this case,
+ * the seed size is set to zero.
+ * @base: Common crypto API algorithm data structure.
+ */
+struct rng_alg {
+ int (*generate)(struct crypto_rng *tfm,
+ const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int dlen);
+ int (*seed)(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
+
+ unsigned int seedsize;
+
+ struct crypto_alg base;
+};
+
struct crypto_rng {
int (*generate)(struct crypto_rng *tfm,
const u8 *src, unsigned int slen,
u8 *dst, unsigned int dlen);
int (*seed)(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
+ unsigned int seedsize;
struct crypto_tfm base;
};
@@ -72,7 +109,8 @@ static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm)
*/
static inline struct rng_alg *crypto_rng_alg(struct crypto_rng *tfm)
{
- return &crypto_rng_tfm(tfm)->__crt_alg->cra_rng;
+ return container_of(crypto_rng_tfm(tfm)->__crt_alg,
+ struct rng_alg, base);
}
/**
@@ -156,7 +194,7 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed,
*/
static inline int crypto_rng_seedsize(struct crypto_rng *tfm)
{
- return crypto_rng_alg(tfm)->seedsize;
+ return tfm->seedsize;
}
#endif
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 781f7d546020..2fa9b05360f7 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -427,7 +427,7 @@ struct compress_alg {
};
/**
- * struct rng_alg - random number generator definition
+ * struct old_rng_alg - random number generator definition
* @rng_make_random: The function defined by this variable obtains a random
* number. The random number generator transform must generate
* the random number out of the context provided with this
@@ -445,7 +445,7 @@ struct compress_alg {
* seeding is implemented internally without the need of support by
* the consumer. In this case, the seed size is set to zero.
*/
-struct rng_alg {
+struct old_rng_alg {
int (*rng_make_random)(struct crypto_rng *tfm, u8 *rdata,
unsigned int dlen);
int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
@@ -559,7 +559,7 @@ struct crypto_alg {
struct blkcipher_alg blkcipher;
struct cipher_alg cipher;
struct compress_alg compress;
- struct rng_alg rng;
+ struct old_rng_alg rng;
} cra_u;
int (*cra_init)(struct crypto_tfm *tfm);