crypto

package
v0.0.0-...-868bdbc Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: AGPL-3.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PrivateKeySizeErr = errors.New("private key length does not equal expected key length")
)

Functions

func Hash

func Hash(hp HashPolicy, s *big.Int) *big.Int

Hash returns a hash of a big integer given a hash policy.

func Verify

func Verify(sp SignaturePolicy, hp HashPolicy, publicKey []byte, message []byte, signature []byte) bool

Verify returns true if the given signature was generated using the given public key, message, signature policy, and hash policy.

Types

type HashPolicy

type HashPolicy interface {
	HashBytes(b []byte) []byte
}

HashPolicy defines how to create a cryptographic hash.

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
	PrivKey    crypto.PrivKey
	PubKey     crypto.PubKey
}

KeyPair represents a private and public key pair.

func FromPrivateKey

func FromPrivateKey(sp SignaturePolicy, privateKey string) (*KeyPair, error)

FromPrivateKey returns a KeyPair given a signature policy and private key.

func (*KeyPair) PrivateKeyHex

func (k *KeyPair) PrivateKeyHex() string

PrivateKeyHex returns the hex representation of the private key.

func (*KeyPair) PublicKeyHex

func (k *KeyPair) PublicKeyHex() string

PublicKeyHex returns the hex representation of the public key.

func (*KeyPair) Sign

func (k *KeyPair) Sign(sp SignaturePolicy, hp HashPolicy, message []byte) ([]byte, error)

Sign returns a cryptographic signature that is a signed hash of the message.

func (*KeyPair) String

func (k *KeyPair) String() (string, string)

String returns the private and public key pair.

type SignaturePolicy

type SignaturePolicy interface {
	GenerateKeys() ([]byte, []byte, error)
	PrivateKeySize() int
	PrivateToPublic(privateKey []byte) ([]byte, error)
	PublicKeySize() int
	Sign(privateKey []byte, message []byte) []byte
	RandomKeyPair() *KeyPair
	Verify(publicKey []byte, message []byte, signature []byte) bool
}

SignaturePolicy defines the creation and validation of a cryptographic signature.

Directories

Path Synopsis
Package ed25519 implements the Ed25519 signature algorithm.
Package ed25519 implements the Ed25519 signature algorithm.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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