[php-src] Issue #25242: Add IPCrypt support in Sodium extension
| From: | bohwaz | Date: | Fri, 06 Nov 2026 15:19:04 +0000 |
| Subject: | [php-src] Issue #25242: Add IPCrypt support in Sodium extension | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-254036@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25242
Author: bohwaz
### Description
libsodium exposes IPCrypt features since version 1.0.21 (January 6, 2026): https://libsodium.gitbook.io/doc/secret-key_cryptography/ip_address_encryption
There is IPCrypt userspace implementation for PHP: https://github.com/jedisct1/php-ipcrypt
But since we are shipping sodium in PHP, it would be nice to also natively have the sodium IPCrypt
functions in PHP.
This would mean adding the following constants and functions:
```php
const SODIUM_CRYPTO_IPCRYPT_NDX_TWEAKBYTES;
// Utils
sodium_ip2bin(string $ip): string
sodium_bin2ip(string $binary): string
// Deterministic
sodium_crypto_ipcrypt_keygen(): string
sodium_crypto_ipcrypt_encrypt(string $binary_ip, string $key): string
sodium_crypto_ipcrypt_decrypt(string $binary_encrypted_ip, string $key): string
// Non-deterministic (ND)
sodium_crypto_ipcrypt_nd_keygen(): string
sodium_crypto_ipcrypt_nd_encrypt(string $binary_ip, string $key): string
sodium_crypto_ipcrypt_nd_decrypt(string $binary_encrypted_ip, string $key): string
// Prefix-preserving encryption (PFX)
sodium_crypto_ipcrypt_pfx_keygen(): string
sodium_crypto_ipcrypt_pfx_encrypt(string $binary_ip, string $key): string
sodium_crypto_ipcrypt_pfx_decrypt(string $binary_encrypted_ip, string $key): string
// Extended non-deterministic encryption (NDX)
sodium_crypto_ipcrypt_ndx_keygen(): string
sodium_crypto_ipcrypt_ndx_encrypt(string $binary_ip, string $key): string
sodium_crypto_ipcrypt_ndx_decrypt(string $binary_encrypted_ip, string $key): string
```