mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-08 03:56:42 +01:00
Poseidon Sponge Hash with different frame sizes (#52)
* Poseidon Sponge Hash with different frame sizes * Update deps. Bump go version * Update & fix linter. * Refactor a bit. * Reduce gc pressure
This commit is contained in:
committed by
GitHub
parent
edc36bfa52
commit
e5cf066b8b
@@ -87,7 +87,7 @@ func (p *PointProjective) Affine() *Point {
|
||||
|
||||
// Add computes the addition of two points in projective coordinates
|
||||
// representation
|
||||
func (p *PointProjective) Add(q *PointProjective, o *PointProjective) *PointProjective {
|
||||
func (p *PointProjective) Add(q, o *PointProjective) *PointProjective {
|
||||
// add-2008-bbjlp
|
||||
// https://hyperelliptic.org/EFD/g1p/auto-twisted-projective.html#doubling-dbl-2008-bbjlp
|
||||
a := ff.NewElement().Mul(q.Z, o.Z)
|
||||
@@ -209,7 +209,7 @@ func PointCoordSign(c *big.Int) bool {
|
||||
func PackSignY(sign bool, y *big.Int) [32]byte {
|
||||
leBuf := utils.BigIntLEBytes(y)
|
||||
if sign {
|
||||
leBuf[31] = leBuf[31] | 0x80 //nolint:gomnd
|
||||
leBuf[31] |= 0x80 //nolint:gomnd
|
||||
}
|
||||
return leBuf
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func UnpackSignY(leBuf [32]byte) (bool, *big.Int) {
|
||||
y := big.NewInt(0)
|
||||
if (leBuf[31] & 0x80) != 0x00 { //nolint:gomnd
|
||||
sign = true
|
||||
leBuf[31] = leBuf[31] & 0x7F //nolint:gomnd
|
||||
leBuf[31] &= 0x7F //nolint:gomnd
|
||||
}
|
||||
utils.SetBigIntFromLEBytes(y, leBuf[:])
|
||||
return sign, y
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Package babyjub eddsa implements the EdDSA over the BabyJubJub curve
|
||||
//
|
||||
//nolint:gomnd
|
||||
package babyjub
|
||||
|
||||
@@ -16,9 +17,9 @@ import (
|
||||
// pruneBuffer prunes the buffer during key generation according to RFC 8032.
|
||||
// https://tools.ietf.org/html/rfc8032#page-13
|
||||
func pruneBuffer(buf *[32]byte) *[32]byte {
|
||||
buf[0] = buf[0] & 0xF8
|
||||
buf[31] = buf[31] & 0x7F
|
||||
buf[31] = buf[31] | 0x40
|
||||
buf[0] &= 0xF8
|
||||
buf[31] &= 0x7F
|
||||
buf[31] |= 0x40
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -210,7 +211,7 @@ func (sComp *SignatureComp) Scan(src interface{}) error {
|
||||
if len(srcB) != 64 {
|
||||
return fmt.Errorf("can't scan []byte of len %d into Signature, want %d", len(srcB), 64)
|
||||
}
|
||||
copy(sComp[:], srcB[:])
|
||||
copy(sComp[:], srcB)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ func (s *Signature) Scan(src interface{}) error {
|
||||
return fmt.Errorf("can't scan []byte of len %d into Signature, want %d", len(srcB), 64)
|
||||
}
|
||||
buf := [64]byte{}
|
||||
copy(buf[:], srcB[:])
|
||||
copy(buf[:], srcB)
|
||||
_, err := s.Decompress(buf)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// the original blake from the SHA3 competition and not the new blake2 version.
|
||||
func Blake512(m []byte) []byte {
|
||||
h := blake512.New()
|
||||
_, err := h.Write(m[:])
|
||||
_, err := h.Write(m)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user