paragonie / sodium_compat

Pure PHP polyfill for ext/sodium

Home Page:https://paragonie.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined constant 'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES'

Kulturnilpferd opened this issue · comments

Hey there,
after updating to php7.3 I get these stragne errors in error.log maybe you could help me...
PHP Fatal error: Uncaught Error: Undefined constant 'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES' in /home/homepages/myhomepage/httpdocs/libraries/vendor/paragonie/sodium_compat/lib/constants.php:22\nStack trace:\n#0 /home/homepages/myhomepage/httpdocs/libraries/vendor/paragonie/sodium_compat/lib/sodium_compat.php(834): require_once()\n#1 /home/homepages/myhomepage/httpdocs/libraries/vendor/paragonie/sodium_compat/autoload.php(45): require_once('/home/homepages...')\n#2 /home/homepages/myhomepage/httpdocs/libraries/vendor/composer/autoload_real.php(66): require('/home/homepages...')\n#3 /home/homepages/myhomepage/httpdocs/libraries/vendor/composer/autoload_real.php(56): composerRequire205c915b9c7d3e718e7c95793ee67ffe('3109cb1a231dcd0...', '/home/homepages...')\n#4 /home/homepages/myhomepage/httpdocs/libraries/vendor/autoload.php(7): ComposerAutoloaderInit205c915b9c7d3e718e7c95793ee67ffe::getLoader()\n#5 /home/homepages/myhomepage/httpdocs/libraries/cms.php(36): require('/home/homepages...')\n in /home/homepages/myhomepage/httpdocs/libraries/vendor/paragonie/sodium_compat/lib/constants.php on line 22, referer: https://myhomepage/groups?start=108

If you update to the latest version of sodium_compat, does this error persist?

Same problem with 1.16.0 and fresh installed composer package.

\Sodium\CRYPTO_PWHASH_SCRIPTSALSA208SHA256_OPSLIMIT_INTERACTIVE undefined constant.

@paragonie-security

Hi, I got similar error

PHP Fatal error: Uncaught Error: Undefined class constant 'CRYPTO_CORE_RISTRETTO255_BYTES' in C:\aether\vendor\paragonie\sodium_compat\lib\ristretto255.php:6

I think those errors are on purpose. Because the encryption or hashing methods are not performant in the sodium_compat package and should only be used with the PHP internal libsodium library. Those errors seam to be a little confusing. Could it be possible to maybe throw an more meaningful exception instead of removing those constants entirely?

I think those errors are on purpose. Because the encryption or hashing methods are not performant in the sodium_compat package and should only be used with the PHP internal libsodium library. Those errors seam to be a little confusing. Could it be possible to maybe throw an more meaningful exception instead of removing those constants entirely?

No, the point of this library is to be a polyfill.

@paragonie-security

Hi, I got similar error

PHP Fatal error: Uncaught Error: Undefined class constant 'CRYPTO_CORE_RISTRETTO255_BYTES' in C:\aether\vendor\paragonie\sodium_compat\lib\ristretto255.php:6

This is bizarre. It definitely exists.

I wonder if triggering the autoloader would sidestep this.

Can you add this line to vendor/paragonie/sodium_compat/autoload.php directly above line 44?

if (!class_exists('ParagonIE_Sodium_Compat')) {
    var_dump('class does not exist');
}

...and then tell me if this affects these errors?

A patch with an alternative proposed fix is in #132. If you can confirm that it addresses the observed behavior, I can merge it and tag v1.6.1 with the fix.

I think those errors are on purpose. Because the encryption or hashing methods are not performant in the sodium_compat package and should only be used with the PHP internal libsodium library. Those errors seam to be a little confusing. Could it be possible to maybe throw an more meaningful exception instead of removing those constants entirely?

No, the point of this library is to be a polyfill.

Okay. That's fine. Took me some hours to understand, that behavior. Just thought it could be a little easier. But I totally understand that point as well. Is there a list of functions not available in the polyfill but available in libsodium? Just for the future. At the moment we rely on other functions which are completely available in your polyfill implementation.

Is there a list of functions not available in the polyfill but available in libsodium? Just for the future. At the moment we rely on other functions which are completely available in your polyfill implementation.

Outside the pwhash API, if a function is not covered by the polyfill, we consider that a bug to be fixed.

@paragonie-security
Hi, I got similar error
PHP Fatal error: Uncaught Error: Undefined class constant 'CRYPTO_CORE_RISTRETTO255_BYTES' in C:\aether\vendor\paragonie\sodium_compat\lib\ristretto255.php:6

This is bizarre. It definitely exists.

I wonder if triggering the autoloader would sidestep this.

Can you add this line to vendor/paragonie/sodium_compat/autoload.php directly above line 44?

if (!class_exists('ParagonIE_Sodium_Compat')) {
    var_dump('class does not exist');
}

...and then tell me if this affects these errors?

var_dump(class_exists('ParagonIE_Sodium_Compat'));exit;

output: bool(true)

A patch with an alternative proposed fix is in #132. If you can confirm that it addresses the observed behavior, I can merge it and tag v1.6.1 with the fix.

I found the issue happened on WordPress, because WordPress embed this package too.
https://github.com/WordPress/WordPress/tree/master/wp-includes/sodium_compat

$rc = new \ReflectionClass('ParagonIE_Sodium_Compat');

var_dump($rc->getFileName());exit;

output: C:\laragon\www\wordpress\wp-includes\sodium_compat\src\Compat.php

If this is a WordPress issue, try this:

  1. Backup wp-includes\sodium_compat
  2. Replace its contents with the branch in #122
  3. Report back and tell us if the problem is fixed.

If so, the solution is simple: Release 1.6.1 and then tell the WordPress team to update their dependency in their next release. We've done this before.

If this is a WordPress issue, try this:

1. Backup `wp-includes\sodium_compat`

2. Replace its contents with the branch in #122

3. Report back and tell us if the problem is fixed.

If so, the solution is simple: Release 1.6.1 and then tell the WordPress team to update their dependency in their next release. We've done this before.

I can confirm its work by following this guidance

Great! v1.16.1 is out. We'll follow up with the WordPress dev team to get sodium_compat updated.