Don't allow duplicate x parts in Shamir. Add unit test for verification.
This commit is contained in:
parent
9db8a5c744
commit
ec57e983f7
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue