[csrng/entropy_src] A security need for added an extra lfsr or other in random bit gen path?
@cdgori comment below:
Side comment: It would be good if we can find a way to "diversify" the behavior of the CSRNG in some way based on DEV/PROD (in general, we don't want someone to be able to use a DEV part as an oracle/predictor for a PROD part set up the same way but with the DEV/PROD fuse(s) flipped the other way - this might not be super meaningful in the case of CSRNG but it bears at least thinking about for a few minutes if there is some low-hanging fruit to implement it - usually we try to mix in a DEV/PROD-dependent-constant into the AES, or an LFSR, or something like that to create parallel but different streams of derivation/execution.)
@tjaychen @senelson7 @martin-lueker @zi-v
yeah so my suggestion ...if we are allowed to mix in extra strings into the sha3 condition, that would be the best place to do it.
We do something similar in keymgr where depending on what state we are in, a different value is mixed in (so you could even use the same output from lc_ctrl).
And I believe I also mentioned this in the original issue, I don't think it's quite as critical for the entropy complex to have this, just because its results are not meant to be deterministic anyways. But it would not hurt if it can be incorporated in a very low effort / low overhead way.
We talked about this a little today/this morning in our weekly discussion. I/we need to be precise about where this would happen, because the behavior is different for entropy_src as for CSRNG. It might be that for both cases this isn't particularly interesting as an attack (as noted, the results are not meant to be deterministic).
Also, @tjaychen since it's only a SHA3 (not a SHAKE/cSHAKE) we can't use the customization strings approach.
So we should come back to this collectively and see if there's anything to be done here.
Status: revisited in meeting 2021/03/30: First off: @cdgori points out that the real goal here is to work out some way to modulate the behavior of the input to the entropy_src conditioner.
CSRNG has a defined personalization string input that can achieve this DEV/PROD distinction. Likewise SHA3 has a term "customization string" concept, though we aren't sure as to whether that is implemented in our SHA3 primitive. Current Status: @cdgori and others to take a look at what specifically is needed DEV/PROD distinctions with the SHA3 conditioning block.
hey all, please correct me if i'm wrong, but i think the personalization string inside csrng is software input right? If that's the case, we probably can't rely on that exclusively since the software could just claim to be in whatever state it wants to be. So if we do go that route, it would be better to attach something extra to the string that software already provides. Is that feasible? I can't remember if there's a max length limit to the string.
And regarding SHA3, if it is legal, I honestly was just thinking of padding the input to conditioning with some extra input (state information).
Again, not sure at all if the specs allow it, but that's where i was headed at least.
From discussion this morning - we will create a diversification value for lifecycle states of PROD*, and use zero for DEV (and all others), with the intent of only consuming the diversification value in the non-deterministic operating modes. In the deterministic modes (e.g. replicating FIPS vectors) we cannot use the diversification value as there are specific inputs supplied to produce known-answer values.
CSRNG already has an input to indicate if the part is in PROD* which is being used to disable certain debug features. So @mwbranstad will use this same signal to select between the two diversification values.
@mwbranstad will look at the way the command/flag inputs to CSRNG are consumed, to make sure the type of operation is being correctly determined for the purposes of mixing in the diversification value.
@msfschaffner I was asked to get your help in doing a small PR to add a 384-bit compile-time random parameter for this diversification value, as none of us know the "magic" required to do so but we expect you do. ;) I can work with you to define the name / location for the parameter.
@cdgori, that sounds good to me. Another option would have been to generate the diversification value in the lc_ctrl and feed it over to csrng (this is done for the key manager, see here). But given that this would involve an interface change, and that the lc_hw_debug_en_i is already routed to csrng, the solution proposed here is probably easier to implement.
As for adding the random netlist constant, you have to do two things:
-
Add the constants as instantiation parameters to the top of the IP like so https://github.com/lowRISC/opentitan/blob/2dae1b21f682740b7c13fc8efd7ff5aa2acc60e6/hw/ip/lc_ctrl/rtl/lc_ctrl.sv#L20-L22
-
Declare that these parameters are random netlist constants in the Hjson file:https://github.com/lowRISC/opentitan/blob/2dae1b21f682740b7c13fc8efd7ff5aa2acc60e6/hw/ip/lc_ctrl/data/lc_ctrl.hjson#L39-L57
Then, rerun reggen and topgen with make -C hw, and you're done.
How do we handle 'SP.800-90A section 11.3 Health Testing' which includes known-answer-tests (KAT)? What's the SW and HW parts in it? Do we plan a different KAT for DEV and PROD? BTW, I don't see much value in such diversification considering that the input to the mechanism is random.
@zi-v we had some discussion of the KAT in the call this week, it sounded like KAT needed to pass on PROD. (It was not clear to me exactly the invocation of the KAT since if it depends on random it cannot be KAT... I was willing to omit the diversification value in the case of deterministic operation, if that is how the KAT is run.)
The primary value of the diversification to me is in the case where the input is made not-random, or much-less-random by an attacker. Then the attacker has less ability to use the DEV part (where there is increased observability) as an oracle for a PROD part being steered in a similar not-random/less-random fashion. If you want to discuss more on next week's call that is fine for me too.
The KAT tests is something that will apply to EDN1 and the CSRNG software instance.
Using the CSRNG as an example, the expectation is that software will follow the following sequence of operations:
instantiate_kat: Issue instantiate command withflag0=1and a known seed taken from test vector. Compare internal state against the test vector expected values.reseed_kat: Issue reseed command withflag0=1and a known seed taken from the test vector. Check internal state.generate_kat: Issue generate command and check internal state and expected DRBG output.
After this, the module can be set to FIPS mode enabled.
My assumption is that we will be able to use the INT_STATE_VAL and the INT_STATE_NUM registers to check the internal state.
For EDN1 I think the flow will be similar but will require additional OTBN assembly.
Looking at the CSRNG implementation for this div value, I see this as the case for the KAT (NIST vector) test: Since the KAT test needs to pass the seed, the seed value from ES is ignored. The ES seed gets XOR'ed with the div value before it is passed to the ctr_drbg processing logic, so in the case of a seed passed from the application side, the div value will have no affect, and the NIST vectors should continue to pass. Bottom line: CSRNG KAT test should be unaffected by this div value feature addition.
@msfschaffner I tried the above recipe, but it fails CI ultimately. I backed off the hjson changes, reran make -C hw, but keep the basic RTL changes in csrng - that passed CI. So I feel like some step is still missing - thoughts?
Can you let me know what the error was?
Note that you need to create the correct type for these parameters in the corresponding package.
I.e., type: "lc_ctrl_pkg::lc_keymgr_div_t", above is just an example, and needs to be replaced by something that points to csrng_pkg::<...>.
yes, create this type in the csrng_pkg.sv. Lint all runs fine, but some of the fpga board tests i think. will rerun.
Looking at the CSRNG implementation for this div value, I see this as the case for the KAT (NIST vector) test: Since the KAT test needs to pass the seed, the seed value from ES is ignored. The ES seed gets XOR'ed with the div value before it is passed to the ctr_drbg processing logic, so in the case of a seed passed from the application side, the div value will have no affect, and the NIST vectors should continue to pass. Bottom line: CSRNG KAT test should be unaffected by this div value feature addition.
If this is the case (and I am understanding you correctly that the diversification value has no effect on KAT), then I'd like to go back to requesting two build-time random diversification values, one for DEV and one for PROD. We had thought to use zero for the DEV one but it sounds like we don't need to?
@msfschaffner 6 CI tests now fail.
Two div values should not be an issue I believe.
I commented directly on the pull request under question https://github.com/lowRISC/opentitan/pull/6902
If this is the case (and I am understanding you correctly that the diversification value has no effect on KAT), then I'd like to go back to requesting two build-time random diversification values, one for DEV and one for PROD. We had thought to use zero for the DEV one but it sounds like we don't need to?
Updated the PR to include two div values. Running into a auto-gen issue where the smoke tests are failing, but I think the implementation in csrng looks fine now.