Skip to content

Commit

Permalink
use php_base64_encode_ex
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Mar 26, 2024
1 parent 596db69 commit cfed1f7
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions ext/openssl/openssl_pwhash.c
Expand Up @@ -162,17 +162,9 @@ static zend_string *php_openssl_argon2_hash(const zend_string *password, zend_ar
return NULL;
}

hash64 = php_base64_encode(hash, HASH_SIZE);
/* No padding utsing 32 *4 / 3 = 42.6 (43 + 1 padding char) */
ZEND_ASSERT(ZSTR_LEN(hash64)==44 && ZSTR_VAL(hash64)[43]=='=');
ZSTR_VAL(hash64)[43] = 0;
ZSTR_LEN(hash64) = 43;

salt64 = php_base64_encode(salt, SALT_SIZE);
/* No padding using 16 *4 / 3 = 21.3 (22 + 2 padding char) */
ZEND_ASSERT(ZSTR_LEN(salt64)==24 && ZSTR_VAL(salt64)[22]=='=' && ZSTR_VAL(salt64)[23]=='=');
ZSTR_VAL(salt64)[22] = 0;
ZSTR_LEN(salt64) = 22;
hash64 = php_base64_encode_ex(hash, HASH_SIZE, PHP_BASE64_NO_PADDING);

salt64 = php_base64_encode_ex(salt, SALT_SIZE, PHP_BASE64_NO_PADDING);

digest = zend_string_alloc(DIGEST_SIZE, 0);
ZSTR_LEN(digest) = snprintf(ZSTR_VAL(digest), ZSTR_LEN(digest), "$%s$v=%d$m=%u,t=%u,p=%u$%s$%s",
Expand Down

0 comments on commit cfed1f7

Please sign in to comment.