schnorr_bn256

package
v0.0.0-...-ee1bab5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 6 Imported by: 0

README

Schnorr signature over bn256 curve

PubKey is rG. Signing:

  • k = rand()
  • R = kG
  • s = k + Hash(msg|P|R)*r Sig = <s, R>

Verification:

  • Check that sG equal to R + Hash(msg|P|R)*P

Description: s = k + hash*prv, so sG = G(k + hash*prv) R = kG, so R + hash*P = kG + hash*prv*G = G (k + hash*prv)

Documentation

Overview

Package schnorr_bn256 Copyright 2023 Oleg Fomenko. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

File `schnorr.go` implements Schnorr signature generation on the bn256 elliptic curve that compatible with alt_bn128 (https://eips.ethereum.org/EIPS/eip-1108)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Msg

func Msg(bytes ...[]byte) *big.Int

func R

func R(G *bn256.G1) (*big.Int, *bn256.G1, error)

func VerifySchnorr

func VerifySchnorr(sig *SchnorrSignature, PublicKey *bn256.G1, G *bn256.G1, m *big.Int) bool

VerifySchnorr verifies Schnorr signature validity. Can be used both for mono- and multi- signing. For multi-signature `PublicKey` should be an aggregated public key. For mono-signature `PublicKey` should be an elliptic point `prv*G`.

Types

type HashF

type HashF func(bytes ...[]byte) []byte
var (
	Hash            HashF = crypto.Keccak256
	ErrFailedRandom       = errors.New("failed to generate secure random")
)

type SchnorrSignature

type SchnorrSignature struct {
	R *bn256.G1
	S *big.Int
}

func MultiSigSchnorr

func MultiSigSchnorr(prv *big.Int, r *big.Int, PubKeyCommon *bn256.G1, RCommon *bn256.G1, m *big.Int) (*SchnorrSignature, error)

MultiSigSchnorr creates the Schnorr signature for the given public key and message. For multi-signature `PubKeyCommon` should be an aggregated public key and `RCommon` should be aggregated R.

func SignSchnorr

func SignSchnorr(prv *big.Int, PublicKey *bn256.G1, G *bn256.G1, m *big.Int) (*SchnorrSignature, error)

SignSchnorr creates the Schnorr signature for the given public key and message. `PublicKey` should be an elliptic point `prv*G`.

Jump to

Keyboard shortcuts

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