Documentation ¶
Overview ¶
Package babyjub eddsa implements the EdDSA over the BabyJubJub curve
Index ¶
- Constants
- Variables
- func Blake512(m []byte) []byte
- func PackSignY(sign bool, y *big.Int) [32]byte
- func PointCoordSign(c *big.Int) bool
- func SkToBigInt(sk *PrivateKey) *big.Int
- func SkToPoseidonHash(sk *PrivateKey) *big.Int
- func SkToRawBigInt(sk *PrivateKey) *big.Int
- func UnpackSignY(leBuf [32]byte) (bool, *big.Int)
- type BjjWrappedPrivateKey
- func (w *BjjWrappedPrivateKey) Equal(x crypto.PrivateKey) bool
- func (w *BjjWrappedPrivateKey) Public() crypto.PublicKey
- func (w *BjjWrappedPrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
- func (w *BjjWrappedPrivateKey) SignUncompressed(rand io.Reader, digest []byte, opts crypto.SignerOpts) (*Signature, error)
- type BjjWrappedPublicKey
- type Point
- type PointProjective
- type PrivKeyScalar
- type PrivateKey
- func (sk *PrivateKey) BlindSign(msg *big.Int) (*Signature, error)
- func (sk *PrivateKey) Public() *PublicKey
- func (sk *PrivateKey) RawScalar() *big.Int
- func (sk *PrivateKey) Scalar() *PrivKeyScalar
- func (sk *PrivateKey) SchnorrPublicKey() *PublicKey
- func (sk *PrivateKey) SchnorrSign(msg *big.Int) *SchnorrSignature
- func (sk *PrivateKey) SignMimc7(msg *big.Int) *Signature
- func (sk *PrivateKey) SignPoseidon(msg *big.Int) *Signature
- type PublicKey
- func (pk *PublicKey) Compress() PublicKeyComp
- func (pk PublicKey) MarshalText() ([]byte, error)
- func (pk *PublicKey) Point() *Point
- func (pk *PublicKey) Scan(src interface{}) error
- func (pk *PublicKey) SchnorrVerify(msg *big.Int, sig *SchnorrSignature) (*Point, bool)
- func (pk PublicKey) String() string
- func (pk *PublicKey) UnmarshalText(h []byte) error
- func (pk PublicKey) Value() (driver.Value, error)
- func (pk *PublicKey) VerifyMimc7(msg *big.Int, sig *Signature) bool
- func (pk *PublicKey) VerifyPoseidon(msg *big.Int, sig *Signature) bool
- type PublicKeyComp
- func (pkComp *PublicKeyComp) Decompress() (*PublicKey, error)
- func (pkComp PublicKeyComp) MarshalText() ([]byte, error)
- func (pkComp *PublicKeyComp) Scan(src interface{}) error
- func (pkComp PublicKeyComp) String() string
- func (pkComp *PublicKeyComp) UnmarshalText(h []byte) error
- func (pkComp PublicKeyComp) Value() (driver.Value, error)
- type SchnorrSignature
- type Signature
- type SignatureComp
- func (sComp *SignatureComp) Decompress() (*Signature, error)
- func (sComp SignatureComp) MarshalText() ([]byte, error)
- func (sComp *SignatureComp) Scan(src interface{}) error
- func (sComp SignatureComp) String() string
- func (sComp *SignatureComp) UnmarshalText(h []byte) error
- func (sComp SignatureComp) Value() (driver.Value, error)
Constants ¶
const MaxAltBn128ValueString = "21888242871839275222246405745257275088548364400416034343698204186575808495617"
Variables ¶
var A *big.Int
A is one of the babyjub constants.
var Aff *ff.Element
Aff is A value in *ff.Element representation
var D *big.Int
D is one of the babyjub constants.
var Dff *ff.Element
Dff is D value in *ff.Element representation
var Order *big.Int
Order of the babyjub curve.
var SubOrder *big.Int
SubOrder is the order of the subgroup of the babyjub curve that contains the points that we use.
Functions ¶
func Blake512 ¶
Blake512 performs the blake-512 hash over the buffer m. Note that this is the original blake from the SHA3 competition and not the new blake2 version.
func PackSignY ¶
PackSignY packs the given sign and the coordinate Y of a point into a 32 byte array. This method does not check that the values belong to a valid Point in the curve.
func PointCoordSign ¶
PointCoordSign returns the sign of the curve point coordinate. It returns false if the sign is positive and false if the sign is negative.
func SkToBigInt ¶
func SkToBigInt(sk *PrivateKey) *big.Int
SkToBigInt converts a private key into the *big.Int value following the EdDSA standard, and using blake-512 hash
func SkToPoseidonHash ¶ added in v0.0.4
func SkToPoseidonHash(sk *PrivateKey) *big.Int
SkToPoseidonHash converts a private key into the *big.Int value hashing it with Poseidon. This is not secure, but this way we make sure that the key is compatible with ZoKrates.
func SkToRawBigInt ¶ added in v0.0.4
func SkToRawBigInt(sk *PrivateKey) *big.Int
SkToRawBigInt converts a private key into the *big.Int value.
func UnpackSignY ¶
UnpackSignY returns the sign and coordinate Y from a given compressed point. This method does not check that the Point belongs to the BabyJubJub curve, thus does not return error in such case. This method is intended to obtain the sign and the Y coordinate without checking if the point belongs to the curve, if the objective is to uncompress a point, Decompress method should be used instead.
Types ¶
type BjjWrappedPrivateKey ¶
type BjjWrappedPrivateKey struct {
// contains filtered or unexported fields
}
BjjWrappedPrivateKey is a wrapper for PrivateKey.
func NewBjjWrappedKey ¶
func NewBjjWrappedKey(privKey *PrivateKey) *BjjWrappedPrivateKey
NewBjjWrappedKey creates a new BjjWrappedPrivateKey.
func RandomBjjWrappedKey ¶
func RandomBjjWrappedKey() *BjjWrappedPrivateKey
RandomBjjWrappedKey creates a new BjjWrappedPrivateKey with a random private key.
func (*BjjWrappedPrivateKey) Equal ¶
func (w *BjjWrappedPrivateKey) Equal(x crypto.PrivateKey) bool
Equal returns true if the private keys are equal.
func (*BjjWrappedPrivateKey) Public ¶
func (w *BjjWrappedPrivateKey) Public() crypto.PublicKey
Public returns the public key of the private key.
func (*BjjWrappedPrivateKey) Sign ¶
func (w *BjjWrappedPrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
Sign signs the digest with the private key.
func (*BjjWrappedPrivateKey) SignUncompressed ¶
func (w *BjjWrappedPrivateKey) SignUncompressed(rand io.Reader, digest []byte, opts crypto.SignerOpts) (*Signature, error)
SignUncompressed signs the digest with the private key and returns uncompressed signature.
type BjjWrappedPublicKey ¶
type BjjWrappedPublicKey struct {
// contains filtered or unexported fields
}
BjjWrappedPublicKey is a wrapper for PublicKey.
type Point ¶
Point represents a point of the babyjub curve.
var B8 *Point
B8 is a base point of the babyjub multiplied by 8 to make it a base point of the subgroup in the curve.
func PointFromSignAndY ¶
PointFromSignAndY returns a Point from a Sign and the Y coordinate
func (*Point) Compress ¶
Compress the point into a 32 byte array that contains the y coordinate in little endian and the sign of the x coordinate.
func (*Point) Decompress ¶
Decompress a compressed Point into p, and also returns the decompressed Point. Returns error if the compressed Point is invalid.
func (*Point) InSubGroup ¶
InSubGroup returns true when the Point p is in the subgroup of the babyjub curve.
func (*Point) Mul ¶
Mul multiplies the Point q by the scalar s and stores the result in p, which is also returned.
func (*Point) Projective ¶
func (p *Point) Projective() *PointProjective
Projective returns a PointProjective from the Point
type PointProjective ¶
PointProjective is the Point representation in projective coordinates
func NewPointProjective ¶
func NewPointProjective() *PointProjective
NewPointProjective creates a new Point in projective coordinates.
func (*PointProjective) Add ¶
func (p *PointProjective) Add(q, o *PointProjective) *PointProjective
Add computes the addition of two points in projective coordinates representation
func (*PointProjective) Affine ¶
func (p *PointProjective) Affine() *Point
Affine returns the Point from the projective representation
type PrivKeyScalar ¶
PrivKeyScalar represents the scalar s output of a private key
func NewPrivKeyScalar ¶
func NewPrivKeyScalar(s *big.Int) *PrivKeyScalar
NewPrivKeyScalar creates a new PrivKeyScalar from a big.Int
func (*PrivKeyScalar) BigInt ¶
func (s *PrivKeyScalar) BigInt() *big.Int
BigInt returns the big.Int corresponding to a PrivKeyScalar.
func (*PrivKeyScalar) Public ¶
func (s *PrivKeyScalar) Public() *PublicKey
Public returns the public key corresponding to the scalar value s of a private key.
type PrivateKey ¶
type PrivateKey [32]byte
PrivateKey is an EdDSA private key, which is a 32byte buffer.
func NewRandPrivKey ¶
func NewRandPrivKey() PrivateKey
NewRandPrivKey generates a new random private key (using cryptographically secure randomness).
func (*PrivateKey) Public ¶
func (sk *PrivateKey) Public() *PublicKey
Public returns the public key corresponding to a private key.
func (*PrivateKey) RawScalar ¶
func (sk *PrivateKey) RawScalar() *big.Int
RawScalar returns the private key as a big integer.
func (*PrivateKey) Scalar ¶
func (sk *PrivateKey) Scalar() *PrivKeyScalar
Scalar converts a private key into the scalar value s following the EdDSA standard, and using blake-512 hash.
func (*PrivateKey) SchnorrPublicKey ¶
func (sk *PrivateKey) SchnorrPublicKey() *PublicKey
func (*PrivateKey) SchnorrSign ¶
func (sk *PrivateKey) SchnorrSign(msg *big.Int) *SchnorrSignature
func (*PrivateKey) SignMimc7 ¶
func (sk *PrivateKey) SignMimc7(msg *big.Int) *Signature
SignMimc7 signs a message encoded as a big.Int in Zq using blake-512 hash for buffer hashing and mimc7 for big.Int hashing.
func (*PrivateKey) SignPoseidon ¶
func (sk *PrivateKey) SignPoseidon(msg *big.Int) *Signature
SignPoseidon signs a message encoded as a big.Int in Zq using blake-512 hash for buffer hashing and Poseidon for big.Int hashing.
type PublicKey ¶
type PublicKey Point
PublicKey represents an EdDSA public key, which is a curve point.
func (*PublicKey) Compress ¶
func (pk *PublicKey) Compress() PublicKeyComp
Compress returns the PublicKeyCompr for the given PublicKey
func (PublicKey) MarshalText ¶
MarshalText implements the marshaler for PublicKey
func (*PublicKey) SchnorrVerify ¶
func (*PublicKey) UnmarshalText ¶
UnmarshalText implements the unmarshaler for the PublicKey
func (*PublicKey) VerifyMimc7 ¶
VerifyMimc7 verifies the signature of a message encoded as a big.Int in Zq using blake-512 hash for buffer hashing and mimc7 for big.Int hashing.
type PublicKeyComp ¶
type PublicKeyComp [32]byte
PublicKeyComp represents a compressed EdDSA Public key; it's a compressed curve point.
func (*PublicKeyComp) Decompress ¶
func (pkComp *PublicKeyComp) Decompress() (*PublicKey, error)
Decompress returns the PublicKey for the given PublicKeyComp
func (PublicKeyComp) MarshalText ¶
func (pkComp PublicKeyComp) MarshalText() ([]byte, error)
MarshalText implements the marshaler for the PublicKeyComp
func (*PublicKeyComp) Scan ¶
func (pkComp *PublicKeyComp) Scan(src interface{}) error
Scan implements Scanner for database/sql.
func (PublicKeyComp) String ¶
func (pkComp PublicKeyComp) String() string
String returns the string representation of the PublicKeyComp
func (*PublicKeyComp) UnmarshalText ¶
func (pkComp *PublicKeyComp) UnmarshalText(h []byte) error
UnmarshalText implements the unmarshaler for the PublicKeyComp
type SchnorrSignature ¶
type Signature ¶
Signature represents an EdDSA uncompressed signature.
func DecompressSig ¶
DecompressSig decompresses a compressed signature.
func (*Signature) Compress ¶
func (s *Signature) Compress() SignatureComp
Compress an EdDSA signature by concatenating the compression of the point R8 and the Little-Endian encoding of S.
func (*Signature) Decompress ¶
Decompress a compressed signature into s, and also returns the decompressed signature. Returns error if the Point decompression fails.
type SignatureComp ¶
type SignatureComp [64]byte
SignatureComp represents a compressed EdDSA signature.
func (*SignatureComp) Decompress ¶
func (sComp *SignatureComp) Decompress() (*Signature, error)
Decompress a compressed signature. Returns error if the Point decompression fails.
func (SignatureComp) MarshalText ¶
func (sComp SignatureComp) MarshalText() ([]byte, error)
MarshalText implements the marshaler for the SignatureComp
func (*SignatureComp) Scan ¶
func (sComp *SignatureComp) Scan(src interface{}) error
Scan implements Scanner for database/sql.
func (SignatureComp) String ¶
func (sComp SignatureComp) String() string
String returns the string representation of the SignatureComp
func (*SignatureComp) UnmarshalText ¶
func (sComp *SignatureComp) UnmarshalText(h []byte) error
UnmarshalText implements the unmarshaler for the SignatureComp