Skip to content

Commit 38b3bab

Browse files
twisslubux
authored andcommitted
Add support for draft-ietf-openpgp-persistent-symmetric-keys-00
This partially reverts commit f280790.
1 parent 8a5f08c commit 38b3bab

25 files changed

+1083
-117
lines changed

openpgp/internal/algorithm/aead.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
// operation.
1313
type AEADMode uint8
1414

15+
// Id returns the algorithm ID, as a byte, of mode.
16+
func (mode AEADMode) Id() uint8 {
17+
return uint8(mode)
18+
}
19+
1520
// Supported modes of operation (see RFC4880bis [EAX] and RFC7253)
1621
const (
1722
AEADModeEAX = AEADMode(1)

openpgp/internal/algorithm/cipher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var CipherById = map[uint8]Cipher{
4646

4747
type CipherFunction uint8
4848

49-
// ID returns the algorithm Id, as a byte, of cipher.
49+
// Id returns the algorithm ID, as a byte, of cipher.
5050
func (sk CipherFunction) Id() uint8 {
5151
return uint8(sk)
5252
}

openpgp/key_generation.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,12 @@ func newSigner(config *packet.Config) (signer interface{}, err error) {
322322
return nil, err
323323
}
324324
return priv, nil
325-
case packet.ExperimentalPubKeyAlgoHMAC:
325+
case packet.PubKeyAlgoHMAC:
326326
hash := algorithm.HashById[hashToHashId(config.Hash())]
327327
return symmetric.HMACGenerateKey(config.Random(), hash)
328+
case packet.ExperimentalPubKeyAlgoHMAC:
329+
hash := algorithm.HashById[hashToHashId(config.Hash())]
330+
return symmetric.ExperimentalHMACGenerateKey(config.Random(), hash)
328331
case packet.PubKeyAlgoMldsa65Ed25519, packet.PubKeyAlgoMldsa87Ed448:
329332
if !config.V6() {
330333
return nil, goerrors.New("openpgp: cannot create a non-v6 mldsa_eddsa key")
@@ -383,9 +386,13 @@ func newDecrypter(config *packet.Config) (decrypter interface{}, err error) {
383386
return x25519.GenerateKey(config.Random())
384387
case packet.PubKeyAlgoEd448, packet.PubKeyAlgoX448: // When passing Ed448, we generate an x448 subkey
385388
return x448.GenerateKey(config.Random())
386-
case packet.ExperimentalPubKeyAlgoAEAD:
389+
case packet.PubKeyAlgoHMAC, packet.PubKeyAlgoAEAD: // When passing HMAC, we generate an AEAD subkey
390+
cipher := algorithm.CipherFunction(config.Cipher())
391+
aead := algorithm.AEADMode(config.AEAD().Mode())
392+
return symmetric.AEADGenerateKey(config.Random(), cipher, aead)
393+
case packet.ExperimentalPubKeyAlgoHMAC, packet.ExperimentalPubKeyAlgoAEAD: // When passing HMAC, we generate an AEAD subkey
387394
cipher := algorithm.CipherFunction(config.Cipher())
388-
return symmetric.AEADGenerateKey(config.Random(), cipher)
395+
return symmetric.ExperimentalAEADGenerateKey(config.Random(), cipher)
389396
case packet.PubKeyAlgoMldsa65Ed25519, packet.PubKeyAlgoMldsa87Ed448:
390397
if pubKeyAlgo, err = packet.GetMatchingMlkem(config.PublicKeyAlgorithm()); err != nil {
391398
return nil, err

openpgp/keys.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,9 @@ func (e *Entity) serializePrivate(w io.Writer, config *packet.Config, reSign boo
771771
// Serialize writes the public part of the given Entity to w, including
772772
// signatures from other entities. No private key material will be output.
773773
func (e *Entity) Serialize(w io.Writer) error {
774-
if e.PrimaryKey.PubKeyAlgo == packet.ExperimentalPubKeyAlgoHMAC ||
774+
if e.PrimaryKey.PubKeyAlgo == packet.PubKeyAlgoHMAC ||
775+
e.PrimaryKey.PubKeyAlgo == packet.PubKeyAlgoAEAD ||
776+
e.PrimaryKey.PubKeyAlgo == packet.ExperimentalPubKeyAlgoHMAC ||
775777
e.PrimaryKey.PubKeyAlgo == packet.ExperimentalPubKeyAlgoAEAD {
776778
return errors.InvalidArgumentError("Can't serialize symmetric primary key")
777779
}
@@ -808,7 +810,9 @@ func (e *Entity) Serialize(w io.Writer) error {
808810
// public key packets contain no meaningful information and do not need
809811
// to be serialized.
810812
// Prevent public key export for forwarding keys, see forwarding section 4.1.
811-
if subkey.PublicKey.PubKeyAlgo == packet.ExperimentalPubKeyAlgoHMAC ||
813+
if subkey.PublicKey.PubKeyAlgo == packet.PubKeyAlgoHMAC ||
814+
subkey.PublicKey.PubKeyAlgo == packet.PubKeyAlgoAEAD ||
815+
subkey.PublicKey.PubKeyAlgo == packet.ExperimentalPubKeyAlgoHMAC ||
812816
subkey.PublicKey.PubKeyAlgo == packet.ExperimentalPubKeyAlgoAEAD ||
813817
subkey.Sig.FlagForward {
814818
continue

0 commit comments

Comments
 (0)