php / php/php-src

AES SIV cipher algorithms implemented incorrectly in openssl module

Abierto
#20,851 2 comentarios 0 reacciones 1 asignado Ver en GitHub

@bukka ya está trabajando en esto.

Desde el 6/1/2026.

Bug Extension: openssl Status: Needs Triage
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.2k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.