mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-03 10:55:14 +00:00
age,cmd/age,cmd/age-keygen: add post-quantum hybrid keys
This commit is contained in:
committed by
Filippo Valsorda
parent
6ece9e45ee
commit
c6fcb5300c
@@ -5,10 +5,13 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"crypto/ecdh"
|
||||
"crypto/mlkem"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"filippo.io/age/internal/bech32"
|
||||
"filippo.io/hpke"
|
||||
)
|
||||
|
||||
// EncodeIdentity encodes a plugin identity string for a plugin with the given
|
||||
@@ -78,3 +81,28 @@ func validPluginName(name string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// EncodeX25519Recipient encodes a native X25519 recipient from a
|
||||
// [crypto/ecdh.X25519] public key. It's meant for plugins that implement
|
||||
// identities that are compatible with native recipients.
|
||||
func EncodeX25519Recipient(pk *ecdh.PublicKey) (string, error) {
|
||||
if pk.Curve() != ecdh.X25519() {
|
||||
return "", fmt.Errorf("wrong ecdh Curve")
|
||||
}
|
||||
return bech32.Encode("age", pk.Bytes())
|
||||
}
|
||||
|
||||
// EncodeHybridRecipient encodes a native MLKEM768-X25519 recipient from a
|
||||
// [crypto/mlkem.EncapsulationKey768] and a [crypto/ecdh.X25519] public key.
|
||||
// It's meant for plugins that implement identities that are compatible with
|
||||
// native recipients.
|
||||
func EncodeHybridRecipient(pq *mlkem.EncapsulationKey768, t *ecdh.PublicKey) (string, error) {
|
||||
if t.Curve() != ecdh.X25519() {
|
||||
return "", fmt.Errorf("wrong ecdh Curve")
|
||||
}
|
||||
pk, err := hpke.NewHybridPublicKey(pq, t)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create hybrid public key: %v", err)
|
||||
}
|
||||
return bech32.Encode("age1pq", pk.Bytes())
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2023 The age Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build go1.20
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"crypto/ecdh"
|
||||
"fmt"
|
||||
|
||||
"filippo.io/age/internal/bech32"
|
||||
)
|
||||
|
||||
// EncodeX25519Recipient encodes a native X25519 recipient from a
|
||||
// [crypto/ecdh.X25519] public key. It's meant for plugins that implement
|
||||
// identities that are compatible with native recipients.
|
||||
func EncodeX25519Recipient(pk *ecdh.PublicKey) (string, error) {
|
||||
if pk.Curve() != ecdh.X25519() {
|
||||
return "", fmt.Errorf("wrong ecdh Curve")
|
||||
}
|
||||
return bech32.Encode("age", pk.Bytes())
|
||||
}
|
||||
Reference in New Issue
Block a user