/*************************** Generic Data Handling ****************************/
/* * boot variable: * 0 ==> No boot test, gathering of runtime data allowed * 1 ==> Boot test enabled and ready for collecting data, gathering runtime * data is disabled * 2 ==> Boot test completed and disabled, gathering of runtime data is * disabled
*/
staticvoid jent_testing_data_init(struct jent_testing *data, u32 boot)
{ /* * The boot time testing implies we have a running test. If the * caller wants to clear it, he has to unset the boot_test flag * at runtime via sysfs to enable regular runtime testing
*/ if (boot) return;
jent_testing_reset(data);
atomic_set(&data->jent_testing_enabled, 1);
pr_warn("Enabling data collection\n");
}
staticvoid jent_testing_fini(struct jent_testing *data, u32 boot)
{ /* If we have boot data, we do not reset yet to allow data to be read */ if (boot) return;
atomic_set(&data->jent_testing_enabled, 0);
jent_testing_reset(data);
pr_warn("Disabling data collection\n");
}
if (!atomic_read(&data->jent_testing_enabled) && (*boot != 1)) returnfalse;
spin_lock_irqsave(&data->lock, flags);
/* * Disable entropy testing for boot time testing after ring buffer * is filled.
*/ if (*boot) { if (((u32)atomic_read(&data->rb_writer)) >
JENT_TEST_RINGBUFFER_SIZE) {
*boot = 2;
pr_warn_once("One time data collection test disabled\n");
spin_unlock_irqrestore(&data->lock, flags); returnfalse;
}
if (atomic_read(&data->rb_writer) == 1)
pr_warn("One time data collection test enabled\n");
}
staticint jent_testing_extract_user(struct file *file, char __user *buf,
size_t nbytes, loff_t *ppos, int (*reader)(u8 *outbuf, u32 outbuflen))
{
u8 *tmp, *tmp_aligned; int ret = 0, large_request = (nbytes > 256);
if (!nbytes) return 0;
/* * The intention of this interface is for collecting at least * 1000 samples due to the SP800-90B requirements. However, due to * memory and performance constraints, it is not desirable to allocate * 8000 bytes of memory. Instead, we allocate space for only 125 * samples, which will allow the user to collect all 1000 samples using * 8 calls to this interface.
*/
tmp = kmalloc(125 * sizeof(u64) + sizeof(u64), GFP_KERNEL); if (!tmp) return -ENOMEM;
tmp_aligned = PTR_ALIGN(tmp, sizeof(u64));
while (nbytes) { int i;
if (large_request && need_resched()) { if (signal_pending(current)) { if (ret == 0)
ret = -ERESTARTSYS; break;
}
schedule();
}
i = min_t(int, nbytes, 125 * sizeof(u64));
i = reader(tmp_aligned, i); if (i <= 0) { if (i < 0)
ret = i; break;
} if (copy_to_user(buf, tmp_aligned, i)) {
ret = -EFAULT; break;
}
nbytes -= i;
buf += i;
ret += i;
}
kfree_sensitive(tmp);
if (ret > 0)
*ppos += ret;
return ret;
}
/************** Raw High-Resolution Timer Entropy Data Handling **************/
static u32 boot_raw_hires_test = 0;
module_param(boot_raw_hires_test, uint, 0644);
MODULE_PARM_DESC(boot_raw_hires_test, "Enable gathering boot time high resolution timer entropy of the first Jitter RNG entropy events");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.