You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So we recently introduced 2 RNGs. One for public and one for private things. My understanding for the reason of this is that if somebody can see (lots of) raw output of the RNG, and there is some problem with it, he might be able to find the internal state RNG or at least predict what it's going to output next. To defend against that we have 2 RNGs, where the output of only 1 of them can be seen by others. The output of the private one is never directly seen by someone else. The private RNG could for instance be used to generate an asymmetric key, where the public key is send to someone else.
So I think we should go over all the code that generates random numbers and see for what it's used and then pick the right RNG for it.
Just a wild suggestion: might it be worthwhile introducing a RAND_public_bytes call that accesses the public RNG like the RAND_priv_bytes call does for the private RNG?
This would assist with converting all existing RAND_bytes calls into one of these two forms. We'd then be able to deprecate the RAND_bytes call at some point in the future (unlikely for a long time).
I think we should internally only use the DRBG API. Since the plan is to actually make that API public, maybe we should remove RAND_priv_bytes again and deprecate RAND_bytes
I'm more hesitant to deprecate RAND_bytes. It is a wonderfully simple API (buffer and length) and any replacement should be as simple. Renaming to RAND_DRBG_public_bytes and RAND_DRBG_private_bytes would be fine with the same arguments. RAND_DRBG_bytes adding a third argument (the DRBG) seems worse from the users' viewpoint.
Compare RAND_DRBG_public_bytes(&x, sizeof(x))
and RAND_DRBG_bytes(RAND_DRBG_get0_global(), &x, sizeof(x))
I'm quite in favour of the former, although RAND_bytes is slightly better I think.
So I just started looking at this, and I notice that we support other rand methods other than the DRBG. If I want to directly use the DRBG API, this starts to get complicated. So I guess I need a wrapper, and maybe RAND_bytes() and RAND_priv_bytes() work for that.
I'm not sure whether this discussion is heading in the right direction, in particular in view of PR #4665. The original intent of adding the private DRBG was simply to use it for all long term secrets like RSA or ECDSA private keys, and for nothing else. (@richsalz please correct my if I'm wrong.) For everything else, using the existing default DRBG via RAND_bytes() is just fine (the per-SSL use case excluded). So maybe the term "public" DRBG (as opposed to "private") was a little bit misleading: It does not have to do with the question whether the random output becomes public (e.g., as IV) or not. Maybe the term "default" or "shared" DRBG would have been less misleading.
Anyway, the task is not to distinguish between "public" vs. "private" random output in the sense whether the output becomes visible or not. But this is precisely what PR #4665 attempts
As for your main question, "when to use the private and public RNGs?": For the normal user the answer is simple: just use RAND_bytes() and don't worry about the details. OpenSSL will take care of the rest. I used to think differently about that, but now I agree with @richsalz and @paulidale: The simplicity of the RAND_METHOD API has its charm, and it will never be replaced, but only amended by the RAND_DRBG API. And since the different reseeding philosophies (push vs. pull) have been reconciled by PR #4328, my reluctance to use RAND_bytes() have diminished.
I believe there are three main use cases for using the RAND_DRBG API in addition to or instead of the classical RAND_METHOD API:
Configure the "backend" DRBGs behind RAND_bytes() and RAND_priv_bytes(), for example to change the reseed time.
Have private DRBG instances with custom reseeding intervals or with prediction resistance enabled (without modifying the defaults)
Have multiple DRBG instances, in perticular per thread instances with locking disabled.
The SSL DRBGs are a good example of the last use case. Since the SSL DRBGs are short-lived and private already, it does not make sense to fall back to using RAND_priv_bytes(). In particular since one looses the advantage of lock-free acces.
For the second use case, it might be convenient to add a RAND_DRBG_bytes() function, such that
So I'd like to explain my understanding again. I think there is a worry that there might be something is wrong with the RNG that we don't know about and an attacker might learn something based on the output about the internal state. My understanding is that this has at least been the case for certain RNGs.
The best defense against that that I can think of is that we have 2 RNGs, 1 for things the attacker can see and 1 for things the attacker can't see. But maybe other people have different/better ideas. And I can't think of an other good reason why we would split the it 2 DRBGs.
I've also started wondering about the effect of chained DRBGs has on this. If we create a new DRBG for each SSL connection, and the attacker can learn about the internal state of the SSL DRBG, can't the attacker also learn about the state of parent DRBG, and so also the master DRBG?
I like the RAND_DRBG_bytes() suggestion. I'd support removing RAND_private_bytes in favour of using this.
I've also started wondering about the effect of chained DRBGs has on this. If we create a new DRBG for each SSL connection, and the attacker can learn about the internal state of the SSL DRBG, can't the attacker also learn about the state of parent DRBG, and so also the master DRBG?
I believe that an attack against a chain needs to be more involved. Assume that the attacker can see the output of DRBG A which is being reseeded by DRBG B, and that the DRBG being used has a weakness that allows the attacker to determine the internal state by observing sufficient output. We'll also assume that the initial state can be determined by observing output rather than state after the output is observed. What are they going to get?
They'll be able to predict the output of DRBG A which isn't good. When DRBG A reseeds, the internal state has changed but they'll be able to determine it again soon (weak DRBG assumption) and be able to figure out what changed in DRBG A's state (the initial state assumption). This still isn't the same as knowing DRBG B's raw output, DRBG B's output has been hashed before being mixed in. It would be necessary to also break the encoding done by ctr_df in drbg_rand.c.
Activity
paulidale commentedon Nov 2, 2017
Just a wild suggestion: might it be worthwhile introducing a
RAND_public_bytescall that accesses the public RNG like theRAND_priv_bytescall does for the private RNG?This would assist with converting all existing
RAND_bytescalls into one of these two forms. We'd then be able to deprecate theRAND_bytescall at some point in the future (unlikely for a long time).Anyway, just a thought.
kroeckx commentedon Nov 2, 2017
I think we should internally only use the DRBG API. Since the plan is to actually make that API public, maybe we should remove RAND_priv_bytes again and deprecate RAND_bytes
paulidale commentedon Nov 2, 2017
I'm more hesitant to deprecate RAND_bytes. It is a wonderfully simple API (buffer and length) and any replacement should be as simple. Renaming to RAND_DRBG_public_bytes and RAND_DRBG_private_bytes would be fine with the same arguments. RAND_DRBG_bytes adding a third argument (the DRBG) seems worse from the users' viewpoint.
Compare
RAND_DRBG_public_bytes(&x, sizeof(x))and
RAND_DRBG_bytes(RAND_DRBG_get0_global(), &x, sizeof(x))I'm quite in favour of the former, although RAND_bytes is slightly better I think.
kroeckx commentedon Nov 3, 2017
So I just started looking at this, and I notice that we support other rand methods other than the DRBG. If I want to directly use the DRBG API, this starts to get complicated. So I guess I need a wrapper, and maybe RAND_bytes() and RAND_priv_bytes() work for that.
mspncp commentedon Nov 4, 2017
I'm not sure whether this discussion is heading in the right direction, in particular in view of PR #4665. The original intent of adding the private DRBG was simply to use it for all long term secrets like RSA or ECDSA private keys, and for nothing else. (@richsalz please correct my if I'm wrong.) For everything else, using the existing default DRBG via RAND_bytes() is just fine (the per-SSL use case excluded). So maybe the term "public" DRBG (as opposed to "private") was a little bit misleading: It does not have to do with the question whether the random output becomes public (e.g., as IV) or not. Maybe the term "default" or "shared" DRBG would have been less misleading.
Anyway, the task is not to distinguish between "public" vs. "private" random output in the sense whether the output becomes visible or not. But this is precisely what PR #4665 attempts
As for your main question, "when to use the private and public RNGs?": For the normal user the answer is simple: just use
RAND_bytes()and don't worry about the details. OpenSSL will take care of the rest. I used to think differently about that, but now I agree with @richsalz and @paulidale: The simplicity of the RAND_METHOD API has its charm, and it will never be replaced, but only amended by the RAND_DRBG API. And since the different reseeding philosophies (push vs. pull) have been reconciled by PR #4328, my reluctance to use RAND_bytes() have diminished.I believe there are three main use cases for using the RAND_DRBG API in addition to or instead of the classical RAND_METHOD API:
The SSL DRBGs are a good example of the last use case. Since the SSL DRBGs are short-lived and private already, it does not make sense to fall back to using RAND_priv_bytes(). In particular since one looses the advantage of lock-free acces.
For the second use case, it might be convenient to add a
RAND_DRBG_bytes()function, such thatis equivalent to
But I would not name this function
RAND_DRBG_public_bytes(), and I would not use it for the shared DRBGs like thisbecause using
RAND_bytes(buf, sizeof(buf)is much easier.RAND_DRBG_bytes()is useful mainly for private drbg instances.kroeckx commentedon Nov 4, 2017
So maybe my understanding for the split is wrong, and I would love to get feedback from others.
But you do have a point if it's SSL specific, they probably can't learn much from it related to an other connection.
kroeckx commentedon Nov 4, 2017
So I'd like to explain my understanding again. I think there is a worry that there might be something is wrong with the RNG that we don't know about and an attacker might learn something based on the output about the internal state. My understanding is that this has at least been the case for certain RNGs.
The best defense against that that I can think of is that we have 2 RNGs, 1 for things the attacker can see and 1 for things the attacker can't see. But maybe other people have different/better ideas. And I can't think of an other good reason why we would split the it 2 DRBGs.
I've also started wondering about the effect of chained DRBGs has on this. If we create a new DRBG for each SSL connection, and the attacker can learn about the internal state of the SSL DRBG, can't the attacker also learn about the state of parent DRBG, and so also the master DRBG?
paulidale commentedon Nov 5, 2017
I like the
RAND_DRBG_bytes()suggestion. I'd support removing RAND_private_bytes in favour of using this.I believe that an attack against a chain needs to be more involved. Assume that the attacker can see the output of DRBG A which is being reseeded by DRBG B, and that the DRBG being used has a weakness that allows the attacker to determine the internal state by observing sufficient output. We'll also assume that the initial state can be determined by observing output rather than state after the output is observed. What are they going to get?
They'll be able to predict the output of DRBG A which isn't good. When DRBG A reseeds, the internal state has changed but they'll be able to determine it again soon (weak DRBG assumption) and be able to figure out what changed in DRBG A's state (the initial state assumption). This still isn't the same as knowing DRBG B's raw output, DRBG B's output has been hashed before being mixed in. It would be necessary to also break the encoding done by
ctr_dfindrbg_rand.c.kroeckx commentedon Nov 17, 2017
I've created a RAND_DRBG_bytes(): #4752