Documentation
¶
Overview ¶
Package xwing implements the hybrid post-quantum Key Encapsulation Mechanism (KEM) X-Wing as specified in [draft-connolly-cfrg-xwing-kem](https://www.ietf.org/archive/id/draft-connolly-cfrg-xwing-kem-07.html) which combines X25519 and ML-KEM-768.
Example ¶
package main
import (
"fmt"
"log"
"github.com/skerkour/stdx-go/xwing"
)
func main() {
alicePrivateKey := xwing.GenerateDecapsulationKey()
alicePublicKey := alicePrivateKey.EncapsulationKey()
// send Alice's PublicKey to Bob with alicePublicKey.Bytes()
alicePublicKey, err := xwing.NewEncapsulationKeyFromBytes(alicePublicKey.Bytes())
if err != nil {
log.Fatal(err)
}
// Bob can now compute a shared secret and a ciphertext
bobSharedSecret, ciphertext, err := alicePublicKey.Encapsulate()
if err != nil {
log.Fatal(err)
}
// Send the ciphertext to Alice
// Alice can know compute the same shared secret as Bob
aliceSharedSecret, err := alicePrivateKey.Decapsulate(ciphertext)
if err != nil {
log.Fatal(err)
}
if aliceSharedSecret == bobSharedSecret {
fmt.Println("shared secrets match")
}
}
Output: shared secrets match
Index ¶
Examples ¶
Constants ¶
View Source
const ( CiphertextSize = mlkem.CiphertextSize768 + 32 EncapsulationKeySize = mlkem.EncapsulationKeySize768 + 32 SeedSize = 32 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DecapsulationKey ¶
type DecapsulationKey struct {
// contains filtered or unexported fields
}
X-Wing decapsulationKey (public) key
func GenerateDecapsulationKey ¶
func GenerateDecapsulationKey() *DecapsulationKey
func NewDecapsulationKeyFromSeed ¶
func NewDecapsulationKeyFromSeed(seed [32]byte) *DecapsulationKey
func (*DecapsulationKey) Bytes ¶
func (decapKey *DecapsulationKey) Bytes() []byte
func (*DecapsulationKey) Decapsulate ¶
func (decapKey *DecapsulationKey) Decapsulate(ciphertext []byte) ([SharedKeySize]byte, error)
func (*DecapsulationKey) EncapsulationKey ¶
func (decapKey *DecapsulationKey) EncapsulationKey() *EncapsulationKey
type EncapsulationKey ¶
type EncapsulationKey struct {
// contains filtered or unexported fields
}
X-Wing encapsulation (public) key
func NewEncapsulationKeyFromBytes ¶
func NewEncapsulationKeyFromBytes(encapKeyBytes []byte) (*EncapsulationKey, error)
func (*EncapsulationKey) Bytes ¶
func (encapKey *EncapsulationKey) Bytes() []byte
func (*EncapsulationKey) Encapsulate ¶
func (encapKey *EncapsulationKey) Encapsulate() (sharedSecret [SharedKeySize]byte, ciphertext []byte, err error)
Click to show internal directories.
Click to hide internal directories.