Skip to content

Commit 0f4d0fa

Browse files
committed
feat: Add PQC support and PQC & Symmetric profiles
1 parent 6fc90ca commit 0f4d0fa

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

crypto/base_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func readTestFile(name string, trimNewlines bool) string {
3535
func init() {
3636
testPGP = PGP()
3737
testPGP.defaultTime = NewConstantClock(testTime) // 2019-05-13T13:37:07+00:00
38-
testProfiles = []*profile.Custom{profile.Default(), profile.RFC4880(), profile.RFC9580()}
39-
testProfileNames = []string{"Default", "RFC4880", "RFC9580"}
38+
testProfiles = []*profile.Custom{profile.Default(), profile.RFC4880(), profile.RFC9580(), profile.Symmetric(), profile.PQC()}
39+
testProfileNames = []string{"Default", "RFC4880", "RFC9580", "Symmetric", "PQC"}
4040
initEncDecTest()
4141
initGenerateKeys()
4242
initArmoredKeys()

crypto/key_clear.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package crypto
33
import (
44
"crypto/dsa"
55
"crypto/rsa"
6-
"errors"
76
"math/big"
87

98
"github.com/ProtonMail/go-crypto/openpgp/ecdh"
@@ -76,7 +75,7 @@ func clearPrivateKey(privateKey interface{}) error {
7675
case *ed448.PrivateKey:
7776
return clearEd448PrivateKey(priv)
7877
default:
79-
return errors.New("gopenpgp: unknown private key")
78+
return nil
8079
}
8180
}
8281

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ProtonMail/gopenpgp/v3
33
go 1.22.0
44

55
require (
6-
github.com/ProtonMail/go-crypto v1.2.0
6+
github.com/ProtonMail/go-crypto v1.2.0-proton
77
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f
88
github.com/stretchr/testify v1.10.0
99
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/ProtonMail/go-crypto v1.2.0 h1:+PhXXn4SPGd+qk76TlEePBfOfivE0zkWFenhGhFLzWs=
2-
github.com/ProtonMail/go-crypto v1.2.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
1+
github.com/ProtonMail/go-crypto v1.2.0-proton h1:zPFHx2D6lXUIGccwfu5wqhgG7mNkgZkECQNYfO5fyqQ=
2+
github.com/ProtonMail/go-crypto v1.2.0-proton/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
33
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k=
44
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
55
github.com/cloudflare/circl v1.6.0 h1:cr5JKic4HI+LkINy2lg3W2jF8sHCVTBncJr5gIIq7qk=

profile/preset.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,65 @@ func RFC9580() *Custom {
8080
V6: true,
8181
}
8282
}
83+
84+
func PQC() *Custom {
85+
setKeyAlgorithm := func(cfg *packet.Config, securityLevel int8) {
86+
cfg.Algorithm = packet.PubKeyAlgoMldsa65Ed25519
87+
}
88+
return &Custom{
89+
SetKeyAlgorithm: setKeyAlgorithm,
90+
Hash: crypto.SHA512,
91+
CipherEncryption: packet.CipherAES256,
92+
CipherKeyEncryption: packet.CipherAES256,
93+
CompressionAlgorithm: packet.CompressionZLIB,
94+
AeadKeyEncryption: &packet.AEADConfig{
95+
DefaultMode: packet.AEADModeGCM,
96+
},
97+
AeadEncryption: &packet.AEADConfig{
98+
DefaultMode: packet.AEADModeGCM,
99+
},
100+
CompressionConfiguration: &packet.CompressionConfig{
101+
Level: 6,
102+
},
103+
S2kKeyEncryption: &s2k.Config{
104+
S2KMode: s2k.Argon2S2K,
105+
Argon2Config: &s2k.Argon2Config{},
106+
},
107+
S2kEncryption: &s2k.Config{
108+
S2KMode: s2k.Argon2S2K,
109+
Argon2Config: &s2k.Argon2Config{},
110+
},
111+
V6: true,
112+
}
113+
}
114+
115+
func Symmetric() *Custom {
116+
setKeyAlgorithm := func(cfg *packet.Config, securityLevel int8) {
117+
cfg.Algorithm = packet.ExperimentalPubKeyAlgoHMAC
118+
}
119+
return &Custom{
120+
SetKeyAlgorithm: setKeyAlgorithm,
121+
Hash: crypto.SHA512,
122+
CipherEncryption: packet.CipherAES256,
123+
CipherKeyEncryption: packet.CipherAES256,
124+
CompressionAlgorithm: packet.CompressionZLIB,
125+
AeadKeyEncryption: &packet.AEADConfig{
126+
DefaultMode: packet.AEADModeGCM,
127+
},
128+
AeadEncryption: &packet.AEADConfig{
129+
DefaultMode: packet.AEADModeGCM,
130+
},
131+
CompressionConfiguration: &packet.CompressionConfig{
132+
Level: 6,
133+
},
134+
S2kKeyEncryption: &s2k.Config{
135+
S2KMode: s2k.Argon2S2K,
136+
Argon2Config: &s2k.Argon2Config{},
137+
},
138+
S2kEncryption: &s2k.Config{
139+
S2KMode: s2k.Argon2S2K,
140+
Argon2Config: &s2k.Argon2Config{},
141+
},
142+
V6: true,
143+
}
144+
}

0 commit comments

Comments
 (0)