php / php/php-src

openssl_sign() cannot sign a precomputed digest

未关闭
#23,422 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: openssl Status: Verified
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 PHP 的 ext/openssl 中的 openssl_sign() 入口点开始,将其当前的摘要处理行为与提到的 EVP_PKEY_sign() 和 EVP_PKEY_verify() API 进行比较。确定一个适用于预计算输入的接口,同时涵盖签名和验证;完成的标准是调用方可以在不再次对现有摘要进行哈希的情况下对其进行签名和验证。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
backend, cryptography, security
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。