[kmac] sideload key size
It seems like whenever cfg.sideload is set and two valid key shares are provided through the KMAC sideload interface
that the internal key length value will be set to Key256 regardless of what is written to the key_len CSR,
which can lead to digest mismatches.
// Sideloaded key is used when KeyMgr KDF is active or !!CFG.sideload is set
always_comb begin
if (keymgr_key_en_i || (mux_sel == SelKeyMgr)) begin
// KeyLen is fixed to the $bits(sideloaded_key)
key_len_o = SideloadedKey;
end else begin
key_len_o = reg_key_len_i;
end
end
Is this intended behavior (as opposed to an approach where the sideloaded keys are sliced or padded with 0 to match the configured key_len) ?
And if so, can this be added to the documentation?
ah.. Thanks for checking, Udi. I think restricting the Key length to what keymgr provides makes more sense.
@tjaychen do you think it is possible scenario that software requests sideloading the secret key but does not use full secret key length but as a smaller or a padded key?
@moidx hmmmm... i don't feel like that would be the case. Because the sideload key usage will mostly be for stuff that's only on-die (we can't ever see the key to export it), so i don't see why there would be a need to "weaken" the key and not always use the strongest version.
Miguel do you see any reason for this?
@eunchan @tjaychen Thanks for confirming this, that makes sense!
ah we should wait for input from Miguel to confirm.
On Thu, Feb 11, 2021 at 12:41 PM udinator [email protected] wrote:
@eunchan https://github.com/eunchan @tjaychen https://github.com/tjaychen Thanks for confirming this, that makes sense!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/5212#issuecomment-777775340, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSQZQRAC3JHJEPYHQELS6Q6JBANCNFSM4XOQ4AFQ .
sgtm, will keep the related PR open until this is fully resolved.
edit: merged the PR to unblock some local work, will open a PR to amend as needed.
I agree with @tjaychen as the key is not expected to be visible to software and we don't have variable key size outputs.
The only case I can think of is if we wanted to sideload 128B to AES and 128B to KMAC to implement authenticated encryption, but this can also be implemented with 2 key derivations and 2 256B keys.
@felixmiller in case I miss anything.
adding @cindychip for visibility
i believe this is okay to close.