Make WordPress Core


Ignore:
Timestamp:
07/18/2024 12:58:40 PM (10 months ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Update sodium_compat to v1.21.1.

The latest version of sodium_compat includes support for AEGIS and preliminary support for PHP 8.4.

Additionally, the PHP 8.2+ SensitiveParameter attribute is now applied where appropriate to functions in the public API. This attribute is used to mark parameters that are sensitive and should be redacted from stack traces.

References:

Follow-up to [49741], [51002], [51591], [52988], [54150], [54310], [55699].

Props jrf, dd32, paragoninitiativeenterprises.
Fixes #61686.

File:
1 edited

Legend:

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

    r54310 r58752  
    2121     * @throws \TypeError
    2222     */
    23     function bin2hex($string)
    24     {
     23    function bin2hex(
     24        #[\SensitiveParameter]
     25        $string
     26    ) {
    2527        return ParagonIE_Sodium_Compat::bin2hex($string);
    2628    }
     
    3537     * @throws \TypeError
    3638     */
    37     function compare($a, $b)
    38     {
     39    function compare(
     40        #[\SensitiveParameter]
     41        $a,
     42        #[\SensitiveParameter]
     43        $b
     44    ) {
    3945        return ParagonIE_Sodium_Compat::compare($a, $b);
    4046    }
     
    4955     * @return string|bool
    5056     */
    51     function crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key)
    52     {
     57    function crypto_aead_aes256gcm_decrypt(
     58        $message,
     59        $assocData,
     60        $nonce,
     61        #[\SensitiveParameter]
     62        $key
     63    ) {
    5364        try {
    5465            return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key);
     
    7182     * @throws \TypeError
    7283     */
    73     function crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key)
    74     {
     84    function crypto_aead_aes256gcm_encrypt(
     85        #[\SensitiveParameter]
     86        $message,
     87        $assocData,
     88        $nonce,
     89        #[\SensitiveParameter]
     90        $key
     91    ) {
    7592        return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key);
    7693    }
     
    95112     * @return string|bool
    96113     */
    97     function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key)
    98     {
     114    function crypto_aead_chacha20poly1305_decrypt(
     115        $message,
     116        $assocData,
     117        $nonce,
     118        #[\SensitiveParameter]
     119        $key
     120    ) {
    99121        try {
    100122            return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key);
     
    117139     * @throws \TypeError
    118140     */
    119     function crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key)
    120     {
     141    function crypto_aead_chacha20poly1305_encrypt(
     142        #[\SensitiveParameter]
     143        $message,
     144        $assocData,
     145        $nonce,
     146        #[\SensitiveParameter]
     147        $key
     148    ) {
    121149        return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key);
    122150    }
     
    131159     * @return string|bool
    132160     */
    133     function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key)
    134     {
     161    function crypto_aead_chacha20poly1305_ietf_decrypt(
     162        $message,
     163        $assocData,
     164        $nonce,
     165        #[\SensitiveParameter]
     166        $key
     167    ) {
    135168        try {
    136169            return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key);
     
    153186     * @throws \TypeError
    154187     */
    155     function crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key)
    156     {
     188    function crypto_aead_chacha20poly1305_ietf_encrypt(
     189        #[\SensitiveParameter]
     190        $message,
     191        $assocData,
     192        $nonce,
     193        #[\SensitiveParameter]
     194        $key
     195    ) {
    157196        return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key);
    158197    }
     
    167206     * @throws \TypeError
    168207     */
    169     function crypto_auth($message, $key)
    170     {
     208    function crypto_auth(
     209        $message,
     210        #[\SensitiveParameter]
     211        $key
     212    ) {
    171213        return ParagonIE_Sodium_Compat::crypto_auth($message, $key);
    172214    }
     
    182224     * @throws \TypeError
    183225     */
    184     function crypto_auth_verify($mac, $message, $key)
    185     {
     226    function crypto_auth_verify(
     227        $mac,
     228        $message,
     229        #[\SensitiveParameter]
     230        $key
     231    ) {
    186232        return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key);
    187233    }
     
    197243     * @throws \TypeError
    198244     */
    199     function crypto_box($message, $nonce, $kp)
    200     {
     245    function crypto_box(
     246        #[\SensitiveParameter]
     247        $message,
     248        $nonce,
     249        #[\SensitiveParameter]
     250        $kp
     251    ) {
    201252        return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp);
    202253    }
     
    223274     * @throws \TypeError
    224275     */
    225     function crypto_box_keypair_from_secretkey_and_publickey($sk, $pk)
    226     {
     276    function crypto_box_keypair_from_secretkey_and_publickey(
     277        #[\SensitiveParameter]
     278        $sk,
     279        $pk
     280    ) {
    227281        return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk);
    228282    }
     
    236290     * @return string|bool
    237291     */
    238     function crypto_box_open($message, $nonce, $kp)
    239     {
     292    function crypto_box_open(
     293        #[\SensitiveParameter]
     294        $message,
     295        $nonce,
     296        #[\SensitiveParameter]
     297        $kp
     298    ) {
    240299        try {
    241300            return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp);
     
    255314     * @throws \TypeError
    256315     */
    257     function crypto_box_publickey($keypair)
    258     {
     316    function crypto_box_publickey(
     317        #[\SensitiveParameter]
     318        $keypair
     319    ) {
    259320        return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair);
    260321    }
     
    268329     * @throws \TypeError
    269330     */
    270     function crypto_box_publickey_from_secretkey($sk)
    271     {
     331    function crypto_box_publickey_from_secretkey(
     332        #[\SensitiveParameter]
     333        $sk
     334    ) {
    272335        return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk);
    273336    }
     
    282345     * @throws \TypeError
    283346     */
    284     function crypto_box_seal($message, $publicKey)
    285     {
     347    function crypto_box_seal(
     348        #[\SensitiveParameter]
     349        $message,
     350        $publicKey
     351    ) {
    286352        return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey);
    287353    }
     
    294360     * @return string|bool
    295361     */
    296     function crypto_box_seal_open($message, $kp)
    297     {
     362    function crypto_box_seal_open(
     363        $message,
     364        #[\SensitiveParameter]
     365        $kp
     366    ) {
    298367        try {
    299368            return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp);
     
    313382     * @throws \TypeError
    314383     */
    315     function crypto_box_secretkey($keypair)
    316     {
     384    function crypto_box_secretkey(
     385        #[\SensitiveParameter]
     386        $keypair
     387    ) {
    317388        return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair);
    318389    }
     
    328399     * @throws \TypeError
    329400     */
    330     function crypto_generichash($message, $key = null, $outLen = 32)
    331     {
     401    function crypto_generichash(
     402        $message,
     403        #[\SensitiveParameter]
     404        $key = null,
     405        $outLen = 32
     406    ) {
    332407        return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen);
    333408    }
     
    342417     * @throws \TypeError
    343418     */
    344     function crypto_generichash_final(&$ctx, $outputLength = 32)
    345     {
     419    function crypto_generichash_final(
     420        #[\SensitiveParameter]
     421        &$ctx,
     422        $outputLength = 32
     423    ) {
    346424        return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength);
    347425    }
     
    356434     * @throws \TypeError
    357435     */
    358     function crypto_generichash_init($key = null, $outLen = 32)
    359     {
     436    function crypto_generichash_init(
     437        #[\SensitiveParameter]
     438        $key = null,
     439        $outLen = 32
     440    ) {
    360441        return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen);
    361442    }
     
    370451     * @throws \TypeError
    371452     */
    372     function crypto_generichash_update(&$ctx, $message = '')
    373     {
     453    function crypto_generichash_update(
     454        #[\SensitiveParameter]
     455        &$ctx,
     456        $message = ''
     457    ) {
    374458        ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message);
    375459    }
     
    386470     * @throws \TypeError
    387471     */
    388     function crypto_kx($my_secret, $their_public, $client_public, $server_public)
    389     {
     472    function crypto_kx(
     473        #[\SensitiveParameter]
     474        $my_secret,
     475        $their_public,
     476        $client_public,
     477        $server_public
     478    ) {
    390479        return ParagonIE_Sodium_Compat::crypto_kx(
    391480            $my_secret,
     
    409498     * @throws \TypeError
    410499     */
    411     function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit)
    412     {
     500    function crypto_pwhash(
     501        $outlen,
     502        #[\SensitiveParameter]
     503        $passwd,
     504        $salt,
     505        $opslimit,
     506        $memlimit
     507    ) {
    413508        return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit);
    414509    }
     
    424519     * @throws \TypeError
    425520     */
    426     function crypto_pwhash_str($passwd, $opslimit, $memlimit)
    427     {
     521    function crypto_pwhash_str(
     522        #[\SensitiveParameter]
     523        $passwd,
     524        $opslimit,
     525        $memlimit
     526    ) {
    428527        return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit);
    429528    }
     
    438537     * @throws \TypeError
    439538     */
    440     function crypto_pwhash_str_verify($passwd, $hash)
    441     {
     539    function crypto_pwhash_str_verify(
     540        #[\SensitiveParameter]
     541        $passwd,
     542        #[\SensitiveParameter]
     543        $hash
     544    ) {
    442545        return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash);
    443546    }
     
    455558     * @throws \TypeError
    456559     */
    457     function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit)
    458     {
     560    function crypto_pwhash_scryptsalsa208sha256(
     561        $outlen,
     562        #[\SensitiveParameter]
     563        $passwd,
     564        #[\SensitiveParameter]
     565        $salt,
     566        $opslimit,
     567        $memlimit
     568    ) {
    459569        return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit);
    460570    }
     
    470580     * @throws \TypeError
    471581     */
    472     function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit)
    473     {
     582    function crypto_pwhash_scryptsalsa208sha256_str(
     583        #[\SensitiveParameter]
     584        $passwd,
     585        $opslimit,
     586        $memlimit
     587    ) {
    474588        return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit);
    475589    }
     
    484598     * @throws \TypeError
    485599     */
    486     function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash)
    487     {
     600    function crypto_pwhash_scryptsalsa208sha256_str_verify(
     601        #[\SensitiveParameter]
     602        $passwd,
     603        #[\SensitiveParameter]
     604        $hash
     605    ) {
    488606        return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash);
    489607    }
     
    498616     * @throws \TypeError
    499617     */
    500     function crypto_scalarmult($n, $p)
    501     {
     618    function crypto_scalarmult(
     619        #[\SensitiveParameter]
     620        $n,
     621        $p
     622    ) {
    502623        return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p);
    503624    }
     
    511632     * @throws \TypeError
    512633     */
    513     function crypto_scalarmult_base($n)
    514     {
     634    function crypto_scalarmult_base(
     635        #[\SensitiveParameter]
     636        $n
     637    ) {
    515638        return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n);
    516639    }
     
    526649     * @throws \TypeError
    527650     */
    528     function crypto_secretbox($message, $nonce, $key)
    529     {
     651    function crypto_secretbox(
     652        #[\SensitiveParameter]
     653        $message,
     654        $nonce,
     655        #[\SensitiveParameter]
     656        $key
     657    ) {
    530658        return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key);
    531659    }
     
    539667     * @return string|bool
    540668     */
    541     function crypto_secretbox_open($message, $nonce, $key)
    542     {
     669    function crypto_secretbox_open(
     670        $message,
     671        $nonce,
     672        #[\SensitiveParameter]
     673        $key
     674    ) {
    543675        try {
    544676            return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key);
     
    559691     * @throws \TypeError
    560692     */
    561     function crypto_shorthash($message, $key = '')
    562     {
     693    function crypto_shorthash(
     694        $message,
     695        #[\SensitiveParameter]
     696        $key = ''
     697    ) {
    563698        return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key);
    564699    }
     
    573708     * @throws \TypeError
    574709     */
    575     function crypto_sign($message, $sk)
    576     {
     710    function crypto_sign(
     711        $message,
     712        #[\SensitiveParameter]
     713        $sk
     714    ) {
    577715        return ParagonIE_Sodium_Compat::crypto_sign($message, $sk);
    578716    }
     
    587725     * @throws \TypeError
    588726     */
    589     function crypto_sign_detached($message, $sk)
    590     {
     727    function crypto_sign_detached(
     728        $message,
     729        #[\SensitiveParameter]
     730        $sk
     731    ) {
    591732        return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk);
    592733    }
     
    630771     * @throws \TypeError
    631772     */
    632     function crypto_sign_publickey($keypair)
    633     {
     773    function crypto_sign_publickey(
     774        #[\SensitiveParameter]
     775        $keypair
     776    ) {
    634777        return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair);
    635778    }
     
    643786     * @throws \TypeError
    644787     */
    645     function crypto_sign_publickey_from_secretkey($sk)
    646     {
     788    function crypto_sign_publickey_from_secretkey(
     789        #[\SensitiveParameter]
     790        $sk
     791    ) {
    647792        return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk);
    648793    }
     
    656801     * @throws \TypeError
    657802     */
    658     function crypto_sign_secretkey($keypair)
    659     {
     803    function crypto_sign_secretkey(
     804        #[\SensitiveParameter]
     805        $keypair
     806    ) {
    660807        return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair);
    661808    }
     
    669816     * @throws \TypeError
    670817     */
    671     function crypto_sign_seed_keypair($seed)
    672     {
     818    function crypto_sign_seed_keypair(
     819        #[\SensitiveParameter]
     820        $seed
     821    ) {
    673822        return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed);
    674823    }
     
    710859     * @throws \TypeError
    711860     */
    712     function crypto_sign_ed25519_sk_to_curve25519($sk)
    713     {
     861    function crypto_sign_ed25519_sk_to_curve25519(
     862        #[\SensitiveParameter]
     863        $sk
     864    ) {
    714865        return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk);
    715866    }
     
    725876     * @throws \TypeError
    726877     */
    727     function crypto_stream($len, $nonce, $key)
    728     {
     878    function crypto_stream(
     879        $len,
     880        $nonce,
     881        #[\SensitiveParameter]
     882        $key
     883    ) {
    729884        return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key);
    730885    }
     
    740895     * @throws \TypeError
    741896     */
    742     function crypto_stream_xor($message, $nonce, $key)
    743     {
     897    function crypto_stream_xor(
     898        #[\SensitiveParameter]
     899        $message,
     900        $nonce,
     901        #[\SensitiveParameter]
     902        $key
     903    ) {
    744904        return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
    745905    }
     
    753913     * @throws \TypeError
    754914     */
    755     function hex2bin($string)
    756     {
     915    function hex2bin(
     916        #[\SensitiveParameter]
     917        $string
     918    ) {
    757919        return ParagonIE_Sodium_Compat::hex2bin($string);
    758920    }
     
    767929     * @throws \TypeError
    768930     */
    769     function memcmp($a, $b)
    770     {
     931    function memcmp(
     932        #[\SensitiveParameter]
     933        $a,
     934        #[\SensitiveParameter]
     935        $b
     936    ) {
    771937        return ParagonIE_Sodium_Compat::memcmp($a, $b);
    772938    }
     
    784950     * @psalm-suppress ReferenceConstraintViolation
    785951     */
    786     function memzero(&$str)
    787     {
     952    function memzero(
     953        #[\SensitiveParameter]
     954        &$str
     955    ) {
    788956        ParagonIE_Sodium_Compat::memzero($str);
    789957    }
Note: See TracChangeset for help on using the changeset viewer.