[kmac] Entropy
KMAC/SHA3 needs a lot of entropy bits in operation. To complete a full Keccak round (24 rounds), it needs total 40kbits.
- 1600b for incoming message chunk to create two shares
- or only creating share for incoming message not the internal capacity. Then up to 1152bits
- 24 x 1600b for Domain Oriented Masking AND logic
It takes 18 + 72 cycles to complete. It means entropy should be fed in ~444bits/clk. Getting the entropy directly from CSRNG is almost impossible. Need to find a good way to create pseudo random bits without degrading the performance.
CC: @cdgori @tjaychen
Related to #3153
My two pence is to use a local LFSR with occasional entropy-based reseeding, perhaps with a scrambler on the outside, then some lightweight way to extend from say a 32b LFSR to 444b per cycles. The reasoning is that I don't think the security level requirements of each bit (the inter-bit dependency factor, for instance) is extremely high for this use case.
But I'll let @cdgori weigh in more on that.
i think it'll take some more formal analysis to determine what base we can duplicate from.. My understanding of the domain masking stuff is that you want the entropy bits to be independent from the shares that are being AND'd together. From that perspective the number of bits don't need to be large. However, the state gets mashed together until the next AND where fresh entropy is injected. I'm hoping there's a way to determine round to round how wide the changes spread, maybe that'll help us determine how many bits.
Other than that...I guess it's paper digging time...
@eunchan , what do you think about slowing keccak down even more? I kind of forgot...but keccak outputs r usable bits on output...so it could be (when compared to hmac) a latency heavy, high throughput function.
For example phase-2 is two cycles right now (is that how we get 72 cycles? 24 + 48?), what if we made it 4 cycles etc? Or worst case process fewer bits at a time. This would get us down closer to ~200 bits, and that's probably a bit more manageable (we could maybe use a 128b lfsr plus other stuff like @sjgitty suggesetd).
@moidx do you have any thoughts here? I'm not too clear on all the software keccak usecases, but the key manager ones for example would not suffer deeply from this. Worst case, key manager could always generate N seeds on every generate call. This would be kind of expensive in terms of storage (might be time to think about memories), but I think there are tricks we can play on locking of the kmac module to get around it.
I don't necessarily think for OpenTitan kmac needs to go as fast as possible and be hardened.
Another thought I had...is that if we trust the paper's claim that we can re-use shares of other masked positions of entropy (with the understanding it degenerates), then we follow that approach across a number of rounds, and accumulate fresh entropy which we XOR on both shares periodically.
So if 4 rounds takes 12 cycles to complete let's say... that would give us hypothetically 12 cycles to accumulate 1600b of entropy. So then every 4 rounds we would "inject" that entropy onto the states. I obviously can't say for sure how this impacts the sca-ness, but it's close in spirit to the paper's claim with "hopefully" more entropy...?
I'll try to give the paper's claims in this area a closer read tomorrow..along with the other paper that talks about the degeneration.
updated in hindsight... this feels like maybe a bad idea...
I have thought about this for the masking in aes. For any masking scheme to work, the random bits basically must fulfill two requirements:
- They must be uniformly distributed. This we can evaluate using simulation. The important part here is that the uniform distribution is achieved within 10 to 14 rounds for aes or 24 rounds for kmac. It is not sufficient to just let the thing run for thousands of cycles and then evaluate the distribution. Because we will reseed after between 10 to 24 cycles, the randomness produced in this window must be uniformly distributed.
- The random bits must be independent between rounds (and mask shares - we just have 1 mask share both for kmac and aes, so let's just look at the rounds). Whenever some remasking is done, it is crucial that the input and output mask are independent. Otherwise intermediate terms inside the remasking circuit are no longer necessarily independent from the actual data. The input mask typically depends somehow on the output mask of the previous round. So we need to ensure that the masks between rounds are independent. This is probably difficult to verify. To start with, I thought about splitting the incoming seed and feeding that to two separate structures (LFSR + scrambling) that we use in tandem.
My plan was to start designing an a prim_prng_masking for that purpose but it will probably be difficult to make it work for both aes, kmac and the various flavors of masking techniques we will experiment with.
Just a note that it would be nice, like the AES, for the KMAC to parameterize some of the hardening options so that we could have a way to contrast the secure and non-secure version. But we should figure out if that is easy to execute or not.
@sjgitty your comments are basically matching what Tim and I discussed yesterday.
But for DOM the independence (as @tjaychen and @vogelpi wrote) has to be analyzed - Tim and I couldn't immediately say how big the LSFR needed to be as compared to the total state pool of Keccak (200 bits? 400 bits? 100 bits?) - because it's related to the diffusion behavior of each round, as far as I can tell. So the sizing will be different for the AES as well, and dependent on the masking scheme we ultimately settle on.
@vogelpi in #3153 I linked to some slides by Daeman about non-uniformity in masks for threshold implementation, you might find them interesting - I think he took a shot at the practical effects of modest non-uniformity. I haven't found anything yet on independence though.
@eunchan , what do you think about slowing keccak down even more? I kind of forgot...but keccak outputs r usable bits on output...so it could be (when compared to hmac) a latency heavy, high throughput function.
For example phase-2 is two cycles right now (is that how we get 72 cycles? 24 + 48?), what if we made it 4 cycles etc? Or worst case process fewer bits at a time. This would get us down closer to ~200 bits, and that's probably a bit more manageable (we could maybe use a 128b lfsr plus other stuff like @sjgitty suggesetd).
The PRD mentiones > 72MB/s throughput for SHA3. Current estimate of SHA3-512 is 88.9MB/s at most. Any additional latency in a round will significantly affect the throughput and may not meet the perf requirement.
hmmm...could you point me to that? Because isn't our sha2 slower? (I could be mis-remembering). Ah i should mention the other part about this is that we need to probably clarify in our documentation we don't necessarily get the best of security / performance all the time.
In my mind, it is okay for an unhardened implementation to reach peak speeds, but okay for a hardened version to run slower.
hmmm...could you point me to that? Because isn't our sha2 slower? (I could be mis-remembering). Ah i should mention the other part about this is that we need to probably clarify in our documentation we don't necessarily get the best of security / performance all the time.
In my mind, it is okay for an unhardened implementation to reach peak speeds, but okay for a hardened version to run slower.
Here's one pager doc. https://docs.google.com/document/d/1_iwJIS1edEzb40vW5dYQqprN2ZTnmJYF_O5WzNeLIL8/edit
HMAC throughput is around 80MB/s
I think this means 80Mb (not MB) / sec, right? PRD seems to refer to 72Mb/sec as well (not 72MB). It's a big difference :)
yeah Euncahn and I just noticed that too :) big sigh of relief.
On Tue, Aug 18, 2020 at 11:29 AM Chris Gori [email protected] wrote:
I think this means 80Mb (not MB) / sec, right? PRD seems to refer to 72Mb/sec as well (not 72MB). It's a big difference :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/3175#issuecomment-675642161, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSUB7SI2XSUDLRQNMYDSBLCAVANCNFSM4QCNJIOQ .
Yeah, we can have 8 more clocks in Chi state.
If we run 64b LFSR, we can create 640b entropy per round. It exceeds what Tim think the minimum bit of entropy (320b).
On 8/18/20 11:45 AM, tjaychen wrote:
yeah Euncahn and I just noticed that too :) big sigh of relief.
On Tue, Aug 18, 2020 at 11:29 AM Chris Gori [email protected] wrote:
I think this means 80Mb (not MB) / sec, right? PRD seems to refer to 72Mb/sec as well (not 72MB). It's a big difference :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub
https://github.com/lowRISC/opentitan/issues/3175#issuecomment-675642161,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAH2RSUB7SI2XSUDLRQNMYDSBLCAVANCNFSM4QCNJIOQ
.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/3175#issuecomment-675650009, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJDG3SVTEGXZ27XT3UZCETSBLD5XANCNFSM4QCNJIOQ.
I have thought about this for the masking in aes. For any masking scheme to work, the random bits basically must fulfill two requirements:
- They must be uniformly distributed. This we can evaluate using simulation. The important part here is that the uniform distribution is achieved within 10 to 14 rounds for aes or 24 rounds for kmac. It is not sufficient to just let the thing run for thousands of cycles and then evaluate the distribution. Because we will reseed after between 10 to 24 cycles, the randomness produced in this window must be uniformly distributed.
- The random bits must be independent between rounds (and mask shares - we just have 1 mask share both for kmac and aes, so let's just look at the rounds). Whenever some remasking is done, it is crucial that the input and output mask are independent. Otherwise intermediate terms inside the remasking circuit are no longer necessarily independent from the actual data. The input mask typically depends somehow on the output mask of the previous round. So we need to ensure that the masks between rounds are independent. This is probably difficult to verify. To start with, I thought about splitting the incoming seed and feeding that to two separate structures (LFSR + scrambling) that we use in tandem.
My plan was to start designing an a
prim_prng_maskingfor that purpose but it will probably be difficult to make it work for both aes, kmac and the various flavors of masking techniques we will experiment with.
@vogelpi actually since you brought it up. I did want to ask one thing. In the AES masking, if I remember, there is both a state mask and the sbox mask. Why is there a need for the state mask? I had wondered maybe it was sufficient to inject entropy via the output mask at the sboxes, so I didn't completely follow why each round needed new entropy also. It would be great if you could enlighten me.
@eunchan are there (still) open question(s) on entropy for KMAC/SHA3? It appears (to me) that you have sorted this out. If so, can this issue be closed?