| 1 |
<?php |
| 2 |
namespace Aws\Crypto; |
| 3 |
|
| 4 |
use Aws\Exception\CryptoException; |
| 5 |
|
| 6 |
abstract class MaterialsProviderV3 implements MaterialsProviderInterfaceV3 |
| 7 |
{ |
| 8 |
private static array $supportedKeySizes = [ |
| 9 |
256 => true |
| 10 |
]; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public static function isSupportedKeySize(int $keySize): bool |
| 20 |
{ |
| 21 |
return isset(self::$supportedKeySizes[$keySize]); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
abstract public function getWrapAlgorithmName(): string; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
abstract public function decryptCek( |
| 44 |
string $encryptedCek, |
| 45 |
array $materialDescription, |
| 46 |
array $options |
| 47 |
): string; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
abstract public function generateCek( |
| 58 |
string $keySize, |
| 59 |
array $context, |
| 60 |
array $options |
| 61 |
): array; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function generateIv(string $openSslName): string |
| 70 |
{ |
| 71 |
$iv = null; |
| 72 |
$cstrong = null; |
| 73 |
|
| 74 |
if ($openSslName === "aes-96-gcm") { |
| 75 |
$iv = openssl_random_pseudo_bytes(12, $cstrong); |
| 76 |
} else if ($openSslName === "aes-224-gcm") { |
| 77 |
$iv = openssl_random_pseudo_bytes(28, $cstrong); |
| 78 |
} else { |
| 79 |
$iv = openssl_random_pseudo_bytes( |
| 80 |
openssl_cipher_iv_length($openSslName), |
| 81 |
$cstrong |
| 82 |
); |
| 83 |
} |
| 84 |
if (!$cstrong) { |
| 85 |
throw new CryptoException("No strong cryptographic source available to generate a random IV."); |
| 86 |
} |
| 87 |
|
| 88 |
return $iv; |
| 89 |
} |
| 90 |
} |