ecc

package
v0.0.0-...-331fbfb Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ecc provides a way to generate, sign, and use Elliptic-Curve X25519 Cryptography keys.

Index

Constants

View Source
const DjbType = 0x05

DjbType is the Diffie-Hellman curve type (curve25519) created by D. J. Bernstein.

View Source
const KeySize int = 33

KeySize is the size of EC keys (32) with the EC type byte prepended to it.

Variables

This section is empty.

Functions

func CalculateSignature

func CalculateSignature(signingKey ECPrivateKeyable, message []byte) [64]byte

CalculateSignature signs a message with the given private key.

func CalculateSignatureAsync

func CalculateSignatureAsync(signingKey ECPrivateKeyable, message []byte, completion complete.Completionable)

CalculateSignatureAsync signs a message with the given private key asyncronously.

func VerifySignature

func VerifySignature(signingKey ECPublicKeyable, message []byte, signature [64]byte) bool

VerifySignature verifies that the message was signed with the given key.

func VerifySignatureAsync

func VerifySignatureAsync(signingKey ECPublicKeyable, message []byte, signature [64]byte, completion complete.Completionable)

VerifySignatureAsync verifies that a message was signed with the given key asyncronously.

Types

type DjbECPrivateKey

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

DjbECPrivateKey implements the ECPrivateKey interface and uses Curve25519.

func NewDjbECPrivateKey

func NewDjbECPrivateKey(key [32]byte) *DjbECPrivateKey

NewDjbECPrivateKey returns a new EC private key with the given bytes.

func (*DjbECPrivateKey) PrivateKey

func (d *DjbECPrivateKey) PrivateKey() [32]byte

PrivateKey returns the private key as a byte-array.

func (*DjbECPrivateKey) Serialize

func (d *DjbECPrivateKey) Serialize() [32]byte

Serialize returns the private key as a byte-array.

func (*DjbECPrivateKey) Type

func (d *DjbECPrivateKey) Type() int

Type returns the EC type value.

type DjbECPublicKey

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

DjbECPublicKey implements the ECPublicKey interface and uses Curve25519.

func NewDjbECPublicKey

func NewDjbECPublicKey(publicKey [32]byte) *DjbECPublicKey

NewDjbECPublicKey creates a new Curve25519 public key with the given bytes.

func (*DjbECPublicKey) PublicKey

func (d *DjbECPublicKey) PublicKey() [32]byte

PublicKey returns the EC public key as a byte array.

func (*DjbECPublicKey) Serialize

func (d *DjbECPublicKey) Serialize() []byte

Serialize returns the public key prepended by the DjbType value.

func (*DjbECPublicKey) Type

func (d *DjbECPublicKey) Type() int

Type returns the DjbType value.

type ECKeyPair

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

ECKeyPair is a combination of both public and private elliptic curve keys.

func GenerateKeyPair

func GenerateKeyPair() (*ECKeyPair, error)

GenerateKeyPair returns an EC Key Pair.

func NewECKeyPair

func NewECKeyPair(publicKey ECPublicKeyable, privateKey ECPrivateKeyable) *ECKeyPair

NewECKeyPair returns a new elliptic curve keypair given the specified public and private keys.

func (*ECKeyPair) PrivateKey

func (e *ECKeyPair) PrivateKey() ECPrivateKeyable

PrivateKey returns the private key from the key pair.

func (*ECKeyPair) PublicKey

func (e *ECKeyPair) PublicKey() ECPublicKeyable

PublicKey returns the public key from the key pair.

type ECPrivateKeyable

type ECPrivateKeyable interface {
	Serialize() [32]byte
	Type() int
}

ECPrivateKeyable is an interface for all elliptic curve private keys.

type ECPublicKeyable

type ECPublicKeyable interface {
	Serialize() []byte
	Type() int
	PublicKey() [32]byte
}

ECPublicKeyable is an interface for all elliptic curve public keys.

func DecodePoint

func DecodePoint(bytes []byte, offset int) (ECPublicKeyable, error)

DecodePoint will take the given bytes and offset and return an ECPublicKeyable object. This is used to check the byte at the given offset in the byte array for a special "type" byte that will determine the key type. Currently only DJB EC keys are supported.

Jump to

Keyboard shortcuts

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