goliboqs

package module
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2019 License: MIT Imports: 4 Imported by: 0

README

goliboqs

GoDoc Build Status

goliboqs is a Go wrapper for the liboqs library. This enables Go applications to use post-quantum key encapsulation mechanisms (KEMs).

Usage

Sample usage is shown below. Error handling omitted for brevity.

// Load the library (don't forget to close)
lib, _ := goliboqs.LoadLib("/path/to/liboqs.so")
defer lib.Close()

// Get a particular KEM (don't forget to close)
kem, _ := lib.GetKem(goliboqs.KemKyber1024)
defer kem.Close()

// Use the kem...
publicKey, secretKey, _ := kem.KeyPair()
sharedSecret, ciphertext, _ := kem.Encaps(publicKey)
recoveredSecret, _ := kem.Decaps(ciphertext, secretKey)
// sharedSecret == recoveredSecret

Running tests

Tests assume liboqs has been installed into /usr/local/liboqs.

Documentation

Overview

Package goliboqs is a Go wrapper around the liboqs library (see https://github.com/open-quantum-safe/liboqs).

Usage

Sample usage is shown below. Error handling omitted for brevity.

// Load the library (don't forget to close)
lib, _ := goliboqs.LoadLib("/path/to/liboqs.so")
defer lib.Close()

// Get a particular KEM (don't forget to close)
kem, _ := lib.GetKem(goliboqs.KemKyber1024)
defer kem.Close()

// Use the kem...
publicKey, secretKey, _ := kem.KeyPair()
sharedSecret, ciphertext, _ := kem.Encaps(publicKey)
recoveredSecret, _ := kem.Decaps(ciphertext, secretKey)
// sharedSecret == recoveredSecret

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kem

type Kem interface {
	// KeyPair generates a new key pair.
	KeyPair() (publicKey, secretKey []byte, err error)

	// Encaps generates a new shared secret and encrypts it under the public key.
	Encaps(public []byte) (sharedSecret, ciphertext []byte, err error)

	// Decaps decrypts an encrypted shared secret.
	Decaps(ciphertext, secretKey []byte) (sharedSecret []byte, err error)

	// Close frees resources uses by this Kem.
	Close() error
}

A Kem is an implementation of a key encapsulation mechanism (KEM) from liboqs. Use GetKem to load a Kem by name. Call Close on the Kem to avoid resource leaks.

type KemType

type KemType string

A KemType identifies a KEM algorithm. Since these are just strings, you can call GetKem with anything you want. This may be useful if you are using a newer version of liboqs.

const (
	KemBike1L1        KemType = "BIKE1-L1"
	KemBike1L3        KemType = "BIKE1-L3"
	KemBike1L5        KemType = "BIKE1-L5"
	KemBike2L1        KemType = "BIKE2-L1"
	KemBike2L3        KemType = "BIKE2-L3"
	KemBike2L5        KemType = "BIKE2-L5"
	KemBike3L1        KemType = "BIKE3-L1"
	KemBike3L3        KemType = "BIKE3-L3"
	KemBike3L5        KemType = "BIKE3-L5"
	KemFrodo640AES    KemType = "FrodoKEM-640-AES"
	KemFrodo640Shake  KemType = "FrodoKEM-640-SHAKE"
	KemFrodo976AES    KemType = "FrodoKEM-976-AES"
	KemFrodo976Shake  KemType = "FrodoKEM-976-SHAKE"
	KemFrodo1344AES   KemType = "FrodoKEM-1344-AES"
	KemFrodo1344Shake KemType = "FrodoKEM-1344-SHAKE"
	KemNewHope512     KemType = "NewHope-512-CCA-KEM"
	KemNewHope1024    KemType = "NewHope-1024-CCA-KEM"
	KemKyber512       KemType = "Kyber-512-CCA-KEM"
	KemKyber768       KemType = "Kyber-768-CCA-KEM"
	KemKyber1024      KemType = "Kyber-1024-CCA-KEM"
	KemSidhP503       KemType = "Sidh-p503"
	KemSidhP751       KemType = "Sidh-p751"
	KemSikeP503       KemType = "Sike-p503"
	KemSikeP751       KemType = "Sike-p751"
)

KEM types defined by liboqs (see kem.h)

type Lib

type Lib struct {
	// contains filtered or unexported fields
}

Lib stores state for the loaded liboqs library. Call Close to free resources after use.

func LoadLib

func LoadLib(path string) (*Lib, error)

LoadLib loads the liboqs library. The path parameter is given directly to dlopen, see the dlopen man page for details of how path is interpreted. (Paths with a slash are treated as absolute or relative paths). Be sure to Close after use to free resources.

func (*Lib) Close

func (l *Lib) Close() error

Close frees resources used by the library and unloads it.

func (*Lib) GetKem

func (l *Lib) GetKem(kemType KemType) (Kem, error)

GetKem returns a Kem for the specified algorithm. Constants are provided for known algorithms, but any string can be provided and will be passed through to liboqs. As a reminder, some algorithms need to be explicitly enabled when building liboqs.

Source Files

Jump to

Keyboard shortcuts

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