Skip to content
Permalink
Browse files

check that generating random keys actually succeeds

  • Loading branch information
jacobgorm committed Nov 8, 2019
1 parent a6e989e commit c2e48194a854a1c55892a6655f18b8b8309ed2b1
Showing with 6 additions and 2 deletions.
  1. +3 −1 block-swap.c
  2. +3 −1 kv.c
@@ -895,7 +895,9 @@ int swap_open(BlockDriverState *bs, const char *filename, int flags)

uint8_t zero_key[CRYPTO_KEY_SIZE] = {};
if (!memcmp(zero_key, s->crypto_key, CRYPTO_KEY_SIZE)) {
RAND_bytes(s->crypto_key, sizeof(s->crypto_key));
if (RAND_priv_bytes(s->crypto_key, sizeof(s->crypto_key)) != 1) {
errx(1, "RAND_bytes failed!");
}
}

/* Chop off filename to reveal dir. */
4 kv.c
@@ -135,7 +135,9 @@ int kv_init(struct kv *kv, const char *kvinfo, int delete_on_close) {
free(dup);
}
if (!have_key) {
RAND_bytes(kv->crypto_key, CRYPTO_KEY_SIZE);
if (RAND_priv_bytes(kv->crypto_key, CRYPTO_KEY_SIZE) != 1) {
errx(1, "RAND_bytes failed!");
}
}

int r;

0 comments on commit c2e4819

Please sign in to comment.
You can’t perform that action at this time.