mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-03 02:22:04 +00:00
* crypto: Use curve25519-voi This switches the ed25519, sr25519 and merlin provider to curve25519-voi and additionally adopts ZIP-215 semantics for ed25519 verification. * crypto: Implement batch verification interface for ed25519 and sr25519 This commit adds the batch verification interface, but does not enable it for anything. * types: Use batch verification for verifying commits signatures
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package sr25519
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/oasisprotocol/curve25519-voi/primitives/sr25519"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
)
|
|
|
|
var _ crypto.BatchVerifier = &BatchVerifier{}
|
|
|
|
// BatchVerifier implements batch verification for sr25519.
|
|
type BatchVerifier struct {
|
|
*sr25519.BatchVerifier
|
|
}
|
|
|
|
func NewBatchVerifier() crypto.BatchVerifier {
|
|
return &BatchVerifier{sr25519.NewBatchVerifier()}
|
|
}
|
|
|
|
func (b *BatchVerifier) Add(key crypto.PubKey, msg, signature []byte) error {
|
|
pk, ok := key.(PubKey)
|
|
if !ok {
|
|
return fmt.Errorf("sr25519: pubkey is not sr25519")
|
|
}
|
|
|
|
var srpk sr25519.PublicKey
|
|
if err := srpk.UnmarshalBinary(pk); err != nil {
|
|
return fmt.Errorf("sr25519: invalid public key: %w", err)
|
|
}
|
|
|
|
var sig sr25519.Signature
|
|
if err := sig.UnmarshalBinary(signature); err != nil {
|
|
return fmt.Errorf("sr25519: unable to decode signature: %w", err)
|
|
}
|
|
|
|
st := signingCtx.NewTranscriptBytes(msg)
|
|
b.BatchVerifier.Add(&srpk, st, &sig)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (b *BatchVerifier) Verify() (bool, []bool) {
|
|
return b.BatchVerifier.Verify(crypto.CReader())
|
|
}
|