Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Crypto/MaterialsProviderV3.php

raw symbols SCIP
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 * Returns if the requested size is supported by AES.
14 *
15 * @param int $keySize Size of the requested key in bits.
16 *
17 * @return bool
18 */
19 public static function isSupportedKeySize(int $keySize): bool
20 {
21 return isset(self::$supportedKeySizes[$keySize]);
22 }
23
24 /**
25 * Returns the wrap algorithm name for this Provider.
26 *
27 * @return string
28 */
29 abstract public function getWrapAlgorithmName(): string;
30
31 /**
32 * Takes an encrypted content encryption key (CEK) and material description
33 * for use decrypting the key according to the Provider's specifications.
34 *
35 * @param string $encryptedCek Encrypted key to be decrypted by the Provider
36 * for use decrypting other data.
37 * @param array $materialDescription Material Description for use in
38 * decrypting the CEK.
39 * @param array $options Options for use in decrypting the CEK.
40 *
41 * @return string
42 */
43 abstract public function decryptCek(
44 string $encryptedCek,
45 array $materialDescription,
46 array $options
47 ): string;
48
49 /**
50 * @param string $keySize Length of a cipher key in bits for generating a
51 * random content encryption key (CEK).
52 * @param array $context Context map needed for key encryption
53 * @param array $options Additional options to be used in CEK generation
54 *
55 * @return array
56 */
57 abstract public function generateCek(
58 string $keySize,
59 array $context,
60 array $options
61 ): array;
62
63 /**
64 * @param string $openSslName Cipher OpenSSL name to use for generating
65 * an initialization vector.
66 *
67 * @return string
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 }