...

Package curve4q

import "github.com/cloudflare/circl/dh/curve4q"
Overview
Index
Examples

Overview ▾

Package curve4q implements Diffie-Hellman operations using the FourQ curve at the 128-bit security level.

References:

Constants

Size is the size in bytes of keys.

const Size = 32

func KeyGen

func KeyGen(public, secret *Key)

KeyGen calculates a public key k from a secret key.

func Shared

func Shared(shared, secret, public *Key) bool

Shared calculates a shared key k from Alice's secret and Bob's public key. Returns true on success.

type Key

Key represents a public or private key of FourQ.

type Key [Size]byte

Example

Code:

var AliceSecret, BobSecret,
    AlicePublic, BobPublic,
    AliceShared, BobShared Key

// Generating Alice's secret and public keys
_, _ = io.ReadFull(rand.Reader, AliceSecret[:])
KeyGen(&AlicePublic, &AliceSecret)

// Generating Bob's secret and public keys
_, _ = io.ReadFull(rand.Reader, BobSecret[:])
KeyGen(&BobPublic, &BobSecret)

// Deriving Alice's shared key
Shared(&AliceShared, &AliceSecret, &BobPublic)

// Deriving Bob's shared key
Shared(&BobShared, &BobSecret, &AlicePublic)

fmt.Println(AliceShared == BobShared)

Output:

true