aboutsummaryrefslogtreecommitdiff
path: root/enc.go
blob: 467e0f097373d769235fb1ae2fc9fd325fb93082 (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
package main

import (
	"bytes"
	"crypto/sha512"

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

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[:])
}

func (v *EncKey) Unmarshal(b []byte) error { return DecodeBase64(v, b) }
func (v *EncKey) Marshal() ([]byte, error) { return EncodeBase64(v) }