[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/cose-lib/src/ -> Algorithms.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  /*
   6   * The MIT License (MIT)
   7   *
   8   * Copyright (c) 2014-2019 Spomky-Labs
   9   *
  10   * This software may be modified and distributed under the terms
  11   * of the MIT license.  See the LICENSE file for details.
  12   */
  13  
  14  namespace Cose;
  15  
  16  use Assert\Assertion;
  17  use Cose\Algorithm\Algorithm;
  18  use Cose\Algorithm\Mac;
  19  use Cose\Algorithm\Signature\ECDSA;
  20  use Cose\Algorithm\Signature\EdDSA;
  21  use Cose\Algorithm\Signature\RSA;
  22  
  23  /**
  24   * @see https://www.iana.org/assignments/cose/cose.xhtml#algorithms
  25   */
  26  abstract class Algorithms
  27  {
  28      public const COSE_ALGORITHM_AES_CCM_64_128_256 = 33;
  29      public const COSE_ALGORITHM_AES_CCM_64_128_128 = 32;
  30      public const COSE_ALGORITHM_AES_CCM_16_128_256 = 31;
  31      public const COSE_ALGORITHM_AES_CCM_16_128_128 = 30;
  32      public const COSE_ALGORITHM_AES_MAC_256_128 = 26;
  33      public const COSE_ALGORITHM_AES_MAC_128_128 = 25;
  34      public const COSE_ALGORITHM_CHACHA20_POLY1305 = 24;
  35      public const COSE_ALGORITHM_AES_MAC_256_64 = 15;
  36      public const COSE_ALGORITHM_AES_MAC_128_64 = 14;
  37      public const COSE_ALGORITHM_AES_CCM_64_64_256 = 13;
  38      public const COSE_ALGORITHM_AES_CCM_64_64_128 = 12;
  39      public const COSE_ALGORITHM_AES_CCM_16_64_256 = 11;
  40      public const COSE_ALGORITHM_AES_CCM_16_64_128 = 10;
  41      public const COSE_ALGORITHM_HS512 = 7;
  42      public const COSE_ALGORITHM_HS384 = 6;
  43      public const COSE_ALGORITHM_HS256 = 5;
  44      public const COSE_ALGORITHM_HS256_64 = 4;
  45      public const COSE_ALGORITHM_A256GCM = 3;
  46      public const COSE_ALGORITHM_A192GCM = 2;
  47      public const COSE_ALGORITHM_A128GCM = 1;
  48      public const COSE_ALGORITHM_A128KW = -3;
  49      public const COSE_ALGORITHM_A192KW = -4;
  50      public const COSE_ALGORITHM_A256KW = -5;
  51      public const COSE_ALGORITHM_DIRECT = -6;
  52      public const COSE_ALGORITHM_ES256 = -7;
  53      public const COSE_ALGORITHM_EdDSA = -8;
  54      public const COSE_ALGORITHM_ED256 = -260;
  55      public const COSE_ALGORITHM_ED512 = -261;
  56      public const COSE_ALGORITHM_DIRECT_HKDF_SHA_256 = -10;
  57      public const COSE_ALGORITHM_DIRECT_HKDF_SHA_512 = -11;
  58      public const COSE_ALGORITHM_DIRECT_HKDF_AES_128 = -12;
  59      public const COSE_ALGORITHM_DIRECT_HKDF_AES_256 = -13;
  60      public const COSE_ALGORITHM_ECDH_ES_HKDF_256 = -25;
  61      public const COSE_ALGORITHM_ECDH_ES_HKDF_512 = -26;
  62      public const COSE_ALGORITHM_ECDH_SS_HKDF_256 = -27;
  63      public const COSE_ALGORITHM_ECDH_SS_HKDF_512 = -28;
  64      public const COSE_ALGORITHM_ECDH_ES_A128KW = -29;
  65      public const COSE_ALGORITHM_ECDH_ES_A192KW = -30;
  66      public const COSE_ALGORITHM_ECDH_ES_A256KW = -31;
  67      public const COSE_ALGORITHM_ECDH_SS_A128KW = -32;
  68      public const COSE_ALGORITHM_ECDH_SS_A192KW = -33;
  69      public const COSE_ALGORITHM_ECDH_SS_A256KW = -34;
  70      public const COSE_ALGORITHM_ES384 = -35;
  71      public const COSE_ALGORITHM_ES512 = -36;
  72      public const COSE_ALGORITHM_PS256 = -37;
  73      public const COSE_ALGORITHM_PS384 = -38;
  74      public const COSE_ALGORITHM_PS512 = -39;
  75      public const COSE_ALGORITHM_RSAES_OAEP = -40;
  76      public const COSE_ALGORITHM_RSAES_OAEP_256 = -41;
  77      public const COSE_ALGORITHM_RSAES_OAEP_512 = -42;
  78      public const COSE_ALGORITHM_ES256K = -43;
  79      public const COSE_ALGORITHM_RS256 = -257;
  80      public const COSE_ALGORITHM_RS384 = -258;
  81      public const COSE_ALGORITHM_RS512 = -259;
  82      public const COSE_ALGORITHM_RS1 = -65535;
  83  
  84      public const COSE_ALGORITHM_MAP = [
  85          self::COSE_ALGORITHM_ES256 => OPENSSL_ALGO_SHA256,
  86          self::COSE_ALGORITHM_ES384 => OPENSSL_ALGO_SHA384,
  87          self::COSE_ALGORITHM_ES512 => OPENSSL_ALGO_SHA512,
  88          self::COSE_ALGORITHM_RS256 => OPENSSL_ALGO_SHA256,
  89          self::COSE_ALGORITHM_RS384 => OPENSSL_ALGO_SHA384,
  90          self::COSE_ALGORITHM_RS512 => OPENSSL_ALGO_SHA512,
  91          self::COSE_ALGORITHM_RS1 => OPENSSL_ALGO_SHA1,
  92      ];
  93  
  94      public const COSE_HASH_MAP = [
  95          self::COSE_ALGORITHM_ES256K => 'sha256',
  96          self::COSE_ALGORITHM_ES256 => 'sha256',
  97          self::COSE_ALGORITHM_ES384 => 'sha384',
  98          self::COSE_ALGORITHM_ES512 => 'sha512',
  99          self::COSE_ALGORITHM_RS256 => 'sha256',
 100          self::COSE_ALGORITHM_RS384 => 'sha384',
 101          self::COSE_ALGORITHM_RS512 => 'sha512',
 102          self::COSE_ALGORITHM_PS256 => 'sha256',
 103          self::COSE_ALGORITHM_PS384 => 'sha384',
 104          self::COSE_ALGORITHM_PS512 => 'sha512',
 105          self::COSE_ALGORITHM_RS1 => 'sha1',
 106      ];
 107  
 108      public static function getOpensslAlgorithmFor(int $algorithmIdentifier): int
 109      {
 110          Assertion::keyExists(self::COSE_ALGORITHM_MAP, $algorithmIdentifier, 'The specified algorithm identifier is not supported');
 111  
 112          return self::COSE_ALGORITHM_MAP[$algorithmIdentifier];
 113      }
 114  
 115      public static function getHashAlgorithmFor(int $algorithmIdentifier): string
 116      {
 117          Assertion::keyExists(self::COSE_HASH_MAP, $algorithmIdentifier, 'The specified algorithm identifier is not supported');
 118  
 119          return self::COSE_HASH_MAP[$algorithmIdentifier];
 120      }
 121  
 122      /**
 123       * @deprecated Will be removed in v3.0. Please use the Manager or the ManagerFactory
 124       */
 125      public static function getAlgorithm(int $identifier): Algorithm
 126      {
 127          $algs = static::getAlgorithms();
 128          Assertion::keyExists($algs, $identifier, 'The specified algorithm identifier is not supported');
 129  
 130          return $algs[$identifier];
 131      }
 132  
 133      /**
 134       * @deprecated Will be removed in v3.0. Please use the Manager or the ManagerFactory
 135       *
 136       * @return Algorithm[]
 137       */
 138      public static function getAlgorithms(): array
 139      {
 140          return [
 141              Mac\HS256::identifier() => new Mac\HS256(),
 142              Mac\HS384::identifier() => new Mac\HS384(),
 143              Mac\HS512::identifier() => new Mac\HS512(),
 144              RSA\RS256::identifier() => new RSA\RS256(),
 145              RSA\RS384::identifier() => new RSA\RS384(),
 146              RSA\RS512::identifier() => new RSA\RS512(),
 147              RSA\PS256::identifier() => new RSA\PS256(),
 148              RSA\PS384::identifier() => new RSA\PS384(),
 149              RSA\PS512::identifier() => new RSA\PS512(),
 150              ECDSA\ES256K::identifier() => new ECDSA\ES256K(),
 151              ECDSA\ES256::identifier() => new ECDSA\ES256(),
 152              ECDSA\ES384::identifier() => new ECDSA\ES384(),
 153              ECDSA\ES512::identifier() => new ECDSA\ES512(),
 154              EdDSA\ED512::identifier() => new EdDSA\ED512(),
 155          ];
 156      }
 157  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer