prysm-pulse/crypto/bls/bls.go

83 lines
3.1 KiB
Go
Raw Normal View History

// Package bls implements a go-wrapper around a library implementing the
// BLS12-381 curve and signature scheme. This package exposes a public API for
// verifying and aggregating BLS signatures used by Ethereum.
package bls
import (
"github.com/prysmaticlabs/prysm/v5/crypto/bls/blst"
"github.com/prysmaticlabs/prysm/v5/crypto/bls/common"
"github.com/prysmaticlabs/prysm/v5/crypto/bls/herumi"
)
// Initialize herumi temporarily while we transition to blst for ethdo.
func init() {
herumi.Init()
}
Change BLS to Herumi Again (#4181) * change to herumi's bls * change alias * change to better * add benchmark * build * change to bazel fork * fix prefix * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * make it work with library * update to latest * change again * add import * update to latest * add sha commit * new static lib with groups swapped * using herumis new lib * fix dep paths in c headers * update again * new changes * fix commit * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * fix serialization * comment * fix test * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * fix to herumis latest version * fix test * fix benchmarks * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * add new workspace * change commit and remove init * get test to pass * remove parameter * remove reverse byte order * make gazelle happy * set pure to off * fix failing tests * Merge branch 'master' into herumiBLS * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * Merge branch 'herumiBLS' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * remove old ref * use HashWithDomain functions * update to latest version * clean up * gaz * add back removed code * switch off pure * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * use local repo * resolve docker issues * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * fix build and tests * gaz * Merge branch 'master' into herumiBLS * Merge refs/heads/master into herumiBLS * Merge refs/heads/master into herumiBLS
2019-12-03 20:29:05 +00:00
// SecretKeyFromBytes creates a BLS private key from a BigEndian byte slice.
func SecretKeyFromBytes(privKey []byte) (SecretKey, error) {
return blst.SecretKeyFromBytes(privKey)
}
Change BLS to Herumi Again (#4181) * change to herumi's bls * change alias * change to better * add benchmark * build * change to bazel fork * fix prefix * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * make it work with library * update to latest * change again * add import * update to latest * add sha commit * new static lib with groups swapped * using herumis new lib * fix dep paths in c headers * update again * new changes * fix commit * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * fix serialization * comment * fix test * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * fix to herumis latest version * fix test * fix benchmarks * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * add new workspace * change commit and remove init * get test to pass * remove parameter * remove reverse byte order * make gazelle happy * set pure to off * fix failing tests * Merge branch 'master' into herumiBLS * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * Merge branch 'herumiBLS' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * remove old ref * use HashWithDomain functions * update to latest version * clean up * gaz * add back removed code * switch off pure * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * use local repo * resolve docker issues * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into herumiBLS * fix build and tests * gaz * Merge branch 'master' into herumiBLS * Merge refs/heads/master into herumiBLS * Merge refs/heads/master into herumiBLS
2019-12-03 20:29:05 +00:00
// PublicKeyFromBytes creates a BLS public key from a BigEndian byte slice.
func PublicKeyFromBytes(pubKey []byte) (PublicKey, error) {
return blst.PublicKeyFromBytes(pubKey)
}
// SignatureFromBytesNoValidation creates a BLS signature from a LittleEndian byte slice.
// It does not check validity of the signature, use only when the byte slice has
// already been verified
func SignatureFromBytesNoValidation(sig []byte) (Signature, error) {
return blst.SignatureFromBytesNoValidation(sig)
}
2019-09-16 21:39:45 +00:00
// SignatureFromBytes creates a BLS signature from a LittleEndian byte slice.
func SignatureFromBytes(sig []byte) (Signature, error) {
return blst.SignatureFromBytes(sig)
}
// MultipleSignaturesFromBytes creates a slice of BLS signatures from a LittleEndian 2d-byte slice.
func MultipleSignaturesFromBytes(sigs [][]byte) ([]Signature, error) {
return blst.MultipleSignaturesFromBytes(sigs)
}
Add blst for BLS (#6539) * Add blst third party dep * initial build * add init * blst passing tests * add feature flag * blst and herumi for spec tests * maybe this works for mac * Actually set feature flag * Add stub for VerifyMultipleSignatures for blst * verifyCompressed * use correct cores sizes * aggregate public keys * add multi-sig verification * encode not hash * revert back * go mod tidy * update blst to latest commit * add batch decompress * fix * add test * gofmt * update blst * go mod tidy * remove kubesec, fix * mod tidy * disable some remote cache * disable some remote cache * disable some remote cache * disable some remote cache * Switch to -D__ADX__ * update * tidy * fix build * Make blst for only linux,amd64 * gofmt * lint * lint * gazelle * fix build tag * more stub methods * shift adx instructions to x86 * fix arm64 * Revert "fix arm64" This reverts commit 4d34ac21b7509a1b385374e3039efecfcab614c1. * add one more in * Revert "Revert "fix arm64"" This reverts commit 1c8ae24ad16ff9811590f1058b9d98c90b63251a. * try darwin now * Revert "try darwin now" This reverts commit 6f884714b8e14a7a803b72157672b6e942047f37. * Add sha256 * remove TODO * checkpoint * finally builds * fix up * add tag * try again * explicit disabling * remove * select properly * fix * better * make CI happy too * Update .bazelrc * Update .bazelrc * fix tests * revert back * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * clean up tests * more clean up * clean up * add * Update shared/bls/blst/signature.go * Update shared/bls/blst/signature.go * Update .buildkite-bazelrc Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * try again * remove go tag * revert change * gaz * gazelle ignore Co-authored-by: nisdas <nishdas93@gmail.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-09-16 13:28:28 +00:00
// AggregatePublicKeys aggregates the provided raw public keys into a single key.
func AggregatePublicKeys(pubs [][]byte) (PublicKey, error) {
return blst.AggregatePublicKeys(pubs)
Add blst for BLS (#6539) * Add blst third party dep * initial build * add init * blst passing tests * add feature flag * blst and herumi for spec tests * maybe this works for mac * Actually set feature flag * Add stub for VerifyMultipleSignatures for blst * verifyCompressed * use correct cores sizes * aggregate public keys * add multi-sig verification * encode not hash * revert back * go mod tidy * update blst to latest commit * add batch decompress * fix * add test * gofmt * update blst * go mod tidy * remove kubesec, fix * mod tidy * disable some remote cache * disable some remote cache * disable some remote cache * disable some remote cache * Switch to -D__ADX__ * update * tidy * fix build * Make blst for only linux,amd64 * gofmt * lint * lint * gazelle * fix build tag * more stub methods * shift adx instructions to x86 * fix arm64 * Revert "fix arm64" This reverts commit 4d34ac21b7509a1b385374e3039efecfcab614c1. * add one more in * Revert "Revert "fix arm64"" This reverts commit 1c8ae24ad16ff9811590f1058b9d98c90b63251a. * try darwin now * Revert "try darwin now" This reverts commit 6f884714b8e14a7a803b72157672b6e942047f37. * Add sha256 * remove TODO * checkpoint * finally builds * fix up * add tag * try again * explicit disabling * remove * select properly * fix * better * make CI happy too * Update .bazelrc * Update .bazelrc * fix tests * revert back * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * clean up tests * more clean up * clean up * add * Update shared/bls/blst/signature.go * Update shared/bls/blst/signature.go * Update .buildkite-bazelrc Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * try again * remove go tag * revert change * gaz * gazelle ignore Co-authored-by: nisdas <nishdas93@gmail.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-09-16 13:28:28 +00:00
}
// AggregateMultiplePubkeys aggregates the provided decompressed keys into a single key.
func AggregateMultiplePubkeys(pubs []PublicKey) PublicKey {
return blst.AggregateMultiplePubkeys(pubs)
}
// AggregateSignatures converts a list of signatures into a single, aggregated sig.
func AggregateSignatures(sigs []common.Signature) common.Signature {
return blst.AggregateSignatures(sigs)
}
// AggregateCompressedSignatures converts a list of compressed signatures into a single, aggregated sig.
func AggregateCompressedSignatures(multiSigs [][]byte) (common.Signature, error) {
return blst.AggregateCompressedSignatures(multiSigs)
}
// VerifySignature verifies a single signature. For performance reason, always use VerifyMultipleSignatures if possible.
func VerifySignature(sig []byte, msg [32]byte, pubKey common.PublicKey) (bool, error) {
return blst.VerifySignature(sig, msg, pubKey)
}
// VerifyMultipleSignatures verifies multiple signatures for distinct messages securely.
func VerifyMultipleSignatures(sigs [][]byte, msgs [][32]byte, pubKeys []common.PublicKey) (bool, error) {
return blst.VerifyMultipleSignatures(sigs, msgs, pubKeys)
}
// NewAggregateSignature creates a blank aggregate signature.
func NewAggregateSignature() common.Signature {
return blst.NewAggregateSignature()
}
// RandKey creates a new private key using a random input.
func RandKey() (common.SecretKey, error) {
return blst.RandKey()
}