php / php/php-src

AES SIV cipher algorithms implemented incorrectly in openssl module

Aperta
#20,851 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@bukka ci sta già lavorando.

Dal 6/1/2026.

Bug Extension: openssl Status: Needs Triage
Lingua principale
C
Stelle
40.4k
Fork
8.2k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.