Skip to content

Commit 7b15fc1

Browse files
committed
hpke: relax seed size check in DeriveKeyPair
RFC 9180 section 7.1.3 says: > For a given KEM, the ikm parameter given to DeriveKeyPair() > SHOULD have length at least Nsk, and SHOULD have at least Nsk > bytes of entropy. Thus, it is not a requirement for HPKE to pass a seed with a fixed size. Protocols such as MLS rely on this. Closes: cloudflare#486
1 parent bba8f1a commit 7b15fc1

File tree

3 files changed

+0
-9
lines changed

3 files changed

+0
-9
lines changed

hpke/hybridkem.go

-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ func (k *hybridKEMPubKey) Equal(pk kem.PublicKey) bool {
160160
func (h hybridKEM) DeriveKeyPair(seed []byte) (kem.PublicKey, kem.PrivateKey) {
161161
// Implementation based on
162162
// https://www.ietf.org/archive/id/draft-irtf-cfrg-hpke-07.html#name-derivekeypair
163-
if len(seed) != h.SeedSize() {
164-
panic(kem.ErrSeedSize)
165-
}
166163

167164
outputSeedSize := h.kemA.SeedSize() + h.kemB.SeedSize()
168165
dkpPrk := h.labeledExtract([]byte(""), []byte("dkp_prk"), seed)

hpke/shortkem.go

-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ func (s shortKEM) calcDH(dh []byte, sk kem.PrivateKey, pk kem.PublicKey) error {
4444
func (s shortKEM) DeriveKeyPair(seed []byte) (kem.PublicKey, kem.PrivateKey) {
4545
// Implementation based on
4646
// https://www.ietf.org/archive/id/draft-irtf-cfrg-hpke-07.html#name-derivekeypair
47-
if len(seed) != s.SeedSize() {
48-
panic(kem.ErrSeedSize)
49-
}
5047

5148
bitmask := byte(0xFF)
5249
if s.Params().BitSize == 521 {

hpke/xkem.go

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ func (x xKEM) calcDH(dh []byte, sk kem.PrivateKey, pk kem.PublicKey) error {
5555
func (x xKEM) DeriveKeyPair(seed []byte) (kem.PublicKey, kem.PrivateKey) {
5656
// Implementation based on
5757
// https://www.ietf.org/archive/id/draft-irtf-cfrg-hpke-07.html#name-derivekeypair
58-
if len(seed) != x.SeedSize() {
59-
panic(kem.ErrSeedSize)
60-
}
6158
sk := &xKEMPrivKey{scheme: x, priv: make([]byte, x.size)}
6259
dkpPrk := x.labeledExtract([]byte(""), []byte("dkp_prk"), seed)
6360
bytes := x.labeledExpand(

0 commit comments

Comments
 (0)