Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-04-20 16:38:46 +0300
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2022-04-20 16:43:00 +0300
commit3cb40f89de42aa694d44cb6e896b732fa062ee75 (patch)
tree2d9c6fb0abba89b022f8bb148e93a7409844c3db /util-linux
parentce9a345632786d5585044ed71ed4c98c305b918f (diff)
seedrng: avoid needless runtime strlen() call
- Avoid needless runtime strlen() call, bloating binary. - Replace failed seed string with series of nulls. function old new delta .rodata 108350 108338 -12 static.seedrng_prefix 26 - -26 seedrng_main 1000 948 -52 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-90) Total: -90 bytes text data bss dec hex filename 975919 4227 1816 981962 efbca busybox_old 975829 4227 1816 981872 efb70 busybox_unstripped Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/seedrng.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c
index 49b9ab54b..5735dc059 100644
--- a/util-linux/seedrng.c
+++ b/util-linux/seedrng.c
@@ -21,7 +21,7 @@
*/
//config:config SEEDRNG
-//config: bool "seedrng (2.1 kb)"
+//config: bool "seedrng (2 kb)"
//config: default y
//config: help
//config: Seed the kernel RNG from seed files, meant to be called
@@ -173,8 +173,6 @@ static int seed_from_file_if_exists(const char *filename, int dfd, bool credit,
int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE;
int seedrng_main(int argc UNUSED_PARAM, char *argv[])
{
- static const char seedrng_prefix[] = "SeedRNG v1 Old+New Prefix";
- static const char seedrng_failure[] = "SeedRNG v1 No New Seed Failure";
char *seed_dir, *creditable_seed, *non_creditable_seed;
int ret, fd = -1, dfd = -1, program_ret = 0;
uint8_t new_seed[MAX_SEED_LEN];
@@ -218,7 +216,7 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[])
}
sha256_begin(&hash);
- sha256_hash(&hash, seedrng_prefix, strlen(seedrng_prefix));
+ sha256_hash(&hash, "SeedRNG v1 Old+New Prefix", 25);
clock_gettime(CLOCK_REALTIME, &timestamp);
sha256_hash(&hash, &timestamp, sizeof(timestamp));
clock_gettime(CLOCK_BOOTTIME, &timestamp);
@@ -236,7 +234,7 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[])
if (ret < 0) {
bb_simple_perror_msg("unable to read new seed");
new_seed_len = SHA256_OUTSIZE;
- strncpy((char *)new_seed, seedrng_failure, new_seed_len);
+ memset(new_seed, 0, SHA256_OUTSIZE);
program_ret |= 1 << 3;
}
sha256_hash(&hash, &new_seed_len, sizeof(new_seed_len));