forked from TrueCloudLab/frostfs-node
[#53] util: Add SaltXOR function
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
834a8597c5
commit
9d8576d397
1 changed files with 17 additions and 0 deletions
17
pkg/util/salt.go
Normal file
17
pkg/util/salt.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
// SaltXOR xors bits of data with salt
|
||||||
|
// repeating salt if necessary.
|
||||||
|
func SaltXOR(data, salt []byte) (result []byte) {
|
||||||
|
result = make([]byte, len(data))
|
||||||
|
ls := len(salt)
|
||||||
|
if ls == 0 {
|
||||||
|
copy(result, data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range result {
|
||||||
|
result[i] = data[i] ^ salt[i%ls]
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in a new issue