diff options
author | Albert ARIBAUD <albert.u.boot@aribaud.net> | 2014-04-08 09:25:08 +0200 |
---|---|---|
committer | Albert ARIBAUD <albert.u.boot@aribaud.net> | 2014-04-08 09:25:08 +0200 |
commit | 519fdde9e6a6ebce7dc743b4f5621503d25b7a45 (patch) | |
tree | 29649f48b92b92342183f71565c34afeca0b1735 /drivers/crypto/ace_sha.c | |
parent | c71645ad2bd5179ad21e2501c26f574e9688f02a (diff) | |
parent | 04d2f0a9f33112bd70ce4d9c451fdca1682e3a59 (diff) | |
download | u-boot-imx-519fdde9e6a6ebce7dc743b4f5621503d25b7a45.zip u-boot-imx-519fdde9e6a6ebce7dc743b4f5621503d25b7a45.tar.gz u-boot-imx-519fdde9e6a6ebce7dc743b4f5621503d25b7a45.tar.bz2 |
Merge branch 'u-boot/master' into 'u-boot-arm/master'
Conflicts:
arch/arm/cpu/arm926ejs/mxs/Makefile
include/configs/trats.h
include/configs/trats2.h
include/mmc.h
Diffstat (limited to 'drivers/crypto/ace_sha.c')
-rw-r--r-- | drivers/crypto/ace_sha.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/drivers/crypto/ace_sha.c b/drivers/crypto/ace_sha.c index acbafde..ed4f541 100644 --- a/drivers/crypto/ace_sha.c +++ b/drivers/crypto/ace_sha.c @@ -5,10 +5,12 @@ * SPDX-License-Identifier: GPL-2.0+ */ #include <common.h> +#include "ace_sha.h" + +#ifdef CONFIG_SHA_HW_ACCEL #include <sha256.h> #include <sha1.h> #include <asm/errno.h> -#include "ace_sha.h" /* SHA1 value for the message of zero length */ static const unsigned char sha1_digest_emptymsg[SHA1_SUM_LEN] = { @@ -111,3 +113,72 @@ void hw_sha1(const unsigned char *pbuf, unsigned int buf_len, if (ace_sha_hash_digest(pbuf, buf_len, pout, ACE_SHA_TYPE_SHA1)) debug("ACE was not setup properly or it is faulty\n"); } +#endif /* CONFIG_SHA_HW_ACCEL */ + +#ifdef CONFIG_LIB_HW_RAND +static unsigned int seed_done; + +void srand(unsigned int seed) +{ + struct exynos_ace_sfr *reg = + (struct exynos_ace_sfr *)samsung_get_base_ace_sfr(); + int i, status; + + /* Seed data */ + for (i = 0; i < ACE_HASH_PRNG_REG_NUM; i++) + writel(seed << i, ®->hash_seed[i]); + + /* Wait for seed setup done */ + while (1) { + status = readl(®->hash_status); + if ((status & ACE_HASH_SEEDSETTING_MASK) || + (status & ACE_HASH_PRNGERROR_MASK)) + break; + } + + seed_done = 1; +} + +unsigned int rand(void) +{ + struct exynos_ace_sfr *reg = + (struct exynos_ace_sfr *)samsung_get_base_ace_sfr(); + int i, status; + unsigned int seed = (unsigned int)&status; + unsigned int ret = 0; + + if (!seed_done) + srand(seed); + + /* Start PRNG */ + writel(ACE_HASH_ENGSEL_PRNG | ACE_HASH_STARTBIT_ON, ®->hash_control); + + /* Wait for PRNG done */ + while (1) { + status = readl(®->hash_status); + if (status & ACE_HASH_PRNGDONE_MASK) + break; + if (status & ACE_HASH_PRNGERROR_MASK) { + seed_done = 0; + return 0; + } + } + + /* Clear Done IRQ */ + writel(ACE_HASH_PRNGDONE_MASK, ®->hash_status); + + /* Read a PRNG result */ + for (i = 0; i < ACE_HASH_PRNG_REG_NUM; i++) + ret += readl(®->hash_prng[i]); + + seed_done = 0; + return ret; +} + +unsigned int rand_r(unsigned int *seedp) +{ + srand(*seedp); + + return rand(); +} +#endif /* CONFIG_LIB_HW_RAND */ |