jitterentropy-kcapi.c (bb897c55042e9330bcf88b4b13cbdd6f9fabdd5e) | jitterentropy-kcapi.c (69f1c387ba700f69e9fdad6d6ce44a3bb774dbff) |
---|---|
1/* 2 * Non-physical true random number generator based on timing jitter -- 3 * Linux Kernel Crypto API specific code 4 * 5 * Copyright Stephan Mueller <smueller@chronox.de>, 2015 - 2023 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 74 unchanged lines hidden (view full) --- 83 * If random_get_entropy does not return a value, i.e. it is not 84 * implemented for a given architecture, use a clock source. 85 * hoping that there are timers we can work with. 86 */ 87 if (tmp == 0) 88 tmp = ktime_get_ns(); 89 90 *out = tmp; | 1/* 2 * Non-physical true random number generator based on timing jitter -- 3 * Linux Kernel Crypto API specific code 4 * 5 * Copyright Stephan Mueller <smueller@chronox.de>, 2015 - 2023 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 74 unchanged lines hidden (view full) --- 83 * If random_get_entropy does not return a value, i.e. it is not 84 * implemented for a given architecture, use a clock source. 85 * hoping that there are timers we can work with. 86 */ 87 if (tmp == 0) 88 tmp = ktime_get_ns(); 89 90 *out = tmp; |
91 jent_raw_hires_entropy_store(tmp); |
|
91} 92 93int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, 94 unsigned int addtl_len, __u64 hash_loop_cnt, 95 unsigned int stuck) 96{ 97 struct shash_desc *hash_state_desc = (struct shash_desc *)hash_state; 98 SHASH_DESC_ON_STACK(desc, hash_state_desc->tfm); --- 219 unchanged lines hidden (view full) --- 318}; 319 320static int __init jent_mod_init(void) 321{ 322 SHASH_DESC_ON_STACK(desc, tfm); 323 struct crypto_shash *tfm; 324 int ret = 0; 325 | 92} 93 94int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, 95 unsigned int addtl_len, __u64 hash_loop_cnt, 96 unsigned int stuck) 97{ 98 struct shash_desc *hash_state_desc = (struct shash_desc *)hash_state; 99 SHASH_DESC_ON_STACK(desc, hash_state_desc->tfm); --- 219 unchanged lines hidden (view full) --- 319}; 320 321static int __init jent_mod_init(void) 322{ 323 SHASH_DESC_ON_STACK(desc, tfm); 324 struct crypto_shash *tfm; 325 int ret = 0; 326 |
327 jent_testing_init(); 328 |
|
326 tfm = crypto_alloc_shash(JENT_CONDITIONING_HASH, 0, 0); | 329 tfm = crypto_alloc_shash(JENT_CONDITIONING_HASH, 0, 0); |
327 if (IS_ERR(tfm)) | 330 if (IS_ERR(tfm)) { 331 jent_testing_exit(); |
328 return PTR_ERR(tfm); | 332 return PTR_ERR(tfm); |
333 } |
|
329 330 desc->tfm = tfm; 331 crypto_shash_init(desc); 332 ret = jent_entropy_init(desc); 333 shash_desc_zero(desc); 334 crypto_free_shash(tfm); 335 if (ret) { 336 /* Handle permanent health test error */ 337 if (fips_enabled) 338 panic("jitterentropy: Initialization failed with host not compliant with requirements: %d\n", ret); 339 | 334 335 desc->tfm = tfm; 336 crypto_shash_init(desc); 337 ret = jent_entropy_init(desc); 338 shash_desc_zero(desc); 339 crypto_free_shash(tfm); 340 if (ret) { 341 /* Handle permanent health test error */ 342 if (fips_enabled) 343 panic("jitterentropy: Initialization failed with host not compliant with requirements: %d\n", ret); 344 |
345 jent_testing_exit(); |
|
340 pr_info("jitterentropy: Initialization failed with host not compliant with requirements: %d\n", ret); 341 return -EFAULT; 342 } 343 return crypto_register_rng(&jent_alg); 344} 345 346static void __exit jent_mod_exit(void) 347{ | 346 pr_info("jitterentropy: Initialization failed with host not compliant with requirements: %d\n", ret); 347 return -EFAULT; 348 } 349 return crypto_register_rng(&jent_alg); 350} 351 352static void __exit jent_mod_exit(void) 353{ |
354 jent_testing_exit(); |
|
348 crypto_unregister_rng(&jent_alg); 349} 350 351module_init(jent_mod_init); 352module_exit(jent_mod_exit); 353 354MODULE_LICENSE("Dual BSD/GPL"); 355MODULE_AUTHOR("Stephan Mueller <smueller@chronox.de>"); 356MODULE_DESCRIPTION("Non-physical True Random Number Generator based on CPU Jitter"); 357MODULE_ALIAS_CRYPTO("jitterentropy_rng"); | 355 crypto_unregister_rng(&jent_alg); 356} 357 358module_init(jent_mod_init); 359module_exit(jent_mod_exit); 360 361MODULE_LICENSE("Dual BSD/GPL"); 362MODULE_AUTHOR("Stephan Mueller <smueller@chronox.de>"); 363MODULE_DESCRIPTION("Non-physical True Random Number Generator based on CPU Jitter"); 364MODULE_ALIAS_CRYPTO("jitterentropy_rng"); |