Don't allow duplicate x parts in Shamir. Add unit test for verification.

This commit is contained in:
Jeff Mitchell 2015-08-26 10:03:44 -07:00
parent 9db8a5c744
commit ec57e983f7
2 changed files with 17 additions and 2 deletions

View File

@ -194,9 +194,16 @@ func Combine(parts [][]byte) ([]byte, error) {
x_samples := make([]uint8, len(parts))
y_samples := make([]uint8, len(parts))
// Set the x value for each sample
// Set the x value for each sample and ensure no x_sample values are the same,
// otherwise div() can be unhappy
checkMap := map[byte]bool{}
for i, part := range parts {
x_samples[i] = part[firstPartLen-1]
samp := part[firstPartLen-1]
if exists := checkMap[samp]; exists {
return nil, fmt.Errorf("duplicte part detected")
}
checkMap[samp] = true
x_samples[i] = samp
}
// Reconstruct each byte

View File

@ -71,6 +71,14 @@ func TestCombine_invalid(t *testing.T) {
if _, err := Combine(parts); err == nil {
t.Fatalf("should err")
}
parts = [][]byte{
[]byte("foo"),
[]byte("foo"),
}
if _, err := Combine(parts); err == nil {
t.Fatalf("should err")
}
}
func TestCombine(t *testing.T) {