xwing

package
v0.0.0-...-fe4e43c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 6 Imported by: 0

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
	SharedKeySize        = 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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL