all: generate discovery key, plumb it around

Not actually used yet.

Updates #483
This commit is contained in:
Brad Fitzpatrick
2020-06-19 12:06:49 -07:00
parent 88c305c8af
commit 53fb25fc2f
8 changed files with 45 additions and 0 deletions

View File

@@ -6,9 +6,11 @@
package key
import (
crand "crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
"go4.org/mem"
"golang.org/x/crypto/curve25519"
@@ -20,6 +22,15 @@ type Private [32]byte
// Private reports whether p is the zero value.
func (p Private) IsZero() bool { return p == Private{} }
// NewPrivate returns a new private key.
func NewPrivate() Private {
var p Private
if _, err := io.ReadFull(crand.Reader, p[:]); err != nil {
panic(err)
}
return p
}
// B32 returns k as the *[32]byte type that's used by the
// golang.org/x/crypto packages. This allocates; it might
// not be appropriate for performance-sensitive paths.