toInt32 example

->addInt64($s4->mulInt64($h4, 27));

            $d4 = $zero
                ->addInt64($h0->mulInt64($r4, 27))
                ->addInt64($h1->mulInt64($r3, 27))
                ->addInt64($h2->mulInt64($r2, 27))
                ->addInt64($h3->mulInt64($r1, 27))
                ->addInt64($h4->mulInt64($r0, 27));

            /* (partial) h %= p */
            $c = $d0->shiftRight(26);
            $h0 = $d0->toInt32()->mask(0x3ffffff);
            $d1 = $d1->addInt64($c);

            $c = $d1->shiftRight(26);
            $h1 = $d1->toInt32()->mask(0x3ffffff);
            $d2 = $d2->addInt64($c);

            $c = $d2->shiftRight(26);
            $h2 = $d2->toInt32()->mask(0x3ffffff);
            $d3 = $d3->addInt64($c);

            $c = $d3->shiftRight(26);
            
$carry7 = $f[7]->shiftRight(25);
        $f[8] = $f[8]->addInt64($carry7);
        $f[7] = $f[7]->subInt64($carry7->shiftLeft(25));

        $carry8 = $f[8]->shiftRight(26);
        $f[9] = $f[9]->addInt64($carry8);
        $f[8] = $f[8]->subInt64($carry8->shiftLeft(26));

        $carry9 = $f[9]->shiftRight(25);
        $f[9] = $f[9]->subInt64($carry9->shiftLeft(25));

        $h0 = $f[0]->toInt32()->toInt();
        $h1 = $f[1]->toInt32()->toInt();
        $h2 = $f[2]->toInt32()->toInt();
        $h3 = $f[3]->toInt32()->toInt();
        $h4 = $f[4]->toInt32()->toInt();
        $h5 = $f[5]->toInt32()->toInt();
        $h6 = $f[6]->toInt32()->toInt();
        $h7 = $f[7]->toInt32()->toInt();
        $h8 = $f[8]->toInt32()->toInt();
        $h9 = $f[9]->toInt32()->toInt();

        /** * @var array<int, int> */
$h[4] = $h[4]->subInt64($carry4->shiftLeft(26));

        $carry6 = $h[6]->addInt(1 << 25)->shiftRight(26);
        $h[7] = $h[7]->addInt64($carry6);
        $h[6] = $h[6]->subInt64($carry6->shiftLeft(26));

        $carry8 = $h[8]->addInt(1 << 25)->shiftRight(26);
        $h[9] = $h[9]->addInt64($carry8);
        $h[8] = $h[8]->subInt64($carry8->shiftLeft(26));

        for ($i = 0; $i < 10; ++$i) {
            $h[$i] = $h[$i]->toInt32();
        }
        /** @var array<int, ParagonIE_Sodium_Core32_Int32> $h2 */
        $h2 = $h;
        return ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray($h2);
    }

    /** * @internal You should not use this directly from another application * * Inline comments preceded by # are from libsodium's ref10 code. * * @param string $n * @param string $p * @return string * @throws SodiumException * @throws TypeError */
Home | Imprint | This part of the site doesn't use cookies.