@@ -19,6 +19,7 @@ import (
1919const (
2020 maxSessionKeyLength = 64
2121 MlKemSeedLen = 64
22+ kdfContext = "OpenPGPCompositeKDFv1"
2223)
2324
2425type PublicKey struct {
@@ -138,16 +139,11 @@ func Decrypt(priv *PrivateKey, kEphemeral, ecEphemeral, ciphertext []byte) (msg
138139 return keywrap .Unwrap (kek , ciphertext )
139140}
140141
141- // buildKey implements the composite KDF 2a from
142- // https://mailarchive.ietf.org/arch/msg/ openpgp/NMTCy707LICtxIhP3Xt1U5C8MF0/
142+ // buildKey implements the composite KDF from
143+ // https://github.com/openpgp-pqc/draft- openpgp-pqc/pull/161
143144func buildKey (pub * PublicKey , eccSecretPoint , eccEphemeral , eccPublicKey , mlkemKeyShare , mlkemEphemeral []byte , mlkemPublicKey kem.PublicKey ) ([]byte , error ) {
144- h := sha3 .New256 ()
145-
146- // SHA3 never returns error
147- _ , _ = h .Write (eccSecretPoint )
148- _ , _ = h .Write (eccEphemeral )
149- _ , _ = h .Write (eccPublicKey )
150- eccKeyShare := h .Sum (nil )
145+ /// Set the output `ecdhKeyShare` to `eccSecretPoint`
146+ eccKeyShare := eccSecretPoint
151147
152148 serializedMlkemPublicKey , err := mlkemPublicKey .MarshalBinary ()
153149 if err != nil {
@@ -162,16 +158,17 @@ func buildKey(pub *PublicKey, eccSecretPoint, eccEphemeral, eccPublicKey, mlkemK
162158 // eccEphemeral - the ECDH ciphertext encoded as an octet string
163159 // eccPublicKey - The ECDH public key of the recipient as an octet string
164160
165- // 2a. SHA3-256(mlkemKeyShare || eccKeyShare || eccEphemeral || eccPublicKey || Domain)
166- // where Domain is "Domain" for LAMPS, and " mlkemEphemeral || mlkemPublicKey || algId" for OpenPGP
167- h . Reset ()
161+ // SHA3-256(mlkemKeyShare || eccKeyShare || eccEphemeral || eccPublicKey ||
162+ // mlkemEphemeral || mlkemPublicKey || algId || "OpenPGPCompositeKDFv1")
163+ h := sha3 . New256 ()
168164 _ , _ = h .Write (mlkemKeyShare )
169165 _ , _ = h .Write (eccKeyShare )
170166 _ , _ = h .Write (eccEphemeral )
171167 _ , _ = h .Write (eccPublicKey )
172168 _ , _ = h .Write (mlkemEphemeral )
173169 _ , _ = h .Write (serializedMlkemPublicKey )
174170 _ , _ = h .Write ([]byte {pub .AlgId })
171+ _ , _ = h .Write ([]byte (kdfContext ))
175172 return h .Sum (nil ), nil
176173}
177174
0 commit comments