diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2022-04-20 15:38:46 +0200 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2022-04-20 15:43:00 +0200 |
commit | 3cb40f89de42aa694d44cb6e896b732fa062ee75 (patch) | |
tree | 2d9c6fb0abba89b022f8bb148e93a7409844c3db /util-linux | |
parent | ce9a345632786d5585044ed71ed4c98c305b918f (diff) | |
download | busybox-w32-3cb40f89de42aa694d44cb6e896b732fa062ee75.tar.gz busybox-w32-3cb40f89de42aa694d44cb6e896b732fa062ee75.tar.bz2 busybox-w32-3cb40f89de42aa694d44cb6e896b732fa062ee75.zip |
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.c | 8 |
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 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | //config:config SEEDRNG | 23 | //config:config SEEDRNG |
24 | //config: bool "seedrng (2.1 kb)" | 24 | //config: bool "seedrng (2 kb)" |
25 | //config: default y | 25 | //config: default y |
26 | //config: help | 26 | //config: help |
27 | //config: Seed the kernel RNG from seed files, meant to be called | 27 | //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, | |||
173 | int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; | 173 | int seedrng_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; |
174 | int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | 174 | int seedrng_main(int argc UNUSED_PARAM, char *argv[]) |
175 | { | 175 | { |
176 | static const char seedrng_prefix[] = "SeedRNG v1 Old+New Prefix"; | ||
177 | static const char seedrng_failure[] = "SeedRNG v1 No New Seed Failure"; | ||
178 | char *seed_dir, *creditable_seed, *non_creditable_seed; | 176 | char *seed_dir, *creditable_seed, *non_creditable_seed; |
179 | int ret, fd = -1, dfd = -1, program_ret = 0; | 177 | int ret, fd = -1, dfd = -1, program_ret = 0; |
180 | uint8_t new_seed[MAX_SEED_LEN]; | 178 | uint8_t new_seed[MAX_SEED_LEN]; |
@@ -218,7 +216,7 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
218 | } | 216 | } |
219 | 217 | ||
220 | sha256_begin(&hash); | 218 | sha256_begin(&hash); |
221 | sha256_hash(&hash, seedrng_prefix, strlen(seedrng_prefix)); | 219 | sha256_hash(&hash, "SeedRNG v1 Old+New Prefix", 25); |
222 | clock_gettime(CLOCK_REALTIME, ×tamp); | 220 | clock_gettime(CLOCK_REALTIME, ×tamp); |
223 | sha256_hash(&hash, ×tamp, sizeof(timestamp)); | 221 | sha256_hash(&hash, ×tamp, sizeof(timestamp)); |
224 | clock_gettime(CLOCK_BOOTTIME, ×tamp); | 222 | clock_gettime(CLOCK_BOOTTIME, ×tamp); |
@@ -236,7 +234,7 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
236 | if (ret < 0) { | 234 | if (ret < 0) { |
237 | bb_simple_perror_msg("unable to read new seed"); | 235 | bb_simple_perror_msg("unable to read new seed"); |
238 | new_seed_len = SHA256_OUTSIZE; | 236 | new_seed_len = SHA256_OUTSIZE; |
239 | strncpy((char *)new_seed, seedrng_failure, new_seed_len); | 237 | memset(new_seed, 0, SHA256_OUTSIZE); |
240 | program_ret |= 1 << 3; | 238 | program_ret |= 1 << 3; |
241 | } | 239 | } |
242 | sha256_hash(&hash, &new_seed_len, sizeof(new_seed_len)); | 240 | sha256_hash(&hash, &new_seed_len, sizeof(new_seed_len)); |