bn256

package
v0.0.0-...-7f98e96 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 6 Imported by: 6

Documentation

Overview

Package bn256 is a wrapper around github.com/cloudflare/bn256.

In addition to generating and using keypairs for signing, it also contains functions needed to implement more involved cryptography, like threshold signatures and multisignatures.

Index

Constants

View Source
const SignatureLength = 64

SignatureLength is the length of the returned signatures after marshaling. It is not explicitly defined in the underlaying package, but it is always 64.

Variables

View Source
var Order = bn256.Order

Order reexports cloudflare/bn256.Order.

Functions

func GenerateKeys

func GenerateKeys() (*VerificationKey, *SecretKey, error)

GenerateKeys randomly.

func VerifyKeys

func VerifyKeys(vk *VerificationKey, sk *SecretKey) bool

VerifyKeys checks whether given secretKey and verificationKey forms a vaild pair.

Types

type PolyVerifier

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

PolyVerifier is a struct which can verify if the given sequence is a polynomial sequence of bounded degree.

func NewPolyVerifier

func NewPolyVerifier(n, f int) PolyVerifier

NewPolyVerifier returns a verifier of polynomial sequences of degree at most f and length n. We assume 0 <= f <= n-1.

func (*PolyVerifier) Verify

func (pv *PolyVerifier) Verify(elems []*VerificationKey) bool

Verify if the given sequence of elems is a polynomial sequence with bounded degree.

type SecretKey

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

SecretKey can be used to sign data.

func AddSecretKeys

func AddSecretKeys(sk1, sk2 *SecretKey) *SecretKey

AddSecretKeys returns a sum of the provided secret keys. If the first argument is nil, it treats it as a zero.

func DecodeSecretKey

func DecodeSecretKey(enc string) (*SecretKey, error)

DecodeSecretKey decodes a secret key encoded as a base64 string.

func NewSecretKey

func NewSecretKey(secret *big.Int) *SecretKey

NewSecretKey returns a secret key with the specified secret.

func (*SecretKey) Encode

func (sk *SecretKey) Encode() string

Encode encodes given SecretKey into a base64 string

func (*SecretKey) Marshal

func (sk *SecretKey) Marshal() []byte

Marshal the secret key.

func (*SecretKey) Sign

func (sk *SecretKey) Sign(msg []byte) *Signature

Sign returns a signature of msg.

func (*SecretKey) Unmarshal

func (sk *SecretKey) Unmarshal(data []byte) (*SecretKey, error)

Unmarshal the secret key.

func (*SecretKey) VerificationKey

func (sk *SecretKey) VerificationKey() *VerificationKey

VerificationKey returns the verification key associated with this secret key.

type Signature

type Signature struct {
	bn256.G1
}

Signature confirms some information.

func AddSignatures

func AddSignatures(sgn1, sgn2 *Signature) *Signature

AddSignatures returns a sum of the provided signatures. If the first argument is nil, it treats it as a zero.

func MulSignature

func MulSignature(sgn *Signature, n *big.Int) *Signature

MulSignature returns the provided signature multiplied by the integer. If the first argument is nil, it treats it as a one.

func (*Signature) Marshal

func (s *Signature) Marshal() []byte

Marshal the signature to bytes.

func (*Signature) Unmarshal

func (s *Signature) Unmarshal(data []byte) (*Signature, error)

Unmarshal a signature from bytes.

type VerificationKey

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

VerificationKey can verify the validity of signatures.

func AddVerificationKeys

func AddVerificationKeys(vk1, vk2 *VerificationKey) *VerificationKey

AddVerificationKeys returns a sum of the provided verification keys. If the first argument is nil, it treats it as a zero.

func DecodeVerificationKey

func DecodeVerificationKey(enc string) (*VerificationKey, error)

DecodeVerificationKey decodes a verification key encoded as a base64 string.

func NewVerificationKey

func NewVerificationKey(secret *big.Int) *VerificationKey

NewVerificationKey returns a verification key for the specified secret.

func (*VerificationKey) Encode

func (vk *VerificationKey) Encode() string

Encode encodes given VerificationKey into a base64 string

func (*VerificationKey) Marshal

func (vk *VerificationKey) Marshal() []byte

Marshal the verification key.

func (*VerificationKey) Unmarshal

func (vk *VerificationKey) Unmarshal(data []byte) (*VerificationKey, error)

Unmarshal the verification key.

func (*VerificationKey) Verify

func (vk *VerificationKey) Verify(s *Signature, msg []byte) bool

Verify returns true if the provided signature is valid for msg.

Jump to

Keyboard shortcuts

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