Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics: Don't allocate when invoking the Inc() fastpath #4193

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crypto/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))
}