|
1 <?php |
|
2 |
|
3 require_once dirname(dirname(__FILE__)) . '/autoload.php'; |
|
4 |
|
5 /** |
|
6 * This file will monkey patch the pure-PHP implementation in place of the |
|
7 * PECL functions and constants, but only if they do not already exist. |
|
8 * |
|
9 * Thus, the functions or constants just proxy to the appropriate |
|
10 * ParagonIE_Sodium_Compat method or class constant, respectively. |
|
11 */ |
|
12 foreach (array( |
|
13 'CRYPTO_AEAD_AESGIS128L_KEYBYTES', |
|
14 'CRYPTO_AEAD_AESGIS128L_NSECBYTES', |
|
15 'CRYPTO_AEAD_AESGIS128L_NPUBBYTES', |
|
16 'CRYPTO_AEAD_AESGIS128L_ABYTES', |
|
17 'CRYPTO_AEAD_AESGIS256_KEYBYTES', |
|
18 'CRYPTO_AEAD_AESGIS256_NSECBYTES', |
|
19 'CRYPTO_AEAD_AESGIS256_NPUBBYTES', |
|
20 'CRYPTO_AEAD_AESGIS256_ABYTES', |
|
21 ) as $constant |
|
22 ) { |
|
23 if (!defined("SODIUM_$constant") && defined("ParagonIE_Sodium_Compat::$constant")) { |
|
24 define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant")); |
|
25 } |
|
26 } |
|
27 if (!is_callable('sodium_crypto_aead_aegis128l_decrypt')) { |
|
28 /** |
|
29 * @see ParagonIE_Sodium_Compat::crypto_aead_aegis128l_decrypt() |
|
30 * @param string $ciphertext |
|
31 * @param string $additional_data |
|
32 * @param string $nonce |
|
33 * @param string $key |
|
34 * @return string |
|
35 * @throws SodiumException |
|
36 */ |
|
37 function sodium_crypto_aead_aegis128l_decrypt( |
|
38 $ciphertext, |
|
39 $additional_data, |
|
40 $nonce, |
|
41 #[\SensitiveParameter] |
|
42 $key |
|
43 ) { |
|
44 return ParagonIE_Sodium_Compat::crypto_aead_aegis128l_decrypt( |
|
45 $ciphertext, |
|
46 $additional_data, |
|
47 $nonce, |
|
48 $key |
|
49 ); |
|
50 } |
|
51 } |
|
52 if (!is_callable('sodium_crypto_aead_aegis128l_encrypt')) { |
|
53 /** |
|
54 * @see ParagonIE_Sodium_Compat::crypto_aead_aegis128l_encrypt() |
|
55 * @param string $message |
|
56 * @param string $additional_data |
|
57 * @param string $nonce |
|
58 * @param string $key |
|
59 * @return string |
|
60 * @throws SodiumException |
|
61 * @throws TypeError |
|
62 */ |
|
63 function sodium_crypto_aead_aegis128l_encrypt( |
|
64 #[\SensitiveParameter] |
|
65 $message, |
|
66 $additional_data, |
|
67 $nonce, |
|
68 #[\SensitiveParameter] |
|
69 $key |
|
70 ) { |
|
71 return ParagonIE_Sodium_Compat::crypto_aead_aegis128l_encrypt( |
|
72 $message, |
|
73 $additional_data, |
|
74 $nonce, |
|
75 $key |
|
76 ); |
|
77 } |
|
78 } |
|
79 if (!is_callable('sodium_crypto_aead_aegis256_decrypt')) { |
|
80 /** |
|
81 * @see ParagonIE_Sodium_Compat::crypto_aead_aegis256_encrypt() |
|
82 * @param string $ciphertext |
|
83 * @param string $additional_data |
|
84 * @param string $nonce |
|
85 * @param string $key |
|
86 * @return string |
|
87 * @throws SodiumException |
|
88 */ |
|
89 function sodium_crypto_aead_aegis256_decrypt( |
|
90 $ciphertext, |
|
91 $additional_data, |
|
92 $nonce, |
|
93 #[\SensitiveParameter] |
|
94 $key |
|
95 ) { |
|
96 return ParagonIE_Sodium_Compat::crypto_aead_aegis256_decrypt( |
|
97 $ciphertext, |
|
98 $additional_data, |
|
99 $nonce, |
|
100 $key |
|
101 ); |
|
102 } |
|
103 } |
|
104 if (!is_callable('sodium_crypto_aead_aegis256_encrypt')) { |
|
105 /** |
|
106 * @see ParagonIE_Sodium_Compat::crypto_aead_aegis256_encrypt() |
|
107 * @param string $message |
|
108 * @param string $additional_data |
|
109 * @param string $nonce |
|
110 * @param string $key |
|
111 * @return string |
|
112 * @throws SodiumException |
|
113 * @throws TypeError |
|
114 */ |
|
115 function sodium_crypto_aead_aegis256_encrypt( |
|
116 #[\SensitiveParameter] |
|
117 $message, |
|
118 $additional_data, |
|
119 $nonce, |
|
120 #[\SensitiveParameter] |
|
121 $key |
|
122 ) { |
|
123 return ParagonIE_Sodium_Compat::crypto_aead_aegis256_encrypt( |
|
124 $message, |
|
125 $additional_data, |
|
126 $nonce, |
|
127 $key |
|
128 ); |
|
129 } |
|
130 } |