php / php/php-src

openssl_sign() cannot sign a precomputed digest

Open
#23,422 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: openssl Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

Description

openssl_sign() currently always performs the digest operation internally before signing the data.

This causes a problem when the input is already a precomputed digest.

For example, when a SHA-256 digest is passed to openssl_sign() together with OPENSSL_ALGO_SHA256, the digest is hashed again:

signature = sign(SHA256(precomputed_sha256_digest))

instead of signing the existing digest directly:

signature = sign(precomputed_sha256_digest)

As a result, PHP currently has no straightforward way to sign an already computed digest using ext/openssl.

Expected behavior

It should be possible to pass a precomputed digest to the OpenSSL extension and sign it directly without applying another hashing operation.

The same should be possible for verification of a signature over a precomputed digest.

Actual behavior

openssl_sign() combines hashing and signing. Therefore, when the caller already has the digest, an additional hashing operation is performed.

Additional information

OpenSSL provides lower-level APIs such as EVP_PKEY_sign() and EVP_PKEY_verify() that can operate on already prepared input.

PHP's OpenSSL extension currently does not expose an equivalent way to perform this operation.

PHP Version
PHP 8.5
Operating System

all

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the openssl_sign() entry point in PHP's ext/openssl and compare its current digesting behavior with the mentioned EVP_PKEY_sign() and EVP_PKEY_verify() APIs. Determine an interface for precomputed input that covers both signing and verification; done means callers can sign and verify an existing digest without hashing it again.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, cryptography, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.