mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-01-04 04:04:24 +00:00
Respond to PR requests.
- Type String renamed Name. - Panic if an invalid modulus size is chosen rather. - Name the interface arguments for the UserDatabase.
This commit is contained in:
@@ -69,7 +69,7 @@ func StringToFormatted(f string) (out Formatted, err error) {
|
||||
|
||||
var min int
|
||||
minStr := top.Front()
|
||||
min, err = strconv.Atoi(minStr.Value.(String).string)
|
||||
min, err = strconv.Atoi(minStr.Value.(Name).string)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func StringToFormatted(f string) (out Formatted, err error) {
|
||||
indices[nxt] = 0
|
||||
}
|
||||
|
||||
staging.Front().Value.(*list.List).PushBack(String{nxt, indices[nxt]})
|
||||
staging.Front().Value.(*list.List).PushBack(Name{nxt, indices[nxt]})
|
||||
indices[nxt]++
|
||||
}
|
||||
}
|
||||
@@ -110,8 +110,8 @@ func (f Formatted) String() string {
|
||||
|
||||
for _, cond := range f.Conds {
|
||||
switch cond.(type) {
|
||||
case String:
|
||||
out += fmt.Sprintf(", %v", cond.(String).string)
|
||||
case Name:
|
||||
out += fmt.Sprintf(", %v", cond.(Name).string)
|
||||
case Formatted:
|
||||
out += fmt.Sprintf(", %v", (cond.(Formatted)).String())
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ func TestFormatted(t *testing.T) {
|
||||
query1 := Formatted{
|
||||
Min: 2,
|
||||
Conds: []Condition{
|
||||
String{"Alice", 0}, String{"Bob", 0}, String{"Carl", 0},
|
||||
Name{"Alice", 0}, Name{"Bob", 0}, Name{"Carl", 0},
|
||||
},
|
||||
}
|
||||
|
||||
query2 := Formatted{
|
||||
Min: 3,
|
||||
Conds: []Condition{
|
||||
String{"Alice", 0}, String{"Bob", 0}, String{"Carl", 0},
|
||||
Name{"Alice", 0}, Name{"Bob", 0}, Name{"Carl", 0},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ func TestFormatted(t *testing.T) {
|
||||
Formatted{
|
||||
Min: 1,
|
||||
Conds: []Condition{
|
||||
String{"Alice", 0}, String{"Bob", 0},
|
||||
Name{"Alice", 0}, Name{"Bob", 0},
|
||||
},
|
||||
},
|
||||
String{"Carl", 0},
|
||||
Name{"Carl", 0},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ func TestFormatted(t *testing.T) {
|
||||
Formatted{
|
||||
Min: 1,
|
||||
Conds: []Condition{
|
||||
String{"Alice", 0}, String{"Carl", 0},
|
||||
Name{"Alice", 0}, Name{"Carl", 0},
|
||||
},
|
||||
},
|
||||
String{"Bob", 0},
|
||||
Name{"Bob", 0},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
33
msp/msp.go
33
msp/msp.go
@@ -13,21 +13,21 @@ import (
|
||||
// when needed, rather than re-build a partial map of known data.
|
||||
type UserDatabase interface {
|
||||
ValidUser(name string) bool
|
||||
CanGetShare(string) bool
|
||||
GetShare(string) ([][]byte, error)
|
||||
CanGetShare(name string) bool
|
||||
GetShare(name string) ([][]byte, error)
|
||||
}
|
||||
|
||||
type Condition interface { // Represents one condition in a predicate
|
||||
Ok(*UserDatabase) bool
|
||||
}
|
||||
|
||||
type String struct { // Type of condition
|
||||
type Name struct { // Type of condition
|
||||
string
|
||||
index int
|
||||
}
|
||||
|
||||
func (s String) Ok(db *UserDatabase) bool {
|
||||
return (*db).CanGetShare(s.string)
|
||||
func (n Name) Ok(db *UserDatabase) bool {
|
||||
return (*db).CanGetShare(n.string)
|
||||
}
|
||||
|
||||
type TraceElem struct {
|
||||
@@ -98,10 +98,13 @@ func Modulus(n int) (modulus *big.Int) {
|
||||
modulus.Sub(modulus, big.NewInt(0).Lsh(big.NewInt(1), 96))
|
||||
modulus.Add(modulus, big.NewInt(1))
|
||||
|
||||
default: // Silent fail.
|
||||
case 127:
|
||||
modulus = big.NewInt(1) // 2^127 - 1
|
||||
modulus.Lsh(modulus, 127)
|
||||
modulus.Sub(modulus, big.NewInt(1))
|
||||
|
||||
default:
|
||||
panic("Invalid modulus size chosen!")
|
||||
}
|
||||
|
||||
return
|
||||
@@ -133,12 +136,12 @@ func (m MSP) DerivePath(db *UserDatabase) (ok bool, names []string, locs []int,
|
||||
|
||||
for i, cond := range m.Conds {
|
||||
switch cond.(type) {
|
||||
case String:
|
||||
if (*db).CanGetShare(cond.(String).string) {
|
||||
case Name:
|
||||
if (*db).CanGetShare(cond.(Name).string) {
|
||||
heap.Push(ts, TraceElem{
|
||||
i,
|
||||
[]string{cond.(String).string},
|
||||
[]string{cond.(String).string},
|
||||
[]string{cond.(Name).string},
|
||||
[]string{cond.(Name).string},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -195,8 +198,8 @@ func (m MSP) DistributeShares(sec []byte, modulus *big.Int, db *UserDatabase) (m
|
||||
}
|
||||
|
||||
switch cond.(type) {
|
||||
case String:
|
||||
name := cond.(String).string
|
||||
case Name:
|
||||
name := cond.(Name).string
|
||||
if _, ok := out[name]; ok {
|
||||
out[name] = append(out[name], m.encode(share, modulus))
|
||||
} else if (*db).ValidUser(name) {
|
||||
@@ -258,12 +261,12 @@ func (m MSP) recoverSecret(modulus *big.Int, db *UserDatabase, cache map[string]
|
||||
index = append(index, loc+1)
|
||||
|
||||
switch gate.(type) {
|
||||
case String:
|
||||
if len(cache[gate.(String).string]) <= gate.(String).index {
|
||||
case Name:
|
||||
if len(cache[gate.(Name).string]) <= gate.(Name).index {
|
||||
return nil, errors.New("Predicate / database mismatch!")
|
||||
}
|
||||
|
||||
shares = append(shares, cache[gate.(String).string][gate.(String).index])
|
||||
shares = append(shares, cache[gate.(Name).string][gate.(Name).index])
|
||||
|
||||
case Formatted:
|
||||
share, err := MSP(gate.(Formatted)).recoverSecret(modulus, db, cache)
|
||||
|
||||
18
msp/raw.go
18
msp/raw.go
@@ -155,7 +155,7 @@ func StringToRaw(r string) (out Raw, err error) {
|
||||
indices[nxt] = 0
|
||||
}
|
||||
|
||||
staging.Front().Value.([2]*list.List)[0].PushBack(String{nxt, indices[nxt]})
|
||||
staging.Front().Value.([2]*list.List)[0].PushBack(Name{nxt, indices[nxt]})
|
||||
indices[nxt]++
|
||||
}
|
||||
}
|
||||
@@ -167,8 +167,8 @@ func (r Raw) String() string {
|
||||
out := ""
|
||||
|
||||
switch (*r.Left).(type) {
|
||||
case String:
|
||||
out += (*r.Left).(String).string
|
||||
case Name:
|
||||
out += (*r.Left).(Name).string
|
||||
default:
|
||||
out += "(" + (*r.Left).(Raw).String() + ")"
|
||||
}
|
||||
@@ -180,8 +180,8 @@ func (r Raw) String() string {
|
||||
}
|
||||
|
||||
switch (*r.Right).(type) {
|
||||
case String:
|
||||
out += (*r.Right).(String).string
|
||||
case Name:
|
||||
out += (*r.Right).(Name).string
|
||||
default:
|
||||
out += "(" + (*r.Right).(Raw).String() + ")"
|
||||
}
|
||||
@@ -199,15 +199,15 @@ func (r Raw) Formatted() (out Formatted) {
|
||||
}
|
||||
|
||||
switch (*r.Left).(type) {
|
||||
case String:
|
||||
out.Conds = []Condition{(*r.Left).(String)}
|
||||
case Name:
|
||||
out.Conds = []Condition{(*r.Left).(Name)}
|
||||
default:
|
||||
out.Conds = []Condition{(*r.Left).(Raw).Formatted()}
|
||||
}
|
||||
|
||||
switch (*r.Right).(type) {
|
||||
case String:
|
||||
out.Conds = append(out.Conds, (*r.Right).(String))
|
||||
case Name:
|
||||
out.Conds = append(out.Conds, (*r.Right).(Name))
|
||||
default:
|
||||
out.Conds = append(out.Conds, (*r.Right).(Raw).Formatted())
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
)
|
||||
|
||||
func TestRaw(t *testing.T) {
|
||||
alice := Condition(String{"Alice", 0})
|
||||
bob := Condition(String{"Bob", 0})
|
||||
carl := Condition(String{"Carl", 0})
|
||||
alice := Condition(Name{"Alice", 0})
|
||||
bob := Condition(Name{"Bob", 0})
|
||||
carl := Condition(Name{"Carl", 0})
|
||||
|
||||
query1 := Raw{
|
||||
NodeType: NodeAnd,
|
||||
|
||||
Reference in New Issue
Block a user