SHAKE: the outlen of EVP_DigestFinalXOF() stays on the context as "xoflen" for the next operation
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 56/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c
- 領域
- cryptography
調査の方向性
Start with EVP_DigestFinalXOF() in crypto/evp/digest.c and SHAKE re-initialisation in providers/implementations/digests/sha3_prov.c; read the XOF parameter handling and reproduce the reported cases in the linked gist. Check how the context behaves after re-initialisation when xoflen was implicit or explicitly set, and verify that a new operation no longer inherits the prior call's output length.
索引モデルが issue の本文から書いたものです。
説明
Summary
EVP_DigestFinalXOF(ctx, md, outlen) first stores outlen on the context as the xoflen parameter (crypto/evp/digest.c, "For backward compatibility we pass the XOFLEN via a param here ...") and never restores it. SHAKE's re-initialisation (keccak_init_params() in providers/implementations/digests/sha3_prov.c, used when EVP_DigestInit_ex2(ctx, NULL, NULL) or the same digest re-uses the provider context) does not reset md_size either. So the length argument of one EVP_DigestFinalXOF() call becomes a setting of the next operation:
EVP_MD_CTX_get_size_ex()after re-initialisation returns the previous call'soutlen(40 in the test below); on a fresh context it returns -1. EVP_DigestInit(3) says that for an XOF it "returns the "xoflen" if it has been set, otherwise it returns 0".EVP_DigestFinal_ex()without anyxoflenset fails on a fresh SHAKE context, but succeeds after re-initialisation and writesoutlenbytes from the earlier call (with a 200-byte earlier call, 200 bytes are written).- If the caller did set
xoflen(e.g. 20) and then usedEVP_DigestFinalXOF(ctx, md, 40)once, the context reports and uses 40 afterwards, not 20.
EVP_DigestInit(3) allows starting a new operation with EVP_DigestInit_ex2() after EVP_DigestFinalXOF() without EVP_MD_CTX_reset(), and describes outlen as the amount of output for that call only. EVP_MD_CTX_reset() or re-initialising with a different digest avoids the problem, because the provider context is recreated.
Reproducer
Tested on master 354f1cf6 and 4.0.3, SHAKE256 (SHAKE128 behaves the same):
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
unsigned char out[256];
unsigned int len = 0;
EVP_DigestInit_ex2(ctx, EVP_shake256(), NULL);
EVP_DigestUpdate(ctx, "abc", 3);
EVP_DigestFinalXOF(ctx, out, 40); /* 1 */
EVP_DigestInit_ex2(ctx, NULL, NULL); /* 1: new operation */
printf("%d\n", EVP_MD_CTX_get_size_ex(ctx)); /* 40; fresh context: -1 */
EVP_DigestUpdate(ctx, "abc", 3);
printf("%d %u\n", EVP_DigestFinal_ex(ctx, out, &len), len); /* 1 40; fresh context: 0 */
shake_xof_reinit.c at https://gist.github.com/GeekQAQ/e8044659d9ad0822b7a848126d4c6f7a covers the variants above (xoflen set to 20 first; EVP_DigestInit_ex(ctx, NULL, NULL); re-init with the same EVP_MD).
Suggested fix
Restore the context's previous xoflen after the provider's final call in EVP_DigestFinalXOF() (reference patch reference.patch at https://gist.github.com/GeekQAQ/e8044659d9ad0822b7a848126d4c6f7a, for reference only). This removes all the effects above and keeps an xoflen that the caller set explicitly. With the patch make test passes.
A related question: whether an xoflen set explicitly with EVP_MD_CTX_set_params() should survive re-initialisation at all is not written down. Today it survives EVP_DigestInit_ex2(ctx, NULL, NULL) and re-initialisation with the same digest, but not re-initialisation with a different digest. The alternative fix, resetting md_size in keccak_init_params(), would also drop the explicit setting.
- 主要言語
- C
- スター
- 31.5k
- フォーク
- 11.6k
- 平均マージ
- 20分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openssl/openssl のほかの issue
-
issue: bug report
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 2 日以内に返信
-
SIGBUS in quic_memfail_test on OpenBSD/sparc64 with clang対応中かも @Sashan が 4 日前に担当しました。 オープンbranch: 4.1 branch: master triaged: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
openssl/openssl#33731 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Bug: buffer overrun in demos/sslecho/main.c対応中かも @prudhvirajkonda8-bot が 5 日前に担当しました。 オープンbranch: 3.5 branch: 4.0 branch: 4.1 branch: master help wanted triaged: bug
難易度 2/5 1時間未満 初心者へのやさしさ 74/100
メンテナーはふだん 2 日以内に返信
-
sk_TYPE_find*() on built-in stack types still requires a non-const STACK_OF対応中かも @bob-beck が 7 日前に担当しました。 オープンbranch: 4.0 branch: 4.1 branch: master triaged: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
openssl/openssl#33707 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
openssl/openssl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
phuslu/nginx-ssl-fingerprint#108 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
389ds/389-ds-base#8157 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
coolsnowwolf/lede#14305 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
SoftEtherVPN/SoftEtherVPN#2344 ·
メンテナーはふだん 1 日以内に返信