@@ -70,9 +70,9 @@ |
||
70 | 70 | */ |
71 | 71 | private static function cost(int $cost): int |
72 | 72 | { |
73 | - if ($cost < 0 || $cost > \pow(2, 32)) { |
|
74 | - throw new \InvalidArgumentException("Hashing cost parameter must between 0 and 2^32"); |
|
75 | - } |
|
73 | + if ($cost < 0 || $cost > \pow(2, 32)) { |
|
74 | + throw new \InvalidArgumentException("Hashing cost parameter must between 0 and 2^32"); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | return $cost; |
78 | 78 | } |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public static function decrypt(string $data, string $pass): string |
37 | 37 | { |
38 | - // Calculate the hash checksum size in bytes for the specified algo |
|
39 | - $hsz = Str::hashSize(static::CHKSUM); |
|
38 | + // Calculate the hash checksum size in bytes for the specified algo |
|
39 | + $hsz = Str::hashSize(static::CHKSUM); |
|
40 | 40 | |
41 | - // Ask openssl for the IV size needed for specified cipher |
|
42 | - $isz = self::ivsize(); |
|
41 | + // Ask openssl for the IV size needed for specified cipher |
|
42 | + $isz = self::ivsize(); |
|
43 | 43 | |
44 | 44 | // Find the IV at the beginning of the cypher text |
45 | 45 | $ivr = Str::substr($data, 0, $isz); |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | // Gather the checksum portion of the ciphertext |
48 | 48 | $sum = Str::substr($data, $isz, $hsz); |
49 | 49 | |
50 | - // Gather the iterations portion of the cipher text as packed/encrytped unsigned long |
|
51 | - $itr = Str::substr($data, $isz + $hsz, 4); |
|
50 | + // Gather the iterations portion of the cipher text as packed/encrytped unsigned long |
|
51 | + $itr = Str::substr($data, $isz + $hsz, 4); |
|
52 | 52 | |
53 | 53 | // Gather message portion of ciphertext after iv and checksum |
54 | 54 | $msg = Str::substr($data, $isz + $hsz + 4); |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | // Encrypt the plaintext |
86 | 86 | $msg = OpensslWrapper::encrypt($data, static::CIPHER, $key, $ivr); |
87 | 87 | |
88 | - // Convert cost integer into 4 byte string and XOR it with the derived key |
|
89 | - $itr = pack('L*', $cost) ^ $key; |
|
88 | + // Convert cost integer into 4 byte string and XOR it with the derived key |
|
89 | + $itr = pack('L*', $cost) ^ $key; |
|
90 | 90 | |
91 | - // Generate the ciphertext checksum |
|
92 | - $chk = \hash_hmac(static::CHKSUM, $msg, $key, true); |
|
91 | + // Generate the ciphertext checksum |
|
92 | + $chk = \hash_hmac(static::CHKSUM, $msg, $key, true); |
|
93 | 93 | |
94 | 94 | // Return iv + checksum + iterations + cyphertext |
95 | 95 | return $ivr . $chk . $itr . $msg; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $chk = \hash_hmac(static::CHKSUM, $msg, $key, true); |
93 | 93 | |
94 | 94 | // Return iv + checksum + iterations + cyphertext |
95 | - return $ivr . $chk . $itr . $msg; |
|
95 | + return $ivr.$chk.$itr.$msg; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | private static function key(string $pass, string $iv, int $cost): string |
107 | 107 | { |
108 | 108 | // Create the authentication string to be hashed |
109 | - $data = $iv . self::RIJNDA . static::CIPHER; |
|
109 | + $data = $iv.self::RIJNDA.static::CIPHER; |
|
110 | 110 | |
111 | 111 | return Hash::ihmac($data, $pass, $cost, static::CHKSUM); |
112 | 112 | } |
@@ -74,10 +74,10 @@ |
||
74 | 74 | { |
75 | 75 | $ret = \openssl_cipher_iv_length(static::CIPHER); |
76 | 76 | |
77 | - if ($ret === false) { |
|
78 | - throw new \Exception("Failed to determine correct IV size."); |
|
79 | - } |
|
77 | + if ($ret === false) { |
|
78 | + throw new \Exception("Failed to determine correct IV size."); |
|
79 | + } |
|
80 | 80 | |
81 | - return $ret; |
|
81 | + return $ret; |
|
82 | 82 | } |
83 | 83 | } |