Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Jun 20, 2023
1 parent 8feb1c0 commit 3e60b1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
13 changes: 11 additions & 2 deletions signer/cosigner_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ type CosignerSecurity interface {
GetID() int

// EncryptAndSign encrypts the nonce and signs it for authentication.
EncryptAndSign(id int, noncePub []byte, nonceShare []byte) (CosignerNonce, error)
EncryptAndSign(
id int,
noncePub []byte,
nonceShare []byte,
) (CosignerNonce, error)

// DecryptAndVerify decrypts the nonce and verifies the signature to authenticate the source cosigner.
DecryptAndVerify(id int, encryptedNoncePub []byte, encryptedNonceShare []byte, signature []byte) ([]byte, []byte, error)
DecryptAndVerify(
id int,
encryptedNoncePub []byte,
encryptedNonceShare []byte,
signature []byte,
) ([]byte, []byte, error)
}
22 changes: 18 additions & 4 deletions signer/cosigner_security_ecies.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

var _ CosignerSecurity = &CosignerSecurityECIES{}

// CosignerSecurityECIES is an implementation of CosignerSecurity using ECIES for encryption and ECDSA for digital signature.
// CosignerSecurityECIES is an implementation of CosignerSecurity
// using ECIES for encryption and ECDSA for digital signature.
type CosignerSecurityECIES struct {
key CosignerECIESKey
eciesPubKeys map[int]CosignerECIESPubKey
Expand Down Expand Up @@ -81,7 +82,14 @@ func (c *CosignerSecurityECIES) EncryptAndSign(id int, noncePub []byte, nonceSha
}

hash := sha256.Sum256(jsonBytes)
signature, err := ecdsa.SignASN1(rand.Reader, &ecdsa.PrivateKey{PublicKey: ecdsa.PublicKey(*c.key.ECIESKey.PublicKey), D: c.key.ECIESKey.D}, hash[:])
signature, err := ecdsa.SignASN1(
rand.Reader,
&ecdsa.PrivateKey{
PublicKey: ecdsa.PublicKey(*c.key.ECIESKey.PublicKey),
D: c.key.ECIESKey.D,
},
hash[:],
)
if err != nil {
return nonce, err
}
Expand All @@ -92,8 +100,14 @@ func (c *CosignerSecurityECIES) EncryptAndSign(id int, noncePub []byte, nonceSha
return nonce, nil
}

// DecryptAndVerify decrypts the nonce and verifies the signature to authenticate the source cosigner.
func (c *CosignerSecurityECIES) DecryptAndVerify(id int, encryptedNoncePub []byte, encryptedNonceShare []byte, signature []byte) ([]byte, []byte, error) {
// DecryptAndVerify decrypts the nonce and verifies
// the signature to authenticate the source cosigner.
func (c *CosignerSecurityECIES) DecryptAndVerify(
id int,
encryptedNoncePub []byte,
encryptedNonceShare []byte,
signature []byte,
) ([]byte, []byte, error) {
digestMsg := CosignerNonce{
SourceID: id,
SourcePubKey: encryptedNoncePub,
Expand Down
10 changes: 8 additions & 2 deletions signer/cosigner_security_rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ func (c *CosignerSecurityRSA) EncryptAndSign(id int, noncePub []byte, nonceShare
return nonce, nil
}

// DecryptAndVerify decrypts the nonce and verifies the signature to authenticate the source cosigner.
func (c *CosignerSecurityRSA) DecryptAndVerify(id int, encryptedNoncePub []byte, encryptedNonceShare []byte, signature []byte) ([]byte, []byte, error) {
// DecryptAndVerify decrypts the nonce and verifies
// the signature to authenticate the source cosigner.
func (c *CosignerSecurityRSA) DecryptAndVerify(
id int,
encryptedNoncePub []byte,
encryptedNonceShare []byte,
signature []byte,
) ([]byte, []byte, error) {
digestMsg := CosignerNonce{
SourceID: id,
SourcePubKey: encryptedNoncePub,
Expand Down
5 changes: 3 additions & 2 deletions signer/local_cosigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (cosigner *LocalCosigner) GetNonces(

var eg errgroup.Group

for i := 1; i <= int(total); i++ {
for i := 1; i <= total; i++ {
if i == id {
continue
}
Expand Down Expand Up @@ -479,7 +479,8 @@ func (cosigner *LocalCosigner) setNonce(req CosignerSetNonceRequest) error {
return errors.New("SourceSig field is required")
}

noncePub, nonceShare, err := cosigner.security.DecryptAndVerify(req.SourceID, req.SourcePubKey, req.EncryptedSharePart, req.SourceSig)
noncePub, nonceShare, err := cosigner.security.DecryptAndVerify(
req.SourceID, req.SourcePubKey, req.EncryptedSharePart, req.SourceSig)
if err != nil {
return err
}
Expand Down

0 comments on commit 3e60b1c

Please sign in to comment.