You are here

public static function ParagonIE_Sodium_Core_Ed25519::small_order in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/Ed25519.php \ParagonIE_Sodium_Core_Ed25519::small_order()

Parameters

string $R:

Return value

bool

Throws

SodiumException

TypeError

3 calls to ParagonIE_Sodium_Core_Ed25519::small_order()
ParagonIE_Sodium_Core_Ed25519::pk_to_curve25519 in vendor/paragonie/sodium_compat/src/Core/Ed25519.php
ParagonIE_Sodium_Core_Ed25519::verify_detached in vendor/paragonie/sodium_compat/src/Core/Ed25519.php
@internal You should not use this directly from another application
ParagonIE_Sodium_File::verify in vendor/paragonie/sodium_compat/src/File.php
Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result.

File

vendor/paragonie/sodium_compat/src/Core/Ed25519.php, line 377

Class

ParagonIE_Sodium_Core_Ed25519
Class ParagonIE_Sodium_Core_Ed25519

Code

public static function small_order($R) {

  /** @var array<int, array<int, int>> $blacklist */
  $blacklist = array(
    /* 0 (order 4) */
    array(
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
    ),
    /* 1 (order 1) */
    array(
      0x1,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
      0x0,
    ),
    /* 2707385501144840649318225287225658788936804267575313519463743609750303402022 (order 8) */
    array(
      0x26,
      0xe8,
      0x95,
      0x8f,
      0xc2,
      0xb2,
      0x27,
      0xb0,
      0x45,
      0xc3,
      0xf4,
      0x89,
      0xf2,
      0xef,
      0x98,
      0xf0,
      0xd5,
      0xdf,
      0xac,
      0x5,
      0xd3,
      0xc6,
      0x33,
      0x39,
      0xb1,
      0x38,
      0x2,
      0x88,
      0x6d,
      0x53,
      0xfc,
      0x5,
    ),
    /* 55188659117513257062467267217118295137698188065244968500265048394206261417927 (order 8) */
    array(
      0xc7,
      0x17,
      0x6a,
      0x70,
      0x3d,
      0x4d,
      0xd8,
      0x4f,
      0xba,
      0x3c,
      0xb,
      0x76,
      0xd,
      0x10,
      0x67,
      0xf,
      0x2a,
      0x20,
      0x53,
      0xfa,
      0x2c,
      0x39,
      0xcc,
      0xc6,
      0x4e,
      0xc7,
      0xfd,
      0x77,
      0x92,
      0xac,
      0x3,
      0x7a,
    ),
    /* p-1 (order 2) */
    array(
      0x13,
      0xe8,
      0x95,
      0x8f,
      0xc2,
      0xb2,
      0x27,
      0xb0,
      0x45,
      0xc3,
      0xf4,
      0x89,
      0xf2,
      0xef,
      0x98,
      0xf0,
      0xd5,
      0xdf,
      0xac,
      0x5,
      0xd3,
      0xc6,
      0x33,
      0x39,
      0xb1,
      0x38,
      0x2,
      0x88,
      0x6d,
      0x53,
      0xfc,
      0x85,
    ),
    /* p (order 4) */
    array(
      0xb4,
      0x17,
      0x6a,
      0x70,
      0x3d,
      0x4d,
      0xd8,
      0x4f,
      0xba,
      0x3c,
      0xb,
      0x76,
      0xd,
      0x10,
      0x67,
      0xf,
      0x2a,
      0x20,
      0x53,
      0xfa,
      0x2c,
      0x39,
      0xcc,
      0xc6,
      0x4e,
      0xc7,
      0xfd,
      0x77,
      0x92,
      0xac,
      0x3,
      0xfa,
    ),
    /* p+1 (order 1) */
    array(
      0xec,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0x7f,
    ),
    /* p+2707385501144840649318225287225658788936804267575313519463743609750303402022 (order 8) */
    array(
      0xed,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0x7f,
    ),
    /* p+55188659117513257062467267217118295137698188065244968500265048394206261417927 (order 8) */
    array(
      0xee,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0x7f,
    ),
    /* 2p-1 (order 2) */
    array(
      0xd9,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
    ),
    /* 2p (order 4) */
    array(
      0xda,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
    ),
    /* 2p+1 (order 1) */
    array(
      0xdb,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
      0xff,
    ),
  );

  /** @var int $countBlacklist */
  $countBlacklist = count($blacklist);
  for ($i = 0; $i < $countBlacklist; ++$i) {
    $c = 0;
    for ($j = 0; $j < 32; ++$j) {
      $c |= self::chrToInt($R[$j]) ^ (int) $blacklist[$i][$j];
    }
    if ($c === 0) {
      return true;
    }
  }
  return false;
}