Skip to content

Commit

Permalink
don't change behavior of user-facing tools yet
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDoanRivian committed Nov 1, 2024
1 parent 0e5277e commit ef58b33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/nebula-cert/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func keygen(args []string, out io.Writer, errOut io.Writer) error {
pub, rawPriv = x25519Keypair()
curve = cert.Curve_CURVE25519
case "P256":
pub, rawPriv = p256Keypair()
pub, rawPriv = p256Keypair(false) //todo support generating compressed keys
curve = cert.Curve_P256
default:
return fmt.Errorf("invalid curve: %s", *cf.curve)
Expand Down
15 changes: 5 additions & 10 deletions cmd/nebula-cert/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func newKeypair(curve cert.Curve) ([]byte, []byte) {
case cert.Curve_CURVE25519:
return x25519Keypair()
case cert.Curve_P256:
return p256KeypairCompressed()
return p256Keypair(false) //todo support generating compressed keys
default:
return nil, nil
}
Expand All @@ -422,19 +422,14 @@ func x25519Keypair() ([]byte, []byte) {
return pubkey, privkey
}

func p256Keypair() ([]byte, []byte) {
func p256Keypair(compressed bool) ([]byte, []byte) {
privkey, err := ecdh.P256().GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
pubkey := privkey.PublicKey()
return pubkey.Bytes(), privkey.Bytes()
}

func p256KeypairCompressed() ([]byte, []byte) {
privkey, err := ecdh.P256().GenerateKey(rand.Reader)
if err != nil {
panic(err)
if !compressed {
pubkey := privkey.PublicKey()
return pubkey.Bytes(), privkey.Bytes()
}
pubkeyBytes := privkey.PublicKey().Bytes()
pubkey, err := noiseutil.LoadP256Pubkey(pubkeyBytes)
Expand Down

0 comments on commit ef58b33

Please sign in to comment.