Make WordPress Core


Ignore:
Timestamp:
12/09/2019 04:40:11 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Update sodium_compat to v1.12.1.

This includes a speedup for signature verification on most platforms and bugfixes for 32-bit platforms.

Props paragoninitiativeenterprises, lukaswaudentio.
Fixes #48371.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/sodium_compat/lib/php72compat.php

    r46586 r46858  
    11<?php
     2
     3require_once dirname(dirname(__FILE__)) . '/autoload.php';
    24
    35/**
     
    911 */
    1012foreach (array(
     13    'BASE64_VARIANT_ORIGINAL',
     14    'BASE64_VARIANT_ORIGINAL_NO_PADDING',
     15    'BASE64_VARIANT_URLSAFE',
     16    'BASE64_VARIANT_URLSAFE_NO_PADDING',
    1117    'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES',
    1218    'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES',
     
    3036    'CRYPTO_BOX_NONCEBYTES',
    3137    'CRYPTO_BOX_SEEDBYTES',
     38    'CRYPTO_KDF_BYTES_MIN',
     39    'CRYPTO_KDF_BYTES_MAX',
     40    'CRYPTO_KDF_CONTEXTBYTES',
     41    'CRYPTO_KDF_KEYBYTES',
    3242    'CRYPTO_KX_BYTES',
     43    'CRYPTO_KX_KEYPAIRBYTES',
     44    'CRYPTO_KX_PRIMITIVE',
    3345    'CRYPTO_KX_SEEDBYTES',
    3446    'CRYPTO_KX_PUBLICKEYBYTES',
    3547    'CRYPTO_KX_SECRETKEYBYTES',
     48    'CRYPTO_KX_SESSIONKEYBYTES',
    3649    'CRYPTO_GENERICHASH_BYTES',
    3750    'CRYPTO_GENERICHASH_BYTES_MIN',
     
    5770    'CRYPTO_SECRETBOX_MACBYTES',
    5871    'CRYPTO_SECRETBOX_NONCEBYTES',
     72    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES',
     73    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES',
     74    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES',
     75    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PUSH',
     76    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PULL',
     77    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY',
     78    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL',
     79    'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX',
    5980    'CRYPTO_SIGN_BYTES',
    6081    'CRYPTO_SIGN_SEEDBYTES',
     
    6990    ) as $constant
    7091) {
    71     if (!defined("SODIUM_$constant")) {
     92    if (!defined("SODIUM_$constant") && defined("ParagonIE_Sodium_Compat::$constant")) {
    7293        define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant"));
    7394    }
    7495}
    75 
     96if (!is_callable('sodium_add')) {
     97    /**
     98     * @see ParagonIE_Sodium_Compat::add()
     99     * @param string $val
     100     * @param string $addv
     101     * @return void
     102     * @throws SodiumException
     103     */
     104    function sodium_add(&$val, $addv)
     105    {
     106        ParagonIE_Sodium_Compat::add($val, $addv);
     107    }
     108}
     109if (!is_callable('sodium_base642bin')) {
     110    /**
     111     * @see ParagonIE_Sodium_Compat::bin2base64()
     112     * @param string $string
     113     * @param int $variant
     114     * @param string $ignore
     115     * @return string
     116     * @throws SodiumException
     117     * @throws TypeError
     118     */
     119    function sodium_base642bin($string, $variant, $ignore ='')
     120    {
     121        return ParagonIE_Sodium_Compat::base642bin($string, $variant, $ignore);
     122    }
     123}
     124if (!is_callable('sodium_bin2base64')) {
     125    /**
     126     * @see ParagonIE_Sodium_Compat::bin2base64()
     127     * @param string $string
     128     * @param int $variant
     129     * @return string
     130     * @throws SodiumException
     131     * @throws TypeError
     132     */
     133    function sodium_bin2base64($string, $variant)
     134    {
     135        return ParagonIE_Sodium_Compat::bin2base64($string, $variant);
     136    }
     137}
    76138if (!is_callable('sodium_bin2hex')) {
    77139    /**
     
    187249     * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen()
    188250     * @return string
     251     * @throws Exception
    189252     */
    190253    function sodium_crypto_aead_chacha20poly1305_keygen()
     
    233296     * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen()
    234297     * @return string
     298     * @throws Exception
    235299     */
    236300    function sodium_crypto_aead_chacha20poly1305_ietf_keygen()
     
    279343     * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen()
    280344     * @return string
     345     * @throws Exception
    281346     */
    282347    function sodium_crypto_aead_xchacha20poly1305_ietf_keygen()
     
    303368     * @see ParagonIE_Sodium_Compat::crypto_auth_keygen()
    304369     * @return string
     370     * @throws Exception
    305371     */
    306372    function sodium_crypto_auth_keygen()
     
    517583     * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen()
    518584     * @return string
     585     * @throws Exception
    519586     */
    520587    function sodium_crypto_generichash_keygen()
     
    535602    {
    536603        ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message);
     604    }
     605}
     606if (!is_callable('sodium_crypto_kdf_keygen')) {
     607    /**
     608     * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen()
     609     * @return string
     610     * @throws Exception
     611     */
     612    function sodium_crypto_kdf_keygen()
     613    {
     614        return ParagonIE_Sodium_Compat::crypto_kdf_keygen();
     615    }
     616}
     617if (!is_callable('sodium_crypto_kdf_derive_from_key')) {
     618    /**
     619     * @see ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key()
     620     * @param int $subkey_len
     621     * @param int $subkey_id
     622     * @param string $context
     623     * @param string $key
     624     * @return string
     625     * @throws Exception
     626     */
     627    function sodium_crypto_kdf_derive_from_key($subkey_len, $subkey_id, $context, $key)
     628    {
     629        return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key(
     630            $subkey_len,
     631            $subkey_id,
     632            $context,
     633            $key
     634        );
    537635    }
    538636}
     
    556654            $server_public
    557655        );
     656    }
     657}
     658if (!is_callable('sodium_crypto_kx_seed_keypair')) {
     659    /**
     660     * @param string $seed
     661     * @return string
     662     * @throws Exception
     663     */
     664    function sodium_crypto_kx_seed_keypair($seed)
     665    {
     666        return ParagonIE_Sodium_Compat::crypto_kx_seed_keypair($seed);
     667    }
     668}
     669if (!is_callable('sodium_crypto_kx_keypair')) {
     670    /**
     671     * @return string
     672     * @throws Exception
     673     */
     674    function sodium_crypto_kx_keypair()
     675    {
     676        return ParagonIE_Sodium_Compat::crypto_kx_keypair();
     677    }
     678}
     679if (!is_callable('sodium_crypto_kx_client_session_keys')) {
     680    /**
     681     * @param string $keypair
     682     * @param string $serverPublicKey
     683     * @return array{0: string, 1: string}
     684     * @throws SodiumException
     685     */
     686    function sodium_crypto_kx_client_session_keys($keypair, $serverPublicKey)
     687    {
     688        return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($keypair, $serverPublicKey);
     689    }
     690}
     691if (!is_callable('sodium_crypto_kx_server_session_keys')) {
     692    /**
     693     * @param string $keypair
     694     * @param string $clientPublicKey
     695     * @return array{0: string, 1: string}
     696     * @throws SodiumException
     697     */
     698    function sodium_crypto_kx_server_session_keys($keypair, $clientPublicKey)
     699    {
     700        return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($keypair, $clientPublicKey);
     701    }
     702}
     703if (!is_callable('sodium_crypto_kx_secretkey')) {
     704    /**
     705     * @param string $keypair
     706     * @return string
     707     * @throws Exception
     708     */
     709    function sodium_crypto_kx_secretkey($keypair)
     710    {
     711        return ParagonIE_Sodium_Compat::crypto_kx_secretkey($keypair);
     712    }
     713}
     714if (!is_callable('sodium_crypto_kx_publickey')) {
     715    /**
     716     * @param string $keypair
     717     * @return string
     718     * @throws Exception
     719     */
     720    function sodium_crypto_kx_publickey($keypair)
     721    {
     722        return ParagonIE_Sodium_Compat::crypto_kx_publickey($keypair);
    558723    }
    559724}
     
    591756    }
    592757}
     758if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) {
     759    /**
     760     * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash()
     761     * @param string $hash
     762     * @param int $opslimit
     763     * @param int $memlimit
     764     * @return bool
     765     *
     766     * @throws SodiumException
     767     */
     768    function sodium_crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit)
     769    {
     770        return ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit);
     771    }
     772}
    593773if (!is_callable('sodium_crypto_pwhash_str_verify')) {
    594774    /**
     
    697877     * @see ParagonIE_Sodium_Compat::crypto_secretbox_keygen()
    698878     * @return string
     879     * @throws Exception
    699880     */
    700881    function sodium_crypto_secretbox_keygen()
     
    722903    }
    723904}
     905if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_push')) {
     906    /**
     907     * @param string $key
     908     * @return array<int, string>
     909     * @throws SodiumException
     910     */
     911    function sodium_crypto_secretstream_xchacha20poly1305_init_push($key)
     912    {
     913        return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push($key);
     914    }
     915}
     916if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) {
     917    /**
     918     * @param string $state
     919     * @param string $msg
     920     * @param string $aad
     921     * @param int $tag
     922     * @return string
     923     * @throws SodiumException
     924     */
     925    function sodium_crypto_secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0)
     926    {
     927        return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push($state, $msg, $aad, $tag);
     928    }
     929}
     930if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_pull')) {
     931    /**
     932     * @param string $header
     933     * @param string $key
     934     * @return string
     935     * @throws Exception
     936     */
     937    function sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key)
     938    {
     939        return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
     940    }
     941}
     942if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) {
     943    /**
     944     * @param string $state
     945     * @param string $cipher
     946     * @param string $aad
     947     * @return bool|array{0: string, 1: int}
     948     * @throws SodiumException
     949     */
     950    function sodium_crypto_secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '')
     951    {
     952        return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull($state, $cipher, $aad);
     953    }
     954}
     955if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_rekey')) {
     956    /**
     957     * @param string $state
     958     * @return void
     959     * @throws SodiumException
     960     */
     961    function sodium_crypto_secretstream_xchacha20poly1305_rekey(&$state)
     962    {
     963        ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey($state);
     964    }
     965}
     966if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_keygen')) {
     967    /**
     968     * @return string
     969     * @throws Exception
     970     */
     971    function sodium_crypto_secretstream_xchacha20poly1305_keygen()
     972    {
     973        return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_keygen();
     974    }
     975}
    724976if (!is_callable('sodium_crypto_shorthash')) {
    725977    /**
     
    740992     * @see ParagonIE_Sodium_Compat::crypto_shorthash_keygen()
    741993     * @return string
     994     * @throws Exception
    742995     */
    743996    function sodium_crypto_shorthash_keygen()
     
    7721025    {
    7731026        return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk);
     1027    }
     1028}
     1029if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) {
     1030    /**
     1031     * @see ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey()
     1032     * @param string $sk
     1033     * @param string $pk
     1034     * @return string
     1035     * @throws SodiumException
     1036     * @throws TypeError
     1037     */
     1038    function sodium_crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk)
     1039    {
     1040        return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk);
    7741041    }
    7751042}
     
    9161183     * @see ParagonIE_Sodium_Compat::crypto_stream_keygen()
    9171184     * @return string
     1185     * @throws Exception
    9181186     */
    9191187    function sodium_crypto_stream_keygen()
     
    10201288    }
    10211289}
     1290if (!is_callable('sodium_pad')) {
     1291    /**
     1292     * @see ParagonIE_Sodium_Compat::pad()
     1293     * @param string $unpadded
     1294     * @param int $blockSize
     1295     * @return int
     1296     * @throws SodiumException
     1297     * @throws TypeError
     1298     */
     1299    function sodium_pad($unpadded, $blockSize)
     1300    {
     1301        return ParagonIE_Sodium_Compat::pad($unpadded, $blockSize, true);
     1302    }
     1303}
     1304if (!is_callable('sodium_unpad')) {
     1305    /**
     1306     * @see ParagonIE_Sodium_Compat::pad()
     1307     * @param string $padded
     1308     * @param int $blockSize
     1309     * @return int
     1310     * @throws SodiumException
     1311     * @throws TypeError
     1312     */
     1313    function sodium_unpad($padded, $blockSize)
     1314    {
     1315        return ParagonIE_Sodium_Compat::unpad($padded, $blockSize, true);
     1316    }
     1317}
    10221318if (!is_callable('sodium_randombytes_buf')) {
    10231319    /**
     
    10501346     * @see ParagonIE_Sodium_Compat::randombytes_random16()
    10511347     * @return int
     1348     * @throws Exception
    10521349     */
    10531350    function sodium_randombytes_random16()
Note: See TracChangeset for help on using the changeset viewer.