Skip to content

Commit

Permalink
Don't allocate when invoking the Inc() fastpath (algorand#4193)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti authored Jun 28, 2022
1 parent 622399c commit 30618c0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions curve25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ func SecretKeyToSeed(secret PrivateKey) (Seed, error) {
func GenerateSignatureSecrets(seed Seed) *SignatureSecrets {
pk0, sk := ed25519GenerateKeySeed(ed25519Seed(seed))
pk := SignatureVerifier(pk0)
cryptoGenSigSecretsTotal.Inc(map[string]string{})
cryptoGenSigSecretsTotal.Inc(nil)
return &SignatureSecrets{SignatureVerifier: pk, SK: sk}
}

// Sign produces a cryptographic Signature of a Hashable message, given
// cryptographic secrets.
func (s *SignatureSecrets) Sign(message Hashable) Signature {
cryptoSigSecretsSignTotal.Inc(map[string]string{})
cryptoSigSecretsSignTotal.Inc(nil)
return s.SignBytes(HashRep(message))
}

// SignBytes signs a message directly, without first hashing.
// Caller is responsible for domain separation.
func (s *SignatureSecrets) SignBytes(message []byte) Signature {
cryptoSigSecretsSignBytesTotal.Inc(map[string]string{})
cryptoSigSecretsSignBytesTotal.Inc(nil)
return Signature(ed25519Sign(ed25519PrivateKey(s.SK), message))
}

Expand All @@ -212,14 +212,14 @@ func (s *SignatureSecrets) SignBytes(message []byte) Signature {
// It returns true if this is the case; otherwise, it returns false.
//
func (v SignatureVerifier) Verify(message Hashable, sig Signature) bool {
cryptoSigSecretsVerifyTotal.Inc(map[string]string{})
cryptoSigSecretsVerifyTotal.Inc(nil)
return ed25519Verify(ed25519PublicKey(v), HashRep(message), ed25519Signature(sig))
}

// VerifyBytes verifies a signature, where the message is not hashed first.
// Caller is responsible for domain separation.
// If the message is a Hashable, Verify() can be used instead.
func (v SignatureVerifier) VerifyBytes(message []byte, sig Signature) bool {
cryptoSigSecretsVerifyBytesTotal.Inc(map[string]string{})
cryptoSigSecretsVerifyBytesTotal.Inc(nil)
return ed25519Verify(ed25519PublicKey(v), message, ed25519Signature(sig))
}

0 comments on commit 30618c0

Please sign in to comment.