package crypto import ( "encoding/binary" "crypto/sha256" ) func buildOneTimeKey(secretKey [32]byte, counter uint32) [32]byte { buf := make([]byte, 36) copy(buf[0:], secretKey[:]) binary.BigEndian.PutUint32(buf[32:], counter) return sha256.Sum256(buf) } func xor32(input [32]byte, key [32]byte) [32]byte { var out [32]byte for i := 0; i < 32; i++ { out[i] = input[i] ^ key[i] } return out } func XorWithOneTimeKey(ciphertext [32]byte, secretKey [32]byte, counter uint32) [32]byte { ephemeralKey := buildOneTimeKey(secretKey, counter) return xor32(ciphertext, ephemeralKey) } func Sha256(data []byte) [32]byte { return sha256.Sum256(data) }