php / php/php-src

AES SIV cipher algorithms implemented incorrectly in openssl module

オープン
#20,851 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@bukka がすでに取り組んでいます。

2026年1月6日 から。

Bug Extension: openssl Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code:

<?php
$algo = 'aes-256-siv';
echo 'Cipher ' . $algo . ' supported: '
    . in_array($algo, openssl_get_cipher_methods()) . PHP_EOL
    . 'Key len: ' . openssl_cipher_key_length($algo) . PHP_EOL
    . 'IV len: ' . openssl_cipher_iv_length($algo) . PHP_EOL;

$key = str_repeat('1', 64);
$enc = openssl_encrypt('Hello world!', $algo, $key, OPENSSL_RAW_DATA);
echo 'ciphertext: ' . bin2hex($enc) . PHP_EOL;

$dec = openssl_decrypt($enc, $algo, $key, OPENSSL_RAW_DATA);
echo 'decrypted: ' . var_export($dec, true) . PHP_EOL;

Resulted in this output:

Cipher aes-256-siv supported: 1
Key len: 64
IV len: 0
ciphertext: 72fffba74d7bc3ddcceeb6d1
decrypted: false

But I expected this output instead:

Cipher aes-256-siv supported: 1
Key len: 64
IV len: 0
ciphertext: c06f0df087e2784c5560ce5d0b37831172fffba74d7bc3ddcceeb6d1
decrypted: 'Hello world!'

Explanation:

AES in SIV mode generates IV on its own (hence name SIV -> Synthetic Initialization Vector). But output of openssl_encrypt contains only actual ciphertext (correct, however) without IV. And this ruins decryption, because without IV it's not possible to decrypt.

I wrote similar java code, that encryts "Hello world!" with aes-256-siv and got result "c06f0df087e2784c5560ce5d0b37831172fffba74d7bc3ddcceeb6d1". This string contains IV and ciphertext concatenated together: IV c06f0df087e2784c5560ce5d0b378311, ciphertext 72fffba74d7bc3ddcceeb6d1.

I hoped that I could at least consume encrypted data from java. But passing IV to openssl_decrypt emits warning: PHP Warning: openssl_decrypt(): IV passed is 16 bytes long which is longer than the 0 expected by selected cipher, truncating in /home/onyn/siv.php on line 18. Well, no miracle happened. Also passing IV with ciphertext together not worked.

This bug affects all reported by openssl_get_cipher_methods variants: aes-128-siv, aes-192-siv and aes-256-siv.

Also note, that AES SIV is an AEAD cipher, so $aad argument must be respected. But in my tests it was silently ignored.

PHP Version
PHP 8.5.1 (cli) (built: Dec 18 2025 23:39:41) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies
Operating System

Ubuntu 24.04

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。