Skip to content

Commit

Permalink
Update docs to RFC9580 (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux authored Nov 7, 2024
1 parent 87b5974 commit f8b97d7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [3.0.0-alpha.0] 2024-01-18
### Added
- New simplified API that is not backward compatible.
- Full support for the crypto refresh.
- Full support for RFC 9580.
- Improved interoperability with other OpenPGP libraries.
- Streaming support for all operations.
- Introduces profiles for OpenPGP customization.
Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ decrypted, err := decHandle.Decrypt(armored, crypto.Armor)
myMessage := decrypted.Bytes()
```

To encrypt with the [latest proposed standard (RFC9580-to-be)](https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html):
To encrypt with the [latest OpenPGP standard (RFC 9580)](https://www.rfc-editor.org/rfc/rfc9580.html):
```go
import "github.com/ProtonMail/gopenpgp/v3/profile"

// Use the profile that conforms with the crypto refresh (RFC9580-to-be).
// Use the latest OpenPGP standard (RFC 9580).
pgp := crypto.PGPWithProfile(profile.RFC9580())
// The default crypto refresh profile uses Argon2 for deriving
// session keys and uses an AEAD for encryption (AES-256, OCB mode).
// Encrypt data with password
...
// Decrypt data with password
...
// The RFC9580 profile uses Argon2 for protecting encrypted keys and
// messages encrypted using a passphrase, and uses AEAD for encryption
// (AES-256, OCB mode).
// Encrypt/Decrypt data with a password
... // See code snippet above.
```

Use a custom or preset profile:
Expand All @@ -102,7 +101,7 @@ import "github.com/ProtonMail/gopenpgp/v3/profile"

// RFC4880 profile
pgp4880 := crypto.PGPWithProfile(profile.RFC4880())
// RFC9580 crypto refresh profile
// RFC9580 profile
pgpCryptoRefresh := crypto.PGPWithProfile(profile.RFC9580())
```

Expand Down Expand Up @@ -271,7 +270,7 @@ pgp4880 := crypto.PGPWithProfile(profile.RFC4880())
pgpCryptoRefresh := crypto.PGPWithProfile(profile.RFC9580())

// Note that RSA keys should not be generated anymore according to
// RFC9580 (crypto refresh).
// RFC9580.

keyGenHandle := pgp4880.KeyGeneration().AddUserId(name, email).New()
// Generates rsa keys with 3072 bits
Expand All @@ -284,9 +283,9 @@ keyGenHandle = pgpDefault.KeyGeneration().AddUserId(name, email).New()
ecKey, err := keyGenHandle.GenerateKey()

keyGenHandle = pgpCryptoRefresh.KeyGeneration().AddUserId(name, email).New()
// Generates curve25519 v6 keys with RFC9580 (crypto refresh).
// Generates curve25519 v6 keys with RFC9580.
ecKey, err = keyGenHandle.GenerateKey()
// Generates curve448 v6 keys with RFC9580 (crypto refresh).
// Generates curve448 v6 keys with RFC9580.
ecKeyHigh, err = keyGenHandle.GenerateKeyWithSecurity(constants.HighSecurity)
```

Expand Down
2 changes: 1 addition & 1 deletion crypto/encryption_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (eh *encryptionHandle) validate() error {
func (eh *encryptionHandle) armorChecksumRequired() bool {
if !constants.ArmorChecksumEnabled {
// If the default behavior is no checksum, we can ignore
// the logic for the crypto refresh check.
// the logic for the RFC9580 check.
return false
}
encryptionConfig := eh.profile.EncryptionConfig()
Expand Down
4 changes: 2 additions & 2 deletions crypto/encryption_handle_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (ehb *EncryptionHandleBuilder) Password(password []byte) *EncryptionHandleB
// Compress indicates if the plaintext should be compressed before encryption.
// Compression affects security and opens the door for side-channel attacks, which
// might allow to extract the plaintext data without a decryption key.
// The openpgp crypto refresh recommends to not use compression.
// RFC9580 recommends to not use compression.
func (ehb *EncryptionHandleBuilder) Compress() *EncryptionHandleBuilder {
ehb.handle.Compression = constants.DefaultCompression
return ehb
Expand All @@ -126,7 +126,7 @@ func (ehb *EncryptionHandleBuilder) Compress() *EncryptionHandleBuilder {
// CompressWith indicates if the plaintext should be compressed before encryption.
// Compression affects security and opens the door for side-channel attacks, which
// might allow to extract the plaintext data without a decryption key.
// The openpgp crypto refresh recommends to not use compression.
// RFC9580 recommends to not use compression.
// Allowed config options:
// constants.NoCompression: none, constants.DefaultCompression: profile default
// constants.ZIPCompression: zip, constants.ZLIBCompression: zlib.
Expand Down
14 changes: 6 additions & 8 deletions crypto/key_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
const (
// KeyGenerationRSA4096 allows to override the output key algorithm in key generation to rsa 4096.
KeyGenerationRSA4096 int = 1
// KeyGenerationC25519 allows to override the output key algorithm in key generation to curve25519.
KeyGenerationC25519 int = 2
// KeyGenerationC25519 allows to override the output key algorithm in key generation to curve25519 crypto refresh.
KeyGenerationC25519Refresh int = 3
// KeyGenerationC448 allows to override the output key algorithm in key generation to curve448.
KeyGenerationC448 int = 4
// KeyGenerationC448Refresh allows to override the output key algorithm in key generation to curve448 crypto refresh.
KeyGenerationC448Refresh int = 5
// KeyGenerationCurve25519Legacy allows to override the output key algorithm in key generation to curve25519 legacy (as defined in RFC4880bis).
KeyGenerationCurve25519Legacy int = 2
// KeyGenerationCurve25519 allows to override the output key algorithm in key generation to curve25519 (as defined in RFC9580).
KeyGenerationCurve25519 int = 3
// KeyGenerationCurve448 allows to override the output key algorithm in key generation to curve448 (as defined in RFC9580).
KeyGenerationCurve448 int = 4
)

type KeyGenerationProfile interface {
Expand Down
10 changes: 4 additions & 6 deletions crypto/key_generation_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ func updateConfig(config *packet.Config, algorithm int) {
case KeyGenerationRSA4096:
config.Algorithm = packet.PubKeyAlgoRSA
config.RSABits = 4096
case KeyGenerationC25519:
case KeyGenerationCurve25519Legacy:
config.V6Keys = false
config.Algorithm = packet.PubKeyAlgoEdDSA
config.Curve = packet.Curve25519
case KeyGenerationC25519Refresh:
case KeyGenerationCurve25519:
config.Algorithm = packet.PubKeyAlgoEd25519
case KeyGenerationC448:
config.Algorithm = packet.PubKeyAlgoEdDSA
config.Curve = packet.Curve448
case KeyGenerationC448Refresh:
case KeyGenerationCurve448:
config.Algorithm = packet.PubKeyAlgoEd448
}
}
2 changes: 1 addition & 1 deletion crypto/sign_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (sh *signatureHandle) validate() error {
func (sh *signatureHandle) armorChecksumRequired() bool {
if !constants.ArmorChecksumEnabled {
// If the default behavior is no checksum, we can ignore
// the logic for the crypto refresh check.
// the logic for the RFC9580 check.
return false
}
if sh.SignKeyRing == nil {
Expand Down
2 changes: 1 addition & 1 deletion profile/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func RFC4880() *Custom {
}

// RFC9580 returns a custom profile for this library
// that conforms with the algorithms in RFC9580 (crypto refresh).
// that conforms with the algorithms in RFC9580.
func RFC9580() *Custom {
setKeyAlgorithm := func(cfg *packet.Config, securityLevel int8) {
switch securityLevel {
Expand Down

0 comments on commit f8b97d7

Please sign in to comment.