History

crypto: drbg - track whether DRBG was seeded with !rng_is_initialized()

Currently, the DRBG implementation schedules asynchronous works from random_ready_callbacks for reseeding the DRBG instances with output from get_random_bytes() once the latter has sufficient entropy available. However, as the get_random_bytes() initialization state can get queried by means of rng_is_initialized() now, there is no real need for this asynchronous reseeding logic anymore and it's better to keep things simple by doing it synchronously when needed instead, i.e. from drbg_generate() once rng_is_initialized() has flipped to true. Of course, for this to work, drbg_generate() would need some means by which it can tell whether or not rng_is_initialized() has flipped to true since the last seeding from get_random_bytes(). Or equivalently, whether or not the last seed from get_random_bytes() has happened when rng_is_initialized() was still evaluating to false. As it currently stands, enum drbg_seed_state allows for the representation of two different DRBG seeding states: DRBG_SEED_STATE_UNSEEDED and DRBG_SEED_STATE_FULL. The former makes drbg_generate() to invoke a full reseeding operation involving both, the rather expensive jitterentropy as well as the get_random_bytes() randomness sources. The DRBG_SEED_STATE_FULL state on the other hand implies that no reseeding at all is required for a !->pr DRBG variant. Introduce the new DRBG_SEED_STATE_PARTIAL state to enum drbg_seed_state for representing the condition that a DRBG was being seeded when rng_is_initialized() had still been false. In particular, this new state implies that - the given DRBG instance has been fully seeded from the jitterentropy source (if enabled) - and drbg_generate() is supposed to reseed from get_random_bytes() *only* once rng_is_initialized() turns to true. Up to now, the __drbg_seed() helper used to set the given DRBG instance's ->seeded state to constant DRBG_SEED_STATE_FULL. Introduce a new argument allowing for the specification of the to be written ->seeded value instead. Make the first of its two callers, drbg_seed(), determine the appropriate value based on rng_is_initialized(). The remaining caller, drbg_async_seed(), is known to get invoked only once rng_is_initialized() is true, hence let it pass constant DRBG_SEED_STATE_FULL for the new argument to __drbg_seed(). There is no change in behaviour, except for that the pr_devel() in drbg_generate() would now report "unseeded" for ->pr DRBG instances which had last been seeded when rng_is_initialized() was still evaluating to false.

Nicolai Stange committed 5 years ago

Commit 2bcd2541 parent ce8ce312 files · +9 −4Browse files

Unified · Split

2 files
  1. crypto/drbg.c +8 −4
  2. include/crypto/drbg.h +1 −0
crypto/drbg.c+8−4
@@ -1036,14 +1036,14 @@ static const struct drbg_state_ops drbg_hash_ops = { · 1035 unmodified lines
10361036 ******************************************************************/
10371037
10381038 static inline int __drbg_seed(struct drbg_state *drbg, struct list_head *seed,
1039− int reseed)
1039+ int reseed, enum drbg_seed_state new_seed_state)
10401040 {
10411041 int ret = drbg->d_ops->update(drbg, seed, reseed);
10421042
10431043 if (ret)
10441044 return ret;
10451045
1046− drbg->seeded = DRBG_SEED_STATE_FULL;
1046+ drbg->seeded = new_seed_state;
10471047 /* 10.1.1.2 / 10.1.1.3 step 5 */
10481048 drbg->reseed_ctr = 1;
10491049
@@ -1093,7 +1093,7 @@ static void drbg_async_seed(struct work_struct *work) · 43 unmodified lines
10931093 */
10941094 drbg->seeded = DRBG_SEED_STATE_UNSEEDED;
10951095
1096− __drbg_seed(drbg, &seedlist, true);
1096+ __drbg_seed(drbg, &seedlist, true, DRBG_SEED_STATE_FULL);
10971097
10981098 if (drbg->seeded == DRBG_SEED_STATE_FULL)
10991099 drbg->reseed_threshold = drbg_max_requests(drbg);
@@ -1123,6 +1123,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, · 23 unmodified lines
11231123 unsigned int entropylen = drbg_sec_strength(drbg->core->flags);
11241124 struct drbg_string data1;
11251125 LIST_HEAD(seedlist);
1126+ enum drbg_seed_state new_seed_state = DRBG_SEED_STATE_FULL;
11261127
11271128 /* 9.1 / 9.2 / 9.3.1 step 3 */
11281129 if (pers && pers->len > (drbg_max_addtl(drbg))) {
@@ -1150,6 +1151,9 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, · 21 unmodified lines
11501151 BUG_ON((entropylen * 2) > sizeof(entropy));
11511152
11521153 /* Get seed from in-kernel /dev/urandom */
1154+ if (!rng_is_initialized())
1155+ new_seed_state = DRBG_SEED_STATE_PARTIAL;
1156+
11531157 ret = drbg_get_random_bytes(drbg, entropy, entropylen);
11541158 if (ret)
11551159 goto out;
@@ -1206,7 +1210,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, · 50 unmodified lines
12061210 memset(drbg->C, 0, drbg_statelen(drbg));
12071211 }
12081212
1209− ret = __drbg_seed(drbg, &seedlist, reseed);
1213+ ret = __drbg_seed(drbg, &seedlist, reseed, new_seed_state);
12101214
12111215 out:
12121216 memzero_explicit(entropy, entropylen * 2);
include/crypto/drbg.h+1−0
@@ -107,6 +107,7 @@ struct drbg_test_data { · 106 unmodified lines
107107
108108 enum drbg_seed_state {
109109 DRBG_SEED_STATE_UNSEEDED,
110+ DRBG_SEED_STATE_PARTIAL, /* Seeded with !rng_is_initialized() */
110111 DRBG_SEED_STATE_FULL,
111112 };
112113

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t