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: jitter - output full sample from test interface

The Jitter RNG time delta is computed based on the difference of two
high-resolution, 64-bit time stamps. However, the test interface added
in 69f1c387ba only outputs the lower 32 bits of those time stamps. To
ensure all information is available during the evaluation process of
the Jitter RNG, output the full 64-bit time stamps.

Any clients collecting data from the test interface will need to be
updated to take this change into account.

Additionally, the size of the temporary buffer that holds the data for
user space has been clarified. Previously, this buffer was
JENT_TEST_RINGBUFFER_SIZE (= 1000) bytes in size, however that value
represents the number of samples held in the kernel space ring buffer,
with each sample taking 8 (previously 4) bytes.

Rather than increasing the size to allow for all 1000 samples to be
output, we keep it at 1000 bytes, but clarify that this means at most
125 64-bit samples will be output every time this interface is called.

Reviewed-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Joachim Vandersmissen <git@jvdsn.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Joachim Vandersmissen and committed by
Herbert Xu
04305f83 9374d6b4

+18 -17
+16 -15
crypto/jitterentropy-testing.c
··· 15 15 #define JENT_TEST_RINGBUFFER_MASK (JENT_TEST_RINGBUFFER_SIZE - 1) 16 16 17 17 struct jent_testing { 18 - u32 jent_testing_rb[JENT_TEST_RINGBUFFER_SIZE]; 18 + u64 jent_testing_rb[JENT_TEST_RINGBUFFER_SIZE]; 19 19 u32 rb_reader; 20 20 atomic_t rb_writer; 21 21 atomic_t jent_testing_enabled; ··· 72 72 pr_warn("Disabling data collection\n"); 73 73 } 74 74 75 - static bool jent_testing_store(struct jent_testing *data, u32 value, 75 + static bool jent_testing_store(struct jent_testing *data, u64 value, 76 76 u32 *boot) 77 77 { 78 78 unsigned long flags; ··· 156 156 } 157 157 158 158 /* We copy out word-wise */ 159 - if (outbuflen < sizeof(u32)) { 159 + if (outbuflen < sizeof(u64)) { 160 160 spin_unlock_irqrestore(&data->lock, flags); 161 161 goto out; 162 162 } 163 163 164 164 memcpy(outbuf, &data->jent_testing_rb[data->rb_reader], 165 - sizeof(u32)); 165 + sizeof(u64)); 166 166 data->rb_reader++; 167 167 168 168 spin_unlock_irqrestore(&data->lock, flags); 169 169 170 - outbuf += sizeof(u32); 171 - outbuflen -= sizeof(u32); 172 - collected_data += sizeof(u32); 170 + outbuf += sizeof(u64); 171 + outbuflen -= sizeof(u64); 172 + collected_data += sizeof(u64); 173 173 } 174 174 175 175 out: ··· 189 189 190 190 /* 191 191 * The intention of this interface is for collecting at least 192 - * 1000 samples due to the SP800-90B requirements. So, we make no 193 - * effort in avoiding allocating more memory that actually needed 194 - * by the user. Hence, we allocate sufficient memory to always hold 195 - * that amount of data. 192 + * 1000 samples due to the SP800-90B requirements. However, due to 193 + * memory and performance constraints, it is not desirable to allocate 194 + * 8000 bytes of memory. Instead, we allocate space for only 125 195 + * samples, which will allow the user to collect all 1000 samples using 196 + * 8 calls to this interface. 196 197 */ 197 - tmp = kmalloc(JENT_TEST_RINGBUFFER_SIZE + sizeof(u32), GFP_KERNEL); 198 + tmp = kmalloc(125 * sizeof(u64) + sizeof(u64), GFP_KERNEL); 198 199 if (!tmp) 199 200 return -ENOMEM; 200 201 201 - tmp_aligned = PTR_ALIGN(tmp, sizeof(u32)); 202 + tmp_aligned = PTR_ALIGN(tmp, sizeof(u64)); 202 203 203 204 while (nbytes) { 204 205 int i; ··· 213 212 schedule(); 214 213 } 215 214 216 - i = min_t(int, nbytes, JENT_TEST_RINGBUFFER_SIZE); 215 + i = min_t(int, nbytes, 125 * sizeof(u64)); 217 216 i = reader(tmp_aligned, i); 218 217 if (i <= 0) { 219 218 if (i < 0) ··· 252 251 .read_wait = __WAIT_QUEUE_HEAD_INITIALIZER(jent_raw_hires.read_wait) 253 252 }; 254 253 255 - int jent_raw_hires_entropy_store(__u32 value) 254 + int jent_raw_hires_entropy_store(__u64 value) 256 255 { 257 256 return jent_testing_store(&jent_raw_hires, value, &boot_raw_hires_test); 258 257 }
+2 -2
crypto/jitterentropy.h
··· 22 22 extern void jent_entropy_collector_free(struct rand_data *entropy_collector); 23 23 24 24 #ifdef CONFIG_CRYPTO_JITTERENTROPY_TESTINTERFACE 25 - int jent_raw_hires_entropy_store(__u32 value); 25 + int jent_raw_hires_entropy_store(__u64 value); 26 26 void jent_testing_init(void); 27 27 void jent_testing_exit(void); 28 28 #else /* CONFIG_CRYPTO_JITTERENTROPY_TESTINTERFACE */ 29 - static inline int jent_raw_hires_entropy_store(__u32 value) { return 0; } 29 + static inline int jent_raw_hires_entropy_store(__u64 value) { return 0; } 30 30 static inline void jent_testing_init(void) { } 31 31 static inline void jent_testing_exit(void) { } 32 32 #endif /* CONFIG_CRYPTO_JITTERENTROPY_TESTINTERFACE */