Code Duplication    Length = 37-37 lines in 2 locations

src/library/sodium_compat/src/Crypto.php 1 location

@@ 477-513 (lines=37) @@
474
     * @param string $keypair
475
     * @return string
476
     */
477
    public static function box_seal_open($message, $keypair)
478
    {
479
        /** @var string $ephemeralPK */
480
        $ephemeralPK = ParagonIE_Sodium_Core_Util::substr($message, 0, 32);
481
482
        /** @var string $ciphertext (ciphertext + MAC) */
483
        $ciphertext = ParagonIE_Sodium_Core_Util::substr($message, 32);
484
485
        /** @var string $secretKey */
486
        $secretKey = self::box_secretkey($keypair);
487
488
        /** @var string $publicKey */
489
        $publicKey = self::box_publickey($keypair);
490
491
        /** @var string $nonce */
492
        $nonce = self::generichash(
493
            $ephemeralPK . $publicKey,
494
            '',
495
            24
496
        );
497
498
        /** @var string $keypair */
499
        $keypair = self::box_keypair_from_secretkey_and_publickey($secretKey, $ephemeralPK);
500
501
        /** @var string $m */
502
        $m = self::box_open($ciphertext, $nonce, $keypair);
503
        try {
504
            ParagonIE_Sodium_Compat::memzero($secretKey);
505
            ParagonIE_Sodium_Compat::memzero($ephemeralPK);
506
            ParagonIE_Sodium_Compat::memzero($nonce);
507
        } catch (Error $ex) {
508
            $secretKey = null;
509
            $ephemeralPK = null;
510
            $nonce = null;
511
        }
512
        return $m;
513
    }
514
515
    /**
516
     * Used by crypto_box() to get the crypto_secretbox() key.

src/library/sodium_compat/src/Crypto32.php 1 location

@@ 477-513 (lines=37) @@
474
     * @param string $keypair
475
     * @return string
476
     */
477
    public static function box_seal_open($message, $keypair)
478
    {
479
        /** @var string $ephemeralPK */
480
        $ephemeralPK = ParagonIE_Sodium_Core32_Util::substr($message, 0, 32);
481
482
        /** @var string $ciphertext (ciphertext + MAC) */
483
        $ciphertext = ParagonIE_Sodium_Core32_Util::substr($message, 32);
484
485
        /** @var string $secretKey */
486
        $secretKey = self::box_secretkey($keypair);
487
488
        /** @var string $publicKey */
489
        $publicKey = self::box_publickey($keypair);
490
491
        /** @var string $nonce */
492
        $nonce = self::generichash(
493
            $ephemeralPK . $publicKey,
494
            '',
495
            24
496
        );
497
498
        /** @var string $keypair */
499
        $keypair = self::box_keypair_from_secretkey_and_publickey($secretKey, $ephemeralPK);
500
501
        /** @var string $m */
502
        $m = self::box_open($ciphertext, $nonce, $keypair);
503
        try {
504
            ParagonIE_Sodium_Compat::memzero($secretKey);
505
            ParagonIE_Sodium_Compat::memzero($ephemeralPK);
506
            ParagonIE_Sodium_Compat::memzero($nonce);
507
        } catch (Error $ex) {
508
            $secretKey = null;
509
            $ephemeralPK = null;
510
            $nonce = null;
511
        }
512
        return $m;
513
    }
514
515
    /**
516
     * Used by crypto_box() to get the crypto_secretbox() key.