crypto_scalarmult_ristretto255.phpt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Check for libsodium scalarmult ristretto255
  3. --EXTENSIONS--
  4. sodium
  5. --SKIPIF--
  6. <?php
  7. if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES')) print "skip libsodium without Ristretto255";
  8. ?>
  9. --FILE--
  10. <?php
  11. $b = sodium_hex2bin("e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76");
  12. $n = str_repeat("\0", SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES);
  13. try {
  14. $p = sodium_crypto_scalarmult_ristretto255_base($n);
  15. } catch (SodiumException $ex) {
  16. echo $ex->getMessage(), "\n";
  17. }
  18. try {
  19. $p2 = sodium_crypto_scalarmult_ristretto255($n, $b);
  20. } catch (SodiumException $ex) {
  21. echo $ex->getMessage(), "\n";
  22. }
  23. for ($i = 1; $i < 16; $i++) {
  24. sodium_increment($n);
  25. $p = sodium_crypto_scalarmult_ristretto255_base($n);
  26. $p2 = sodium_crypto_scalarmult_ristretto255($n, $b);
  27. var_dump(sodium_bin2hex($p));
  28. assert($p === $p2);
  29. }
  30. try {
  31. sodium_crypto_scalarmult(substr($n, 1), $p);
  32. } catch (SodiumException $ex) {
  33. echo $ex->getMessage(), "\n";
  34. }
  35. ?>
  36. --EXPECT--
  37. sodium_crypto_scalarmult_ristretto255_base(): Argument #1 ($n) must not be zero
  38. Result is identity element
  39. string(64) "e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76"
  40. string(64) "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919"
  41. string(64) "94741f5d5d52755ece4f23f044ee27d5d1ea1e2bd196b462166b16152a9d0259"
  42. string(64) "da80862773358b466ffadfe0b3293ab3d9fd53c5ea6c955358f568322daf6a57"
  43. string(64) "e882b131016b52c1d3337080187cf768423efccbb517bb495ab812c4160ff44e"
  44. string(64) "f64746d3c92b13050ed8d80236a7f0007c3b3f962f5ba793d19a601ebb1df403"
  45. string(64) "44f53520926ec81fbd5a387845beb7df85a96a24ece18738bdcfa6a7822a176d"
  46. string(64) "903293d8f2287ebe10e2374dc1a53e0bc887e592699f02d077d5263cdd55601c"
  47. string(64) "02622ace8f7303a31cafc63f8fc48fdc16e1c8c8d234b2f0d6685282a9076031"
  48. string(64) "20706fd788b2720a1ed2a5dad4952b01f413bcf0e7564de8cdc816689e2db95f"
  49. string(64) "bce83f8ba5dd2fa572864c24ba1810f9522bc6004afe95877ac73241cafdab42"
  50. string(64) "e4549ee16b9aa03099ca208c67adafcafa4c3f3e4e5303de6026e3ca8ff84460"
  51. string(64) "aa52e000df2e16f55fb1032fc33bc42742dad6bd5a8fc0be0167436c5948501f"
  52. string(64) "46376b80f409b29dc2b5f6f0c52591990896e5716f41477cd30085ab7f10301e"
  53. string(64) "e0c418f7c8d9c4cdd7395b93ea124f3ad99021bb681dfc3302a9d99a2e53e64e"
  54. sodium_crypto_scalarmult(): Argument #1 ($n) must be SODIUM_CRYPTO_SCALARMULT_SCALARBYTES bytes long