1: <?php
2:
3: /**
4: * Support for libsodium PECL package, and the upcoming PHP 7.2 built in extension
5: * The 2 versions of libsodium differ in the following ways:
6: *
7: * PECL uses a Sodium namespace, the PHP version does not
8: * PECL exposes the extension as "libsodium", the PHP verions is "sodium"
9: * PHP prefixes functions and constants with "sodium_"
10: *
11: * @package framework
12: * @subpackage crypt
13: */
14:
15: class Hm_Sodium_PECL {
16:
17: public static function crypto_auth_verify($hmac, $crypt_string, $crypt_key) {
18: return \Sodium\crypto_auth_verify($hmac, $crypt_string, $crypt_key);
19: }
20:
21: public static function crypto_secretbox_open($crypt_string, $salt, $crypt_key) {
22: return \Sodium\crypto_secretbox_open($crypt_string, $salt, $crypt_key);
23: }
24:
25: public static function crypto_secretbox($string, $salt, $key) {
26: return \Sodium\crypto_secretbox($string, $salt, $key);
27: }
28:
29: public static function crypto_auth($ciphertext, $key) {
30: return \Sodium\crypto_auth($ciphertext, $key);
31: }
32:
33: public static function crypto_pwhash_str($password) {
34: return \Sodium\crypto_pwhash_str($password, \Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
35: \Sodium\CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE);
36: }
37:
38: public static function crypto_pwhash_str_verify($hash, $password) {
39: return \Sodium\crypto_pwhash_str_verify($hash, $password);
40: }
41:
42: public static function randombytes_buf() {
43: return \Sodium\randombytes_buf(\Sodium\CRYPTO_SECRETBOX_NONCEBYTES);
44: }
45: }
46:
47: /**
48: * @package framework
49: * @subpackage crypt
50: */
51: class Hm_Sodium_PHP {
52: public static function crypto_auth_verify($hmac, $crypt_string, $crypt_key) {
53: return sodium_crypto_auth_verify($hmac, $crypt_string, $crypt_key);
54: }
55:
56: public static function crypto_secretbox_open($crypt_string, $salt, $crypt_key) {
57: return sodium_crypto_secretbox_open($crypt_string, $salt, $crypt_key);
58: }
59:
60: public static function crypto_secretbox($string, $salt, $key) {
61: return sodium_crypto_secretbox($string, $salt, $key);
62: }
63:
64: public static function crypto_auth($ciphertext, $key) {
65: return sodium_crypto_auth($ciphertext, $key);
66: }
67:
68: public static function crypto_pwhash_str($password) {
69: return sodium_crypto_pwhash_str($password, SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
70: SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE);
71: }
72:
73: public static function crypto_pwhash_str_verify($hash, $password) {
74: return sodium_crypto_pwhash_str_verify($hash, $password);
75: }
76:
77: public static function randombytes_buf() {
78: return random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
79: }
80: }
81: