@@ -4481,6 +4481,54 @@ std::optional<EVP_PKEY_CTX*> EVPMDCtxPointer::verifyInit(
4481
4481
return ctx;
4482
4482
}
4483
4483
4484
+ std::optional<EVP_PKEY_CTX*> EVPMDCtxPointer::signInitWithContext (
4485
+ const EVPKeyPointer& key,
4486
+ const Digest& digest,
4487
+ const Buffer<const unsigned char >& context_string) {
4488
+ #ifdef OSSL_SIGNATURE_PARAM_CONTEXT_STRING
4489
+ EVP_PKEY_CTX* ctx = nullptr ;
4490
+
4491
+ const OSSL_PARAM params[] = {
4492
+ OSSL_PARAM_construct_octet_string (
4493
+ OSSL_SIGNATURE_PARAM_CONTEXT_STRING,
4494
+ const_cast <unsigned char *>(context_string.data ),
4495
+ context_string.len ),
4496
+ OSSL_PARAM_END};
4497
+
4498
+ if (!EVP_DigestSignInit_ex (
4499
+ ctx_.get (), &ctx, nullptr , nullptr , nullptr , key.get (), params)) {
4500
+ return std::nullopt ;
4501
+ }
4502
+ return ctx;
4503
+ #else
4504
+ return std::nullopt ;
4505
+ #endif
4506
+ }
4507
+
4508
+ std::optional<EVP_PKEY_CTX*> EVPMDCtxPointer::verifyInitWithContext (
4509
+ const EVPKeyPointer& key,
4510
+ const Digest& digest,
4511
+ const Buffer<const unsigned char >& context_string) {
4512
+ #ifdef OSSL_SIGNATURE_PARAM_CONTEXT_STRING
4513
+ EVP_PKEY_CTX* ctx = nullptr ;
4514
+
4515
+ const OSSL_PARAM params[] = {
4516
+ OSSL_PARAM_construct_octet_string (
4517
+ OSSL_SIGNATURE_PARAM_CONTEXT_STRING,
4518
+ const_cast <unsigned char *>(context_string.data ),
4519
+ context_string.len ),
4520
+ OSSL_PARAM_END};
4521
+
4522
+ if (!EVP_DigestVerifyInit_ex (
4523
+ ctx_.get (), &ctx, nullptr , nullptr , nullptr , key.get (), params)) {
4524
+ return std::nullopt ;
4525
+ }
4526
+ return ctx;
4527
+ #else
4528
+ return std::nullopt ;
4529
+ #endif
4530
+ }
4531
+
4484
4532
DataPointer EVPMDCtxPointer::signOneShot (
4485
4533
const Buffer<const unsigned char >& buf) const {
4486
4534
if (!ctx_) return {};
0 commit comments