Skip to content

Commit

Permalink
fixup! crypto: add optional callback to crypto.sign and crypto.verify
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 10, 2021
1 parent 5673dcb commit 8176164
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/crypto/crypto_sig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,15 @@ bool IsOneShot(const ManagedEVPPKey& key) {
}
}

bool UseP1363Encoding(const SignConfiguration& params) {
switch (EVP_PKEY_id(params.key->GetAsymmetricKey().get())) {
bool UseP1363Encoding(const ManagedEVPPKey& key,
const DSASigEnc& dsa_encoding) {
switch (EVP_PKEY_id(key.get())) {
case EVP_PKEY_EC:
case EVP_PKEY_DSA: return params.dsa_encoding == kSigEncP1363;
case EVP_PKEY_DSA:
return dsa_encoding == kSigEncP1363;
default:
return false;
}
return false;
}
} // namespace

Expand Down Expand Up @@ -775,7 +778,7 @@ Maybe<bool> SignTraits::AdditionalConfig(
// the signature from WebCrypto format into DER format...
ManagedEVPPKey m_pkey = params->key->GetAsymmetricKey();
Mutex::ScopedLock lock(*m_pkey.mutex());
if (UseP1363Encoding(*params)) {
if (UseP1363Encoding(m_pkey, params->dsa_encoding)) {
params->signature =
ConvertFromWebCryptoSignature(m_pkey, signature.ToByteSource());
} else {
Expand Down Expand Up @@ -872,7 +875,7 @@ bool SignTraits::DeriveBits(
if (!EVP_DigestSignFinal(context.get(), data, &len))
return false;

if (UseP1363Encoding(params)) {
if (UseP1363Encoding(m_pkey, params.dsa_encoding)) {
*out = ConvertToWebCryptoSignature(
params.key->GetAsymmetricKey(), buf);
} else {
Expand Down

0 comments on commit 8176164

Please sign in to comment.