aboutsummaryrefslogtreecommitdiff
path: root/keys.go
blob: 0fcfee9d73363e306ceaa17e4b2b0f541c0a7620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"bytes"
	"crypto/sha512"

	"golang.org/x/crypto/ed25519"
)

var (
	PKAlg  = [2]byte{'E', 'd'}
	KDFAlg = [2]byte{'B', 'K'}
)

type Sig struct {
	PKAlg  [2]byte
	KeyNum [8]byte
	Sig    [ed25519.SignatureSize]byte
}

type PubKey struct {
	PKAlg  [2]byte
	KeyNum [8]byte
	PubKey [ed25519.PublicKeySize]byte
}

type EncKey struct {
	PKAlg     [2]byte
	KDFAlg    [2]byte
	KDFRounds uint32
	Salt      [16]byte
	Checksum  [8]byte
	KeyNum    [8]byte
	SecKey    [ed25519.PrivateKeySize]byte
}

func xor(text, key []byte) {
	if len(text) != len(key) {
		return
	}
	for i := 0; i < len(text); i++ {
		text[i] ^= key[i]
	}
}

func (v *EncKey) IsValid() bool {
	sum := sha512.Sum512(v.SecKey[:])
	return bytes.Equal(sum[:8], v.Checksum[:])
}