sntrup4591761

package module
v0.0.0-...-9e0f3af Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: ISC Imports: 8 Imported by: 21

README

sntrup4591761

Build Status ISC License GoDoc

Streamlined NTRU Prime 4591^761

sntrup4591761 is a Go library implementing the Streamlined NTRU Prime 4591761 cryptosystem. Most of the code consists of a port of the reference C implementation.

Constants

  • PublicKeySize

The size of an encoded public key.

  • PrivateKeySize

The size of an encoded private key.

  • CiphertextSize

The size of a ciphertext encapsulating a shared key.

  • SharedKeySize

The size of a shared key.

Functions

  • GenerateKey(s io.Reader) (*[PublicKeySize]byte, *[PrivateKeySize]byte, error)

GenerateKey returns a new a public/private key pair with randomness from s. GenerateKey will fail if randomness cannot be obtained from s.

  • Encapsulate(s io.Reader, publicKey *[PublicKeySize]byte) (*[CiphertextSize]byte, *[SharedKeySize]byte, error)

Encapsulate generates a random shared key and encrypts it with the given public key. The shared key and its corresponding ciphertext are returned. Encapsulate will fail if randomness cannot be obtained from s.

  • Decapsulate(ciphertext *[CiphertextSize]byte, privateKey *[PrivateKeySize]byte) (*[SharedKeySize]byte, int)

Decapsulate uses a private key to decrypt a ciphertext, returning an encapsulated shared key. Decapsulate will return zero if the ciphertext is invalid.

Examples

The library is accompanied by three small standalone applications demonstrating its use: keygen, encap, and decap. A test script is provided to exercise these applications comprehensively.

To build the bundled applications, ensure that the repository lies in your GOPATH and run make. Once built, the auxiliary test script can be triggered by invoking ./test.

Sage tests

A set of 128 different instances of NTRU Prime were simulated in Sage and their data compiled in testdata/sage128.gz. The TestSage Go test contrasts the results obtained by the library with those from the Sage implementation. Please note that this test can take seconds to complete.

Running the tests

To run the Sage tests and other tests, ensure that the repository lies in your GOPATH and run go test -v.

License

sntrup4591761 is licensed under the copyfree ISC License.

Documentation

Index

Constants

View Source
const (
	PublicKeySize  = 1218
	PrivateKeySize = 1600
	CiphertextSize = 1047
	SharedKeySize  = 32
)

Variables

This section is empty.

Functions

func Encapsulate

func Encapsulate(s io.Reader, pk *PublicKey) (*Ciphertext, *SharedKey, error)

Encapsulate generates a random shared key and encrypts it with the given public key. The shared key and its corresponding ciphertext are returned. Randomness is obtained from s.

func GenerateKey

func GenerateKey(s io.Reader) (*PublicKey, *PrivateKey, error)

GenerateKey returns a new public/private key pair with randomness from s.

Types

type Ciphertext

type Ciphertext = [CiphertextSize]byte

type PrivateKey

type PrivateKey = [PrivateKeySize]byte

type PublicKey

type PublicKey = [PublicKeySize]byte

type SharedKey

type SharedKey = [SharedKeySize]byte

func Decapsulate

func Decapsulate(cstr *Ciphertext, sk *PrivateKey) (*SharedKey, int)

Decapsulate uses a private key to decrypt a ciphertext, returning a shared key.

Directories

Path Synopsis
examples
r3
rq

Jump to

Keyboard shortcuts

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