diff options
author | FreeArtMan <dos21h@gmail.com> | 2023-02-04 14:10:26 +0000 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2023-02-04 14:10:26 +0000 |
commit | 380f0fe40b1ab20790e75dac779e73667cc5ac72 (patch) | |
tree | 9fa3b9c93b58c966daa22f955282bc3c181d909a /md/writeup/kernel_dev_hwrng.md | |
parent | df881efab146ca3ee61bf8936f948dd976fc4740 (diff) | |
download | md-content-380f0fe40b1ab20790e75dac779e73667cc5ac72.tar.gz md-content-380f0fe40b1ab20790e75dac779e73667cc5ac72.zip |
Update all content to new pygmentize
Diffstat (limited to 'md/writeup/kernel_dev_hwrng.md')
-rw-r--r-- | md/writeup/kernel_dev_hwrng.md | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/md/writeup/kernel_dev_hwrng.md b/md/writeup/kernel_dev_hwrng.md index d632652..5c43b92 100644 --- a/md/writeup/kernel_dev_hwrng.md +++ b/md/writeup/kernel_dev_hwrng.md @@ -24,20 +24,20 @@ builtin random generator and instruction __rdrand__. Hardware random generator have own entry inside sysfs lets check _/sys/class/misc/hw_random/ -``` +```bash $ls /sys/class/misc/hw_random/ dev power rng_available rng_current subsystem uevent ``` Check available hwrng modules -``` +```bash $cat /sys/class/misc/hw_random/rng_available zero-rng ``` Check currently running hwrng module -``` +```bash $cat /sys/class/misc/hw_random/rng_current zero-rng ``` @@ -56,7 +56,7 @@ $cat /dev/urandom | rngtest -t 5 ``` _Program output_ -``` +```sh rngtest: starting FIPS tests... rngtest: bits received from input: 462500032 rngtest: FIPS 140-2 successes: 23108 @@ -161,19 +161,19 @@ MODULE_AUTHOR("Internet User"); Rng module depends on rng-core module -``` +```sh modprobe rng-core ``` then load our module -``` +```sh insmode zero_rng.ko ``` check if everything is properly loaded -``` +```sh $lsmod | grep rng zero_hwrng 16384 0 rng_core 16384 1 zero_hwrng @@ -183,7 +183,7 @@ rng_core 16384 1 zero_hwrng Lets test how our stuff works -``` +```sh $ dd if=/dev/hwrng of=/tmp/random bs=1024 count=32 32+0 records in 32+0 records out @@ -195,7 +195,7 @@ $ hexdump /tmp/random ``` As we can see all data that we get is just zeros lets check it with rng-tools -``` +```sh $ cat /tmp/random | rngtest -t 5 rngtest 5 Copyright (c) 2004 by Henrique de Moraes Holschuh @@ -224,7 +224,7 @@ Lets assume that we are running this code on Intel arch and it supports _rdrand_ instruction for random generation. -``` +```c void get_hw_rand2(uint8_t *mem) { int i=0; @@ -237,7 +237,7 @@ void get_hw_rand2(uint8_t *mem) Lets replace intel_rng_read function with our naive implementation of _rdrand_ -``` +```c static int intel_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) { int i; @@ -264,27 +264,27 @@ static int intel_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) Verify that our module loaded -``` +```sh $ cat /sys/class/misc/hw_random/rng_available zero-rng intel-rng ``` Check with module are currently used -``` +```sh $ cat /sys/class/misc/hw_random/rng_current zero-rng ``` if not our module set lets set it -``` +```sh $ echo "intel-rng" > /sys/class/misc/hw_random/rng_current ``` check if its current module used -``` +```sh $ cat /sys/class/misc/hw_random/rng_current intel-rng ``` |