mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 12:07:54 +00:00
Don't allow duplicate x parts in Shamir. Add unit test for verification.
This commit is contained in:
@@ -194,9 +194,16 @@ func Combine(parts [][]byte) ([]byte, error) {
|
|||||||
x_samples := make([]uint8, len(parts))
|
x_samples := make([]uint8, len(parts))
|
||||||
y_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 {
|
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
|
// Reconstruct each byte
|
||||||
|
|||||||
@@ -71,6 +71,14 @@ func TestCombine_invalid(t *testing.T) {
|
|||||||
if _, err := Combine(parts); err == nil {
|
if _, err := Combine(parts); err == nil {
|
||||||
t.Fatalf("should err")
|
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) {
|
func TestCombine(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user