From 9d8576d397df800ac7593cb12db17d72b5c4440a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 28 Sep 2020 16:20:44 +0300 Subject: [PATCH] [#53] util: Add SaltXOR function Signed-off-by: Leonard Lyubich --- pkg/util/salt.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pkg/util/salt.go diff --git a/pkg/util/salt.go b/pkg/util/salt.go new file mode 100644 index 0000000000..26a3fe3a4e --- /dev/null +++ b/pkg/util/salt.go @@ -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 +}