fe_invert example

throw new SodiumException('Public key is on a small order');
        }
        $A = self::ge_frombytes_negate_vartime(self::substr($pk, 0, 32));
        $p1 = self::ge_mul_l($A);
        if (!self::fe_isnonzero($p1->X)) {
            throw new SodiumException('Unexpected zero result');
        }

        # fe_1(one_minus_y);         # fe_sub(one_minus_y, one_minus_y, A.Y);         # 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),
            
# fe_mul(z2,tmp1,tmp0);             $z2 = self::fe_mul($tmp1$tmp0);
        }

        # fe_cswap(x2,x3,swap);         self::fe_cswap($x2$x3$swap);

        # fe_cswap(z2,z3,swap);         self::fe_cswap($z2$z3$swap);

        # fe_invert(z2,z2);         $z2 = self::fe_invert($z2);

        # fe_mul(x2,x2,z2);         $x2 = self::fe_mul($x2$z2);
        # fe_tobytes(q,x2);         return (string) self::fe_tobytes($x2);
    }

    /** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsY * @param ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsZ * @return ParagonIE_Sodium_Core32_Curve25519_Fe * @throws SodiumException * @throws TypeError */
/** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core_Curve25519_Ge_P3 $h * @return string * @throws SodiumException * @throws TypeError */
    public static function ge_p3_tobytes(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $h)
    {
        $recip = self::fe_invert($h->Z);
        $x = self::fe_mul($h->X, $recip);
        $y = self::fe_mul($h->Y, $recip);
        $s = self::fe_tobytes($y);
        $s[31] = self::intToChr(
            self::chrToInt($s[31]) ^ (self::fe_isnegative($x) << 7)
        );
        return $s;
    }

    /** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core_Curve25519_Ge_P3 $p * @return ParagonIE_Sodium_Core_Curve25519_Ge_P1p1 */
# fe_mul(z2,tmp1,tmp0);             $z2 = self::fe_mul($tmp1$tmp0);
        }

        # fe_cswap(x2,x3,swap);         self::fe_cswap($x2$x3$swap);

        # fe_cswap(z2,z3,swap);         self::fe_cswap($z2$z3$swap);

        # fe_invert(z2,z2);         $z2 = self::fe_invert($z2);

        # fe_mul(x2,x2,z2);         $x2 = self::fe_mul($x2$z2);
        # fe_tobytes(q,x2);         return self::fe_tobytes($x2);
    }

    /** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core_Curve25519_Fe $edwardsY * @param ParagonIE_Sodium_Core_Curve25519_Fe $edwardsZ * @return ParagonIE_Sodium_Core_Curve25519_Fe */
throw new SodiumException('Public key is on a small order');
        }
        $A = self::ge_frombytes_negate_vartime($pk);
        $p1 = self::ge_mul_l($A);
        if (!self::fe_isnonzero($p1->X)) {
            throw new SodiumException('Unexpected zero result');
        }

        # fe_1(one_minus_y);         # fe_sub(one_minus_y, one_minus_y, A.Y);         # 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(
            
/** * @internal You should not use this directly from another application * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $h * @return string * @throws SodiumException * @throws TypeError */
    public static function ge_p3_tobytes(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $h)
    {
        $recip = self::fe_invert($h->Z);
        $x = self::fe_mul($h->X, $recip);
        $y = self::fe_mul($h->Y, $recip);
        $s = self::fe_tobytes($y);
        $s[31] = self::intToChr(
            self::chrToInt($s[31]) ^ (self::fe_isnegative($x) << 7)
        );
        return $s;
    }

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