Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: caam - add a test for the RNG

CAAM includes a Random Number Generator. This change adds
a kernel configuration option to test the RNG's capabilities via the
hw_random framework.

Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com>
Signed-off-by: Dan Douglass <dan.douglass@nxp.com>
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Victoria Milhoan (b42089) and committed by
Herbert Xu
2be0d806 ef492d08

+57
+9
drivers/crypto/caam/Kconfig
··· 162 162 config CRYPTO_DEV_FSL_CAAM_BLOB_GEN 163 163 bool 164 164 165 + config CRYPTO_DEV_FSL_CAAM_RNG_TEST 166 + bool "Test caam rng" 167 + select CRYPTO_DEV_FSL_CAAM_RNG_API 168 + help 169 + Selecting this will enable a self-test to run for the 170 + caam RNG. 171 + This test is several minutes long and executes 172 + just before the RNG is registered with the hw_random API. 173 + 165 174 endif # CRYPTO_DEV_FSL_CAAM_JR 166 175 167 176 endif # CRYPTO_DEV_FSL_CAAM
+48
drivers/crypto/caam/caamrng.c
··· 172 172 kfifo_free(&ctx->fifo); 173 173 } 174 174 175 + #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_TEST 176 + static inline void test_len(struct hwrng *rng, size_t len, bool wait) 177 + { 178 + u8 *buf; 179 + int read_len; 180 + struct caam_rng_ctx *ctx = to_caam_rng_ctx(rng); 181 + struct device *dev = ctx->ctrldev; 182 + 183 + buf = kcalloc(CAAM_RNG_MAX_FIFO_STORE_SIZE, sizeof(u8), GFP_KERNEL); 184 + 185 + while (len > 0) { 186 + read_len = rng->read(rng, buf, len, wait); 187 + 188 + if (read_len < 0 || (read_len == 0 && wait)) { 189 + dev_err(dev, "RNG Read FAILED received %d bytes\n", 190 + read_len); 191 + kfree(buf); 192 + return; 193 + } 194 + 195 + print_hex_dump_debug("random bytes@: ", 196 + DUMP_PREFIX_ADDRESS, 16, 4, 197 + buf, read_len, 1); 198 + 199 + len = len - read_len; 200 + } 201 + 202 + kfree(buf); 203 + } 204 + 205 + static inline void test_mode_once(struct hwrng *rng, bool wait) 206 + { 207 + test_len(rng, 32, wait); 208 + test_len(rng, 64, wait); 209 + test_len(rng, 128, wait); 210 + } 211 + 212 + static void self_test(struct hwrng *rng) 213 + { 214 + pr_info("Executing RNG SELF-TEST with wait\n"); 215 + test_mode_once(rng, true); 216 + } 217 + #endif 218 + 175 219 static int caam_init(struct hwrng *rng) 176 220 { 177 221 struct caam_rng_ctx *ctx = to_caam_rng_ctx(rng); ··· 301 257 caam_rng_exit(ctrldev); 302 258 return ret; 303 259 } 260 + 261 + #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_TEST 262 + self_test(&ctx->rng); 263 + #endif 304 264 305 265 devres_close_group(ctrldev, caam_rng_init); 306 266 return 0;