Skip to content

Commit ca5f265

Browse files
committed
feat: export GalMulSlice and GalMulSliceXor
1 parent edb0e62 commit ca5f265

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

mulslice.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package reedsolomon
2+
3+
import "cmp"
4+
5+
// LowLevel exposes low level functionality.
6+
type LowLevel struct {
7+
o *options
8+
}
9+
10+
// WithOptions resets the options to the default+provided options.
11+
// Options that don't apply to the called functions will be ignored.
12+
// This should not be called concurrent with other calls.
13+
func (l *LowLevel) WithOptions(opts ...Option) {
14+
o := defaultOptions
15+
for _, opt := range opts {
16+
opt(&o)
17+
}
18+
}
19+
20+
func (l LowLevel) options() *options {
21+
return cmp.Or(l.o, &defaultOptions)
22+
}
23+
24+
// GalMulSlice multiplies the elements of in by c, writing the result to out: out[i] = c * in[i].
25+
// out must be at least as long as in.
26+
func (l LowLevel) GalMulSlice(c byte, in, out []byte) {
27+
galMulSlice(c, in, out, l.options())
28+
}
29+
30+
// GalMulSliceXor multiplies the elements of in by c, and adds the result to out: out[i] ^= c * in[i].
31+
// out must be at least as long as in.
32+
func (l LowLevel) GalMulSliceXor(c byte, in, out []byte) {
33+
galMulSliceXor(c, in, out, l.options())
34+
}
35+
36+
// Inv returns the multiplicative inverse of e in GF(2^8).
37+
// Should not be called with 0 (returns 0 in this case).
38+
func Inv(e byte) byte {
39+
return invTable[e]
40+
}

0 commit comments

Comments
 (0)