Skip to content

Commit

Permalink
Set public key from private key in DNSKEY instead of copying it from …
Browse files Browse the repository at this point in the history
…DNSKEY to private key

Previously when loading a PrivateKey into a DNSKEY we would return the PrivateKey with the PublicKey set from the DNSKEY struct.
Now that behaviour is flipped and the PublicKey is taken from the PrivateKey and set in the DNSKEY.
  • Loading branch information
Martin Frausing committed Apr 26, 2024
1 parent e4ef594 commit afda3af
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions dnssec_keyscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rsa"
"io"
"math/big"
Expand Down Expand Up @@ -48,22 +49,21 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
if err != nil {
return nil, err
}
pub := k.publicKeyRSA()
if pub == nil {
return nil, ErrKey
}
priv.PublicKey = *pub
k.setPublicKeyRSA(priv.PublicKey.E, priv.PublicKey.N)
return priv, nil
case ECDSAP256SHA256, ECDSAP384SHA384:
priv, err := readPrivateKeyECDSA(m)
if err != nil {
return nil, err
}
pub := k.publicKeyECDSA()
if pub == nil {
return nil, ErrKey
switch uint8(algo) {
case ECDSAP256SHA256:
priv.PublicKey.Curve = elliptic.P256()
case ECDSAP384SHA384:
priv.PublicKey.Curve = elliptic.P384()
}
priv.PublicKey = *pub
priv.PublicKey.X, priv.PublicKey.Y = priv.PublicKey.Curve.ScalarBaseMult(priv.D.Bytes())
k.setPublicKeyECDSA(priv.PublicKey.X, priv.PublicKey.Y)
return priv, nil
case ED25519:
return readPrivateKeyED25519(m)
Expand Down

0 comments on commit afda3af

Please sign in to comment.