crypto: rng - Add multiple algorithm registration interface
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 21 Apr 2015 02:46:40 +0000 (10:46 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 22 Apr 2015 01:30:16 +0000 (09:30 +0800)
This patch adds the helpers that allow the registration and removal
of multiple RNG algorithms.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/rng.c
include/crypto/internal/rng.h

index 5e0425a246579f490f52b14eb00d5c2a5f5b0c8a..e98ce1ca527dc3e3a7a772a504a94b33cd074887 100644 (file)
@@ -233,5 +233,34 @@ void crypto_unregister_rng(struct rng_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_rng);
 
+int crypto_register_rngs(struct rng_alg *algs, int count)
+{
+       int i, ret;
+
+       for (i = 0; i < count; i++) {
+               ret = crypto_register_rng(algs + i);
+               if (ret)
+                       goto err;
+       }
+
+       return 0;
+
+err:
+       for (--i; i >= 0; --i)
+               crypto_unregister_rng(algs + i);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(crypto_register_rngs);
+
+void crypto_unregister_rngs(struct rng_alg *algs, int count)
+{
+       int i;
+
+       for (i = count - 1; i >= 0; --i)
+               crypto_unregister_rng(algs + i);
+}
+EXPORT_SYMBOL_GPL(crypto_unregister_rngs);
+
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Random Number Generator");
index 93d41bcc444e3979ebc6d4494b29eb315beaa5fb..2c9a865c66e2686997c9912e44ed8c4d6be5544b 100644 (file)
@@ -20,6 +20,8 @@ extern const struct crypto_type crypto_rng_type;
 
 int crypto_register_rng(struct rng_alg *alg);
 void crypto_unregister_rng(struct rng_alg *alg);
+int crypto_register_rngs(struct rng_alg *algs, int count);
+void crypto_unregister_rngs(struct rng_alg *algs, int count);
 
 static inline void *crypto_rng_ctx(struct crypto_rng *tfm)
 {