aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/crypto.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@mullvad.net>2021-12-20 14:37:43 +0100
committerRasmus Dahlberg <rasmus@mullvad.net>2021-12-20 18:23:48 +0100
commit7e0f0f84eac2e37edfd177196ed65afa0559f967 (patch)
tree98f4825366814764be58c204373162db4748be9d /pkg/types/crypto.go
parentd62b75e067b0fadd5e1066e3b3522959203e0341 (diff)
types: Add types and tests
Diffstat (limited to 'pkg/types/crypto.go')
-rw-r--r--pkg/types/crypto.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/types/crypto.go b/pkg/types/crypto.go
new file mode 100644
index 0000000..72152bf
--- /dev/null
+++ b/pkg/types/crypto.go
@@ -0,0 +1,30 @@
+package types
+
+import (
+ "crypto/ed25519"
+ "crypto/sha256"
+)
+
+const (
+ HashSize = sha256.Size
+ SignatureSize = ed25519.SignatureSize
+ PublicKeySize = ed25519.PublicKeySize
+
+ InteriorNodePrefix = byte(0x00)
+ LeafNodePrefix = byte(0x01)
+)
+
+type (
+ Hash [HashSize]byte
+ Signature [SignatureSize]byte
+ PublicKey [PublicKeySize]byte
+)
+
+func HashFn(buf []byte) *Hash {
+ var hash Hash = sha256.Sum256(buf)
+ return &hash
+}
+
+func LeafHash(buf []byte) *Hash {
+ return HashFn(append([]byte{LeafNodePrefix}, buf...))
+}