aboutsummaryrefslogtreecommitdiff
path: root/keys.go
blob: d96d99980d05f7290e9262105a7a7c65508857ed (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
package main

import (
	"bytes"
	"crypto/sha512"

	"github.com/agl/ed25519"
)

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

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

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

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