diff options
author | Samuel Lidén Borell <samuel@kodafritt.se> | 2017-11-13 19:03:16 +0100 |
---|---|---|
committer | Samuel Lidén Borell <samuel@kodafritt.se> | 2017-11-13 19:03:16 +0100 |
commit | a636c87d4d227d9288b36898a868e08ba7b6f8db (patch) | |
tree | a2c468e92d22b2c85242d0e4f601477a9fdac977 /fakerandom.c | |
download | fakerandom-main.tar.gz fakerandom-main.tar.bz2 fakerandom-main.zip |
Diffstat (limited to 'fakerandom.c')
-rw-r--r-- | fakerandom.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/fakerandom.c b/fakerandom.c new file mode 100644 index 0000000..6889319 --- /dev/null +++ b/fakerandom.c @@ -0,0 +1,56 @@ +/* + + Copyright (c) 2017 Samuel Lidén Borell <samuel@kodafritt.se> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +*/ + +#include <fcntl.h> +#include <linux/random.h> +#include <sys/ioctl.h> +#include <stdio.h> + +int main(int argc, const char **argv) +{ + int fd, res, ent; + + (void) argv; + if (argc > 1) { + printf("usage: fakerandom\n\n" + "Increases the entropy counter, without actually adding any entropy.\n" + "Obviously this is NOT secure. Do not use on production systems!\n\n"); + return 0; + } + + fd = open("/dev/random", O_WRONLY); + if (fd < 0) { + perror("failed to open /dev/random"); + return 1; + } + + ent = 0x1000000; + res = ioctl(fd, RNDADDTOENTCNT, &ent); + if (res < 0) { + perror("failed to add fake entropy"); + return 1; + } + return 0; +} + |