bls

package module
v0.0.0-...-bd61158 Latest Latest
Warning

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

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

README

Boneh–Lynn–Shacham Signature Scheme

Build Status

Disclaimer

I wrote this library to familiarize myself with some basic pairing-based cryptosystems. I am not a cryptographer. Nor has any cryptographer that I know reviewed this code. I would advise against using it in any production system.

Overview

This library provides a high-level API for signing and verifying message digests using the BLS signature scheme. It includes support for aggregate signatures, threshold signatures, and ring signatures.

Prerequisites

Install the pairing-based crypto library from Stanford.

wget https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz
if [[ $(sha256sum pbc-0.5.14.tar.gz) = \
	772527404117587560080241cedaf441e5cac3269009cdde4c588a1dce4c23d2* ]]
then
	tar xf pbc-0.5.14.tar.gz
	pushd pbc-0.5.14
	sh configure
	make
	sudo make install
	popd
else
	echo 'Cannot download PBC library from crypto.stanford.edu.'
	exit 1
fi

Install

Install this library using the go get command.

go get github.com/enzoh/go-bls

Usage

Check out the documentation.

License

GPLv3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregateVerify

func AggregateVerify(signature Signature, hashes [][sha256.Size]byte, keys []PublicKey) (bool, error)

Verify an aggregate signature on the message digests using the public keys of the signers.

func GenKeyShares

func GenKeyShares(t int, n int, system System) (PublicKey, []PublicKey, PrivateKey, []PrivateKey, error)

Generate a key pair from the given cryptosystem and divide each key into n shares such that t shares can combine signatures to recover a threshold signature. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func GenKeys

func GenKeys(system System) (PublicKey, PrivateKey, error)

Generate a key pair from the given cryptosystem. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func Verify

func Verify(signature Signature, hash [sha256.Size]byte, key PublicKey) bool

Verify a signature on the message digest using the public key of the signer.

Types

type Element

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

func PKElementFormString

func PKElementFormString(pairing Pairing, eleStr string) Element

func SKElementFormString

func SKElementFormString(pairing Pairing, eleStr string) Element

func (Element) Free

func (element Element) Free()

Free the memory occupied by the element. The element cannot be used after calling this function.

func (Element) GetPKElementString

func (ele Element) GetPKElementString() string

func (Element) GetSKElementString

func (ele Element) GetSKElementString() string

type Pairing

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

func GenPairing

func GenPairing(params Params) Pairing

Generate a pairing from the given parameters. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func (Pairing) Free

func (pairing Pairing) Free()

Free the memory occupied by the pairing. The pairing cannot be used after calling this function.

type Params

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

func GenParamsTypeA

func GenParamsTypeA(rbits int, qbits int) Params

Generate type A pairing parameters. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed. More information about type A pairing parameters can be found in the PBC library manual: https://crypto.stanford.edu/pbc/manual/ch08s03.html.

func GenParamsTypeD

func GenParamsTypeD(d uint, bitlimit uint) (Params, error)

Generate type D pairing parameters. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed. More information about type D pairing parameters can be found in the PBC library manual: https://crypto.stanford.edu/pbc/manual/ch08s06.html.

func GenParamsTypeF

func GenParamsTypeF(bits int) Params

Generate type F pairing parameters. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed. More information about type F pairing parameters can be found in the PBC library manual: https://crypto.stanford.edu/pbc/manual/ch08s08.html.

func ParamsFromBytes

func ParamsFromBytes(bytes []byte) (Params, error)

ParamsFromBytes imports Params from the provided byte slice. It expects the data format exported by ToBytes. An example of Type A params of this form can be found in param/a.param

This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func ParamsFromString

func ParamsFromString(paramsStr string) Params

func (Params) Free

func (params Params) Free()

Free the memory occupied by the pairing parameters. The parameters cannot be used after calling this function.

func (Params) GetParamsString

func (params Params) GetParamsString() string

func (Params) ToBytes

func (params Params) ToBytes() ([]byte, error)

ToBytes exports Params to a byte slice. The output format is a custom set of ASCII key-value pairs. Pairs are separated by the space character (` `), and delimited by a newline (`\n`).

type PrivateKey

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

func SKFromString

func SKFromString(SKString string, pairing Pairing) PrivateKey

func (PrivateKey) Free

func (secret PrivateKey) Free()

Free the memory occupied by the private key. The private key cannot be used after calling this function.

func (PrivateKey) GetSKString

func (sk PrivateKey) GetSKString() string

type PublicKey

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

func PKFromString

func PKFromString(PKString string, pairing Pairing) PublicKey

func (PublicKey) Free

func (key PublicKey) Free()

Free the memory occupied by the public key. The public key cannot be used after calling this function.

func (PublicKey) GetPKString

func (pk PublicKey) GetPKString() string

type Signature

type Signature = Element

func Aggregate

func Aggregate(signatures []Signature, system System) (Signature, error)

Aggregate signatures using the cryptosystem. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func Sign

func Sign(hash [sha256.Size]byte, secret PrivateKey) Signature

Sign a message digest using a private key. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func SignatureFromString

func SignatureFromString(pairing Pairing, signStr string) Signature

func Threshold

func Threshold(shares []Signature, memberIds []int, system System) (Signature, error)

Recover a threshold signature from the signature shares provided by the group members using the cryptosystem. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func (Signature) GetSignatureString

func (signature Signature) GetSignatureString() string

type System

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

func GenSystem

func GenSystem(pairing Pairing) (System, error)

Generate a cryptosystem from the given pairing. This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func SystemFromBytes

func SystemFromBytes(pairing Pairing, bytes []byte) (System, error)

SystemFromBytes imports a System from the provided byte slice.

This function allocates C structures on the C heap using malloc. It is the responsibility of the caller to prevent memory leaks by arranging for the C structures to be freed.

func SystemFromString

func SystemFromString(pairing Pairing, sysStr string) System

func (System) Free

func (system System) Free()

Free the memory occupied by the cryptosystem. The cryptosystem cannot be used after calling this function.

func (System) GetSystemString

func (sys System) GetSystemString() string

func (System) SigFromBytes

func (system System) SigFromBytes(bytes []byte) (Signature, error)

Convert a byte slice to a signature.

func (System) SigToBytes

func (system System) SigToBytes(signature Signature) []byte

Convert a signature to a byte slice.

func (System) ToBytes

func (system System) ToBytes() []byte

ToBytes exports the System to a byte slice.

Jump to

Keyboard shortcuts

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