From 052a8d9fe07d59ea96ca7a0a035be1e31bffcce3 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 7 Aug 2023 21:17:22 +0000 Subject: [PATCH] remove xor from wire mixvec type; mixing type will implement this --- wire/mixvec.go | 50 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) diff --git a/wire/mixvec.go b/wire/mixvec.go index a1edd68fce..ca14fe2cc3 100644 --- a/wire/mixvec.go +++ b/wire/mixvec.go @@ -26,23 +26,12 @@ func NewMixVec(n, msize uint32) *MixVec { } } -// IsDim returns whether the Vec has dimensions n-by-msize. -func (v *MixVec) IsDim(n, msize uint32) bool { - return v.N == n && v.Msize == msize && len(v.Data) == int(n*msize) -} - -// Equals returns whether the two vectors have equal dimensions and data. -func (v *MixVec) Equals(other *MixVec) bool { - return other.IsDim(v.N, v.Msize) && bytes.Equal(other.Data, v.Data) -} - -// M returns the i'th message of the vector. -func (v *MixVec) M(i int) []byte { - off := uint32(i) * v.Msize - return v.Data[off : off+v.Msize] -} - func (v *MixVec) String() string { + m := func(i int) []byte { + off := uint32(i) * v.Msize + return v.Data[off : off+v.Msize] + } + b := new(strings.Builder) b.Grow(2 + int(v.N*(2*v.Msize+1))) b.WriteString("[") @@ -50,35 +39,8 @@ func (v *MixVec) String() string { if i != 0 { b.WriteString(" ") } - fmt.Fprintf(b, "%x", v.M(i)) + fmt.Fprintf(b, "%x", m(i)) } b.WriteString("]") return b.String() } - -// Xor writes the xor of each vector element of src1 and src2 into v. -// Source and destination vectors are allowed to be equal. -// Panics if vectors do not share identical dimensions. -func (v *MixVec) Xor(src1, src2 *MixVec) { - switch { - case v.N != src1.N, v.Msize != src1.Msize, len(v.Data) != len(src1.Data): - fallthrough - case v.N != src2.N, v.Msize != src2.Msize, len(v.Data) != len(src2.Data): - panic("dcnet: vectors do not share identical dimensions") - } - for i := range v.Data { - v.Data[i] = src1.Data[i] ^ src2.Data[i] - } -} - -// XorVectors calculates the xor of all vectors. -// Panics if vectors do not share identical dimensions. -func XorVectors(vs ...MixVec) MixVec { - n := uint32(len(vs)) - msize := vs[0].Msize - res := NewMixVec(n, msize) - for i := range vs { - res.Xor(res, &vs[i]) - } - return *res -}