fe_sq example

# 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);             $x3 = self::fe_add($z3$z2);

            # fe_sub(z2,z3,z2);             $z2 = self::fe_sub($z3$z2);

            # fe_mul(x2,tmp1,tmp0);

    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 */

        $x = self::fe_mul(
            
/** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $Z * @return ParagonIE_Sodium_Core32_Curve25519_Fe * @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);
        
# 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);             $x3 = self::fe_add($z3$z2);

            # fe_sub(z2,z3,z2);             $z2 = self::fe_sub($z3$z2);

            # fe_mul(x2,tmp1,tmp0);


    /** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core_Curve25519_Fe $Z * @return ParagonIE_Sodium_Core_Curve25519_Fe */
    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);
        
Home | Imprint | This part of the site doesn't use cookies.