Skip to content

Commit

Permalink
Simplify crypto implementation interface
Browse files Browse the repository at this point in the history
Remove the "key-value store"-like methods for public key management.
If the crypto implementation needs to store public key information,
it should manage the public keys out-of-band.

Signed-off-by: Matej Pavlovic <matopavlovic@gmail.com>
  • Loading branch information
matejpavlovic committed Jun 16, 2022
1 parent 249b7cd commit 9e6bde8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
20 changes: 0 additions & 20 deletions pkg/crypto/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ type Impl interface {
// Storing and using the private key is completely implementation-dependent.
Sign(data [][]byte) ([]byte, error)

// RegisterNodeKey associates a public key with a numeric node ID.
// The representation of the key is implementation-dependent.
// Calls to VerifyNodeSig will fail until RegisterNodeKey is successfully called with the corresponding node ID.
// Returns nil on success, a non-nil error on failure.
RegisterNodeKey(pubKey []byte, nodeID t.NodeID) error

// RegisterClientKey associates a public key with a numeric client ID.
// The representation of the key is implementation-dependent.
// Calls to VerifyClientSig will fail until RegisterClientKey is successfully called with the corresponding client ID.
// Returns nil on success, a non-nil error on failure.
RegisterClientKey(pubKey []byte, clientID t.ClientID) error

// DeleteNodeKey removes the public key associated with nodeID from the module's state.
// Any subsequent call to VerifyNodeSig(..., nodeID) will fail.
DeleteNodeKey(nodeID t.NodeID)

// DeleteClientKey removes the public key associated with clientID from the module's state.
// Any subsequent call to VerifyClientSig(..., clientID) will fail.
DeleteClientKey(clientID t.ClientID)

// VerifyNodeSig verifies a signature produced by the node with numeric ID nodeID over data.
// Returns nil on success (i.e., if the given signature is valid) and a non-nil error otherwise.
// Note that RegisterNodeKey must be used to register the node's public key before calling VerifyNodeSig,
Expand Down
6 changes: 3 additions & 3 deletions pkg/crypto/pseudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NodePseudo(nodes []t.NodeID, clients []t.ClientID, ownID t.NodeID, seed int
}

// Look up the own private key and create a CryptoImpl module instance that would sign with this key.
var c Impl
var c *DefaultImpl
for i, id := range nodes {
if id == ownID {
if c, err = NewDefaultImpl(nodePrivKeys[i]); err != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func ClientPseudo(nodes []t.NodeID, clients []t.ClientID, ownID t.ClientID, seed
}

// Look up the own private key and create a CryptoImpl module instance that would sign with this key.
var c Impl
var c *DefaultImpl
for i, id := range clients {
if id == ownID {
if c, err = NewDefaultImpl(clientPrivKeys[i]); err != nil {
Expand Down Expand Up @@ -149,7 +149,7 @@ func generateKeys(numKeys int, randomness io.Reader) (privKeys [][]byte, pubKeys
// nodes and nodePubKeys must have the same length.
// The analogous happens for client keys, using c.RegisterClientKey.
func registerPubKeys(
c Impl,
c *DefaultImpl,
nodes []t.NodeID,
nodePubKeys [][]byte,
clients []t.ClientID,
Expand Down

0 comments on commit 9e6bde8

Please sign in to comment.