Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions group/edwards25519/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func hashToField(m []byte, dst string, count int) []fieldElement {

func expandMessageXMD(h hash.Hash, m []byte, domainSeparator string, byteLen int) ([]byte, error) {
r := float64(byteLen) / float64(h.Size()>>3)
ell := int(math.Ceil(r))
ell := int64(math.Ceil(r))
if ell > 255 || ell < 0 || byteLen > 65535 || len(domainSeparator) == 0 {
return nil, errors.New("invalid parameters")
}
Expand All @@ -349,15 +349,15 @@ func expandMessageXMD(h hash.Hash, m []byte, domainSeparator string, byteLen int
domainSeparator = string(h.Sum(nil))
}

padDom, err := i2OSP(len(domainSeparator), 1)
padDom, err := i2OSP(int64(len(domainSeparator)), 1)
if err != nil {
return nil, err
}

dstPrime := append([]byte(domainSeparator), padDom...)
byteLenStr, _ := i2OSP(byteLen, 2)
byteLenStr, _ := i2OSP(int64(byteLen), 2)
zeroPad, _ := i2OSP(0, 1)
zPad, _ := i2OSP(0, h.BlockSize())
zPad, _ := i2OSP(0, uint32(h.BlockSize()))

// mPrime = Z_pad || msg || l_i_b_str || I2OSP(0, 1) || DST_prim
mPrime := make([]byte, 0, len(zPad)+len(m)+len(byteLenStr)+len(zeroPad)+len(dstPrime))
Expand All @@ -369,21 +369,21 @@ func expandMessageXMD(h hash.Hash, m []byte, domainSeparator string, byteLen int

// b0 = H(msg_prime)
h.Reset()
h.Write([]byte(mPrime))
h.Write(mPrime)
b0 := h.Sum(nil)

// b_1 = H(b_0 || I2OSP(1, 1) || DST_prime)
h.Reset()
h.Write(b0)
onePad, _ := i2OSP(1, 1)
h.Write([]byte(onePad))
h.Write([]byte(dstPrime))
h.Write(onePad)
h.Write(dstPrime)
b1 := h.Sum(nil)

bFinal := make([]byte, 0, len(b1)*(ell+1))
bFinal := make([]byte, 0, int64(len(b1))*(ell+1))
bFinal = append(bFinal, b1...)
bPred := b1
for i := 2; i <= ell; i++ {
for i := int64(2); i <= ell; i++ {
x, err := byteXor(bPred, b0, bPred)
if err != nil {
return nil, err
Expand All @@ -402,7 +402,7 @@ func expandMessageXMD(h hash.Hash, m []byte, domainSeparator string, byteLen int
return bFinal[:byteLen], nil
}

func expandMessageXOF(h sha3.ShakeHash, m []byte, domainSeparator string, byteLen int) ([]byte, error) {
func expandMessageXOF(h sha3.ShakeHash, m []byte, domainSeparator string, byteLen int64) ([]byte, error) {
if byteLen > 65535 || len(domainSeparator) == 0 {
return nil, errors.New("invalid parameters")
}
Expand All @@ -427,7 +427,7 @@ func expandMessageXOF(h sha3.ShakeHash, m []byte, domainSeparator string, byteLe
domainSeparator = string(dst)
}

dstPad, err := i2OSP(len(domainSeparator), 1)
dstPad, err := i2OSP(int64(len(domainSeparator)), 1)
if err != nil {
return nil, err
}
Expand All @@ -450,21 +450,21 @@ func expandMessageXOF(h sha3.ShakeHash, m []byte, domainSeparator string, byteLe
return nil, err
}

if n != byteLen {
if int64(n) != byteLen {
return nil, fmt.Errorf("read %d byte instead of expected %d from xof", n, byteLen)
}

return uniformBytes, nil
}

func i2OSP(x int, xLen int) ([]byte, error) {
b := big.NewInt(int64(x))
func i2OSP(x int64, xLen uint32) ([]byte, error) {
b := big.NewInt(x)
s := b.Bytes()
if len(s) > xLen {
if uint32(len(s)) > xLen {
return nil, fmt.Errorf("input %d superior to max length %d", len(s), xLen)
}

pad := make([]byte, (xLen - len(s)))
pad := make([]byte, (xLen - uint32(len(s))))
return append(pad, s...), nil
}

Expand Down
4 changes: 2 additions & 2 deletions group/edwards25519/point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestExpandMessageXMDSHA512(t *testing.T) {
func TestExpandMessageXOFSHAKE128ShortDST(t *testing.T) {
dst := "QUUX-V01-CS02-with-expander-SHAKE128"
h := sha3.NewShake128()
outputLength := []int{32, 128}
outputLength := []int64{32, 128}

expectedHex32byte := []string{
"86518c9cd86581486e9485aa74ab35ba150d1c75c88e26b7043e44e2acd735a2",
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestExpandMessageXOFSHAKE128ShortDST(t *testing.T) {
func TestExpandMessageXOFSHAKE128LongDST(t *testing.T) {
dst := "QUUX-V01-CS02-with-expander-SHAKE128-long-DST-111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
h := sha3.NewShake128()
outputLength := []int{32, 128}
outputLength := []int64{32, 128}

expectedHex32byte := []string{
"827c6216330a122352312bccc0c8d6e7a146c5257a776dbd9ad9d75cd880fc53",
Expand Down
4 changes: 2 additions & 2 deletions internal/test/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// ThresholdTest performs a simple check on a threshold scheme implementation
func ThresholdTest(test *testing.T, keyGroup kyber.Group, scheme sign.ThresholdScheme) {
msg := []byte("Hello threshold Boneh-Lynn-Shacham")
n := 10
n := uint32(10)
t := n/2 + 1
test.Run("Correct sharing and recovering", func(tt *testing.T) {
secret := keyGroup.Scalar().Pick(random.New())
Expand Down Expand Up @@ -85,7 +85,7 @@ func ThresholdTest(test *testing.T, keyGroup kyber.Group, scheme sign.ThresholdS
fakeShares := fakePriPoly.Shares(n)
fakeSigShares := make([][]byte, 0)
fakePubPoly := fakePriPoly.Commit(keyGroup.Point().Base())
for i := 0; i < n; i++ {
for i := uint32(0); i < n; i++ {
fakeSig, _ := scheme.Sign(fakeShares[i], msg)
fakeSigShares = append(fakeSigShares, fakeSig)
}
Expand Down
4 changes: 2 additions & 2 deletions proof/deniable.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
func DeniableProver(suite Suite, self int, prover Prover,
verifiers []Verifier) Protocol {

return Protocol(func(ctx Context) []error {
return func(ctx Context) []error {
dp := deniableProver{}
return dp.run(suite, self, prover, verifiers, ctx)
})
}
}

type deniableProver struct {
Expand Down
8 changes: 4 additions & 4 deletions proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,15 @@ func (prf *proof) prover(p Predicate, sval map[string]kyber.Scalar,
pval map[string]kyber.Point,
choice map[Predicate]int) Prover {

return Prover(func(ctx ProverContext) error {
return func(ctx ProverContext) error {
return prf.prove(p, sval, pval, choice, ctx)
})
}
}

// Produce a higher-order Verifier embodying a given proof predicate.
func (prf *proof) verifier(p Predicate, pval map[string]kyber.Point) Verifier {

return Verifier(func(ctx VerifierContext) error {
return func(ctx VerifierContext) error {
return prf.verify(p, pval, ctx)
})
}
}
Loading
Loading