mirror of
https://github.com/arnaucube/go-iden3-crypto.git
synced 2026-02-07 11:36:41 +01:00
Compare commits
4 Commits
feature/gi
...
feature/ex
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d189a6bedc | ||
|
|
14c3144613 | ||
|
|
b98a9fe65a | ||
|
|
4d1bbacd6c |
@@ -36,6 +36,13 @@ func NewRandPrivKey() PrivateKey {
|
||||
// Scalar converts a private key into the scalar value s following the EdDSA
|
||||
// standard, and using blake-512 hash.
|
||||
func (k *PrivateKey) Scalar() *PrivKeyScalar {
|
||||
s := SkToBigInt(k)
|
||||
return NewPrivKeyScalar(s)
|
||||
}
|
||||
|
||||
// SkToBigInt converts a private key into the *big.Int value following the
|
||||
// EdDSA standard, and using blake-512 hash
|
||||
func SkToBigInt(k *PrivateKey) *big.Int {
|
||||
sBuf := Blake512(k[:])
|
||||
sBuf32 := [32]byte{}
|
||||
copy(sBuf32[:], sBuf[:32])
|
||||
@@ -43,7 +50,7 @@ func (k *PrivateKey) Scalar() *PrivKeyScalar {
|
||||
s := new(big.Int)
|
||||
utils.SetBigIntFromLEBytes(s, sBuf32[:])
|
||||
s.Rsh(s, 3)
|
||||
return NewPrivKeyScalar(s)
|
||||
return s
|
||||
}
|
||||
|
||||
// Pub returns the public key corresponding to a private key.
|
||||
|
||||
@@ -103,6 +103,7 @@ func CheckBigIntArrayInField(arr []*big.Int) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// BigIntArrayToElementArray converts an array of *big.Int into an array of *ff.Element
|
||||
func BigIntArrayToElementArray(bi []*big.Int) []*ff.Element {
|
||||
var o []*ff.Element
|
||||
for i := range bi {
|
||||
@@ -110,3 +111,15 @@ func BigIntArrayToElementArray(bi []*big.Int) []*ff.Element {
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// ElementArrayToBigIntArray converts an array of *ff.Element into an array of *big.Int
|
||||
func ElementArrayToBigIntArray(e []*ff.Element) []*big.Int {
|
||||
var o []*big.Int
|
||||
for i := range e {
|
||||
ei := e[i]
|
||||
bi := big.NewInt(0)
|
||||
ei.ToBigIntRegular(bi)
|
||||
o = append(o, bi)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user