forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: sun4i-ss - support the Security System PRNG
The Security System has a PRNG, this patch adds support for it via crypto_rng. Signed-off-by: Corentin Labbe <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sun4i-ss.o | ||
sun4i-ss-y += sun4i-ss-core.o sun4i-ss-hash.o sun4i-ss-cipher.o | ||
sun4i-ss-$(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG) += sun4i-ss-prng.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "sun4i-ss.h" | ||
|
||
int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, | ||
unsigned int slen) | ||
{ | ||
struct sun4i_ss_alg_template *algt; | ||
struct rng_alg *alg = crypto_rng_alg(tfm); | ||
|
||
algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng); | ||
memcpy(algt->ss->seed, seed, slen); | ||
|
||
return 0; | ||
} | ||
|
||
int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src, | ||
unsigned int slen, u8 *dst, unsigned int dlen) | ||
{ | ||
struct sun4i_ss_alg_template *algt; | ||
struct rng_alg *alg = crypto_rng_alg(tfm); | ||
int i; | ||
u32 v; | ||
u32 *data = (u32 *)dst; | ||
const u32 mode = SS_OP_PRNG | SS_PRNG_CONTINUE | SS_ENABLED; | ||
size_t len; | ||
struct sun4i_ss_ctx *ss; | ||
unsigned int todo = (dlen / 4) * 4; | ||
|
||
algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng); | ||
ss = algt->ss; | ||
|
||
spin_lock(&ss->slock); | ||
|
||
writel(mode, ss->base + SS_CTL); | ||
|
||
while (todo > 0) { | ||
/* write the seed */ | ||
for (i = 0; i < SS_SEED_LEN / BITS_PER_LONG; i++) | ||
writel(ss->seed[i], ss->base + SS_KEY0 + i * 4); | ||
|
||
/* Read the random data */ | ||
len = min_t(size_t, SS_DATA_LEN / BITS_PER_BYTE, todo); | ||
readsl(ss->base + SS_TXFIFO, data, len / 4); | ||
data += len / 4; | ||
todo -= len; | ||
|
||
/* Update the seed */ | ||
for (i = 0; i < SS_SEED_LEN / BITS_PER_LONG; i++) { | ||
v = readl(ss->base + SS_KEY0 + i * 4); | ||
ss->seed[i] = v; | ||
} | ||
} | ||
|
||
writel(0, ss->base + SS_CTL); | ||
spin_unlock(&ss->slock); | ||
return dlen; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters