mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-01-09 07:33:47 +00:00
Import bug fixes from MSP.
This commit is contained in:
25
msp/msp.go
25
msp/msp.go
@@ -198,16 +198,16 @@ func (m MSP) DistributeShares(sec []byte, modulus *big.Int, db *UserDatabase) (m
|
||||
case String:
|
||||
name := cond.(String).string
|
||||
if _, ok := out[name]; ok {
|
||||
out[name] = append(out[name], share.Bytes())
|
||||
out[name] = append(out[name], m.encode(share, modulus))
|
||||
} else if (*db).ValidUser(name) {
|
||||
out[name] = [][]byte{share.Bytes()}
|
||||
out[name] = [][]byte{m.encode(share, modulus)}
|
||||
} else {
|
||||
return out, errors.New("Unknown user in predicate.")
|
||||
}
|
||||
|
||||
default:
|
||||
below := MSP(cond.(Formatted))
|
||||
subOut, err := below.DistributeShares(share.Bytes(), modulus, db)
|
||||
subOut, err := below.DistributeShares(m.encode(share, modulus), modulus, db)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
@@ -343,8 +343,6 @@ func (m MSP) recoverSecret(modulus *big.Int, db *UserDatabase, cache map[string]
|
||||
|
||||
// Compute dot product of the shares vector and the reconstruction vector to
|
||||
// reconstruct the secret.
|
||||
size := len(modulus.Bytes())
|
||||
out := make([]byte, size)
|
||||
secInt := big.NewInt(0)
|
||||
|
||||
for i, share := range shares {
|
||||
@@ -364,6 +362,19 @@ func (m MSP) recoverSecret(modulus *big.Int, db *UserDatabase, cache map[string]
|
||||
secInt.Add(secInt, shareInt).Mod(secInt, modulus)
|
||||
}
|
||||
|
||||
out = append(out, secInt.Bytes()...)
|
||||
return out[len(out)-size:], nil
|
||||
return m.encode(secInt, modulus), nil
|
||||
}
|
||||
|
||||
func (m MSP) encode(x *big.Int, modulus *big.Int) (out []byte) {
|
||||
tmp := x.Bytes()
|
||||
tmpSize := len(tmp)
|
||||
|
||||
modSize := len(modulus.Bytes())
|
||||
out = make([]byte, modSize)
|
||||
|
||||
for pos := 0; pos < tmpSize; pos++ {
|
||||
out[modSize-pos-1] = tmp[tmpSize-pos-1]
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -133,7 +133,14 @@ func StringToRaw(r string) (out Raw, err error) {
|
||||
|
||||
if staging.Len() == 0 {
|
||||
if len(r) == 0 {
|
||||
return top[0].Front().Value.(Raw), nil
|
||||
res := top[0].Front().Value
|
||||
|
||||
switch res.(type) {
|
||||
case Raw:
|
||||
return res.(Raw), nil
|
||||
default:
|
||||
return out, errors.New("Invalid string: Only one condition was found.")
|
||||
}
|
||||
}
|
||||
return out, errors.New("Invalid string: Can't parse anymore, but there's still data. Too many closing parentheses or too few opening parentheses?")
|
||||
}
|
||||
|
||||
@@ -72,3 +72,11 @@ func TestRaw(t *testing.T) {
|
||||
t.Fatalf("Query #2 formatted wrong: %v", query2.Formatted().String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneCondition(t *testing.T) {
|
||||
_, err := StringToRaw("(Alice or Bob)")
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("A predicate with only one condition should fail to parse!")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user