Skip to content
Snippets Groups Projects
Commit bc3f946a authored by David Stainton's avatar David Stainton
Browse files

Add constant time key comparison methods

parent c765b86b
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ package ctidh ...@@ -5,6 +5,7 @@ package ctidh
import "C" import "C"
import ( import (
"bytes" "bytes"
"crypto/hmac"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -137,6 +138,11 @@ func (p *PublicKey) FromBytes(data []byte) error { ...@@ -137,6 +138,11 @@ func (p *PublicKey) FromBytes(data []byte) error {
return nil return nil
} }
// Equal is a constant time comparison of the two public keys.
func (p *PublicKey) Equal(publicKey *PublicKey) bool {
return hmac.Equal(p.Bytes(), publicKey.Bytes())
}
// Blind performs a blinding operation // Blind performs a blinding operation
// and mutates the public key. // and mutates the public key.
// See notes below about blinding operation with CTIDH. // See notes below about blinding operation with CTIDH.
...@@ -196,6 +202,11 @@ func (p *PrivateKey) FromBytes(data []byte) error { ...@@ -196,6 +202,11 @@ func (p *PrivateKey) FromBytes(data []byte) error {
return nil return nil
} }
// Equal is a constant time comparison of the two private keys.
func (p *PrivateKey) Equal(privateKey *PrivateKey) bool {
return hmac.Equal(p.Bytes(), privateKey.Bytes())
}
// ToPEMFile writes out the PrivateKey to a PEM file at path f. // ToPEMFile writes out the PrivateKey to a PEM file at path f.
func (p *PrivateKey) ToPEMFile(f string) error { func (p *PrivateKey) ToPEMFile(f string) error {
keyType := Name() + " PRIVATE KEY" keyType := Name() + " PRIVATE KEY"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment