Skip to content

Commit

Permalink
We need a more surgical polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Apr 14, 2021
1 parent 93f84d9 commit efcecfb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
5 changes: 4 additions & 1 deletion autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ function sodiumCompatAutoloader($class)
} else {
assert(class_exists('ParagonIE_Sodium_Compat'));
}
require_once (dirname(__FILE__) . '/lib/php72compat.php');
require_once(dirname(__FILE__) . '/lib/php72compat.php');
} elseif (!function_exists('sodium_crypto_stream_xchacha20_xor')) {
// Older versions of {PHP, ext/sodium} will not define these
require_once(dirname(__FILE__) . '/lib/php72compat.php');
}
42 changes: 1 addition & 41 deletions lib/php72compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -1218,47 +1218,7 @@ function sodium_crypto_stream_xor($message, $nonce, $key)
return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
}
}
if (!is_callable('sodium_crypto_stream_xchacha20')) {
/**
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20()
* @param int $len
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
* @throws TypeError
*/
function sodium_crypto_stream_xchacha20($len, $nonce, $key)
{
ParagonIE_Sodium_Compat::crypto_stream_xchacha20($len, $nonce, $key, true);
}
}
if (!is_callable('sodium_crypto_stream_xchacha20_keygen')) {
/**
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_keygen()
* @return string
* @throws Exception
*/
function sodium_crypto_stream_xchacha20_keygen()
{
return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_keygen();
}
}
if (!is_callable('sodium_crypto_stream_xchacha20_xor')) {
/**
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor()
* @param string $message
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
* @throws TypeError
*/
function sodium_crypto_stream_xchacha20_xor($message, $nonce, $key)
{
ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor($message, $nonce, $key, true);
}
}
require_once dirname(__FILE__) . '/stream-xchacha20.php';
if (!is_callable('sodium_hex2bin')) {
/**
* @see ParagonIE_Sodium_Compat::hex2bin()
Expand Down
43 changes: 43 additions & 0 deletions lib/stream-xchacha20.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

if (!is_callable('sodium_crypto_stream_xchacha20')) {
/**
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20()
* @param int $len
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
* @throws TypeError
*/
function sodium_crypto_stream_xchacha20($len, $nonce, $key)
{
return ParagonIE_Sodium_Compat::crypto_stream_xchacha20($len, $nonce, $key, true);
}
}
if (!is_callable('sodium_crypto_stream_xchacha20_keygen')) {
/**
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_keygen()
* @return string
* @throws Exception
*/
function sodium_crypto_stream_xchacha20_keygen()
{
return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_keygen();
}
}
if (!is_callable('sodium_crypto_stream_xchacha20_xor')) {
/**
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor()
* @param string $message
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
* @throws TypeError
*/
function sodium_crypto_stream_xchacha20_xor($message, $nonce, $key)
{
return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor($message, $nonce, $key, true);
}
}

0 comments on commit efcecfb

Please sign in to comment.