fe_mul example

# fe_sub(tmp1,x2,z2);             $tmp1 = self::fe_sub($x2$z2);

            # fe_add(x2,x2,z2);             $x2 = self::fe_add($x2$z2);

            # fe_add(z2,x3,z3);             $z2 = self::fe_add($x3$z3);

            # fe_mul(z3,tmp0,x2);             $z3 = self::fe_mul($tmp0$x2);

            # fe_mul(z2,z2,tmp1);             $z2 = self::fe_mul($z2$tmp1);

            # fe_sq(tmp0,tmp1);             $tmp0 = self::fe_sq($tmp1);

            # fe_sq(tmp1,x2);             $tmp1 = self::fe_sq($x2);

            # fe_add(x3,z3,z2);

    public static function fe_invert(ParagonIE_Sodium_Core_Curve25519_Fe $Z)
    {
        $z = clone $Z;
        $t0 = self::fe_sq($z);
        $t1 = self::fe_sq($t0);
        $t1 = self::fe_sq($t1);
        $t1 = self::fe_mul($z$t1);
        $t0 = self::fe_mul($t0$t1);
        $t2 = self::fe_sq($t0);
        $t1 = self::fe_mul($t1$t2);
        $t2 = self::fe_sq($t1);
        for ($i = 1; $i < 5; ++$i) {
            $t2 = self::fe_sq($t2);
        }
        $t1 = self::fe_mul($t2$t1);
        $t2 = self::fe_sq($t1);
        for ($i = 1; $i < 10; ++$i) {
            $t2 = self::fe_sq($t2);
        }

    public static function ristretto255_sqrt_ratio_m1(
        ParagonIE_Sodium_Core_Curve25519_Fe $u,
        ParagonIE_Sodium_Core_Curve25519_Fe $v
    ) {
        $sqrtm1 = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$sqrtm1);

        $v3 = self::fe_mul(
            self::fe_sq($v),
            $v
        ); /* v3 = v^3 */
        $x = self::fe_mul(
            self::fe_mul(
                self::fe_sq($v3),
                $u
            ),
            $v
        ); /* x = uv^7 */

        
            $tmp0 = self::fe_sub($x3$z3);
            # fe_sub(tmp1,x2,z2);             $tmp1 = self::fe_sub($x2$z2);

            # fe_add(x2,x2,z2);             $x2 = self::fe_add($x2$z2);

            # fe_add(z2,x3,z3);             $z2 = self::fe_add($x3$z3);

            # fe_mul(z3,tmp0,x2);             $z3 = self::fe_mul($tmp0$x2);

            # fe_mul(z2,z2,tmp1);             $z2 = self::fe_mul($z2$tmp1);

            # fe_sq(tmp0,tmp1);             $tmp0 = self::fe_sq($tmp1);

            # fe_sq(tmp1,x2);             $tmp1 = self::fe_sq($x2);

            # fe_add(x3,z3,z2);
        # fe_invert(one_minus_y, one_minus_y);         $one_minux_y = self::fe_invert(
            self::fe_sub(
                self::fe_1(),
                $A->Y
            )
        );

        # fe_1(x);         # fe_add(x, x, A.Y);         # fe_mul(x, x, one_minus_y);         $x = self::fe_mul(
            self::fe_add(self::fe_1()$A->Y),
            $one_minux_y
        );

        # fe_tobytes(curve25519_pk, x);         return self::fe_tobytes($x);
    }

    /** * @internal You should not use this directly from another application * * @param string $sk * @return string * @throws SodiumException * @throws TypeError */

    public static function fe_invert(ParagonIE_Sodium_Core32_Curve25519_Fe $Z)
    {
        $z = clone $Z;
        $t0 = self::fe_sq($z);
        $t1 = self::fe_sq($t0);
        $t1 = self::fe_sq($t1);
        $t1 = self::fe_mul($z$t1);
        $t0 = self::fe_mul($t0$t1);
        $t2 = self::fe_sq($t0);
        $t1 = self::fe_mul($t1$t2);
        $t2 = self::fe_sq($t1);
        for ($i = 1; $i < 5; ++$i) {
            $t2 = self::fe_sq($t2);
        }
        $t1 = self::fe_mul($t2$t1);
        $t2 = self::fe_sq($t1);
        for ($i = 1; $i < 10; ++$i) {
            $t2 = self::fe_sq($t2);
        }
        $one_minux_y = self::fe_invert(
            self::fe_sub(
                self::fe_1(),
                $A->Y
            )
        );


        # fe_1(x);         # fe_add(x, x, A.Y);         # fe_mul(x, x, one_minus_y);         $x = self::fe_mul(
            self::fe_add(self::fe_1()$A->Y),
            $one_minux_y
        );

        # fe_tobytes(curve25519_pk, x);         return self::fe_tobytes($x);
    }

    /** * @internal You should not use this directly from another application * * @param string $sk * @return string * @throws SodiumException * @throws TypeError */
Home | Imprint | This part of the site doesn't use cookies.