Skip to content

Commit 3fe9bb1

Browse files
authored
Possible Fix: Issue #60263 (Crypto cant sign/verify prehashed inputs)
1 parent 77d8197 commit 3fe9bb1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

deps/ncrypto/ncrypto.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,18 +4298,46 @@ bool EVPMDCtxPointer::copyTo(const EVPMDCtxPointer& other) const {
42984298
std::optional<EVP_PKEY_CTX*> EVPMDCtxPointer::signInit(const EVPKeyPointer& key,
42994299
const Digest& digest) {
43004300
EVP_PKEY_CTX* ctx = nullptr;
4301+
4302+
if (digest == nullptr) {
4303+
// Inicializa sin digest (firma raw, sin hashing interno)
4304+
ctx = EVP_PKEY_CTX_new(key.get(), nullptr);
4305+
if (!ctx) return std::nullopt;
4306+
if (EVP_PKEY_sign_init(ctx) <= 0) {
4307+
EVP_PKEY_CTX_free(ctx);
4308+
return std::nullopt;
4309+
}
4310+
ctx_.reset(ctx);
4311+
return ctx;
4312+
}
4313+
43014314
if (!EVP_DigestSignInit(ctx_.get(), &ctx, digest, nullptr, key.get())) {
43024315
return std::nullopt;
43034316
}
4317+
43044318
return ctx;
43054319
}
43064320

43074321
std::optional<EVP_PKEY_CTX*> EVPMDCtxPointer::verifyInit(
43084322
const EVPKeyPointer& key, const Digest& digest) {
43094323
EVP_PKEY_CTX* ctx = nullptr;
4324+
4325+
if (digest == nullptr) {
4326+
// Inicializa sin digest (verificación raw, sin hashing interno)
4327+
ctx = EVP_PKEY_CTX_new(key.get(), nullptr);
4328+
if (!ctx) return std::nullopt;
4329+
if (EVP_PKEY_verify_init(ctx) <= 0) {
4330+
EVP_PKEY_CTX_free(ctx);
4331+
return std::nullopt;
4332+
}
4333+
ctx_.reset(ctx);
4334+
return ctx;
4335+
}
4336+
43104337
if (!EVP_DigestVerifyInit(ctx_.get(), &ctx, digest, nullptr, key.get())) {
43114338
return std::nullopt;
43124339
}
4340+
43134341
return ctx;
43144342
}
43154343

0 commit comments

Comments
 (0)