fe_isnonzero example


    public static function pk_to_curve25519($pk)
    {
        if (self::small_order($pk)) {
            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
            )
        );

    public static function pk_to_curve25519($pk)
    {
        if (self::small_order($pk)) {
            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
            )
        );
        $vxx = self::fe_sq($h->X);
        $vxx = self::fe_mul($vxx$v);
        $check = self::fe_sub($vxx$u); /* vx^2 - u */

        # if (fe_isnonzero(check)) {         # fe_add(check,vxx,u); /* vx^2+u */         # if (fe_isnonzero(check)) {         # return -1;         # }         # fe_mul(h->X,h->X,sqrtm1);         # }         if (self::fe_isnonzero($check)) {
            $check = self::fe_add($vxx$u); /* vx^2 + u */
            if (self::fe_isnonzero($check)) {
                throw new RangeException('Internal check failed.');
            }
            $h->X = self::fe_mul(
                $h->X,
                ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$sqrtm1)
            );
        }

        # if (fe_isnegative(h->X) == (s[31] >> 7)) {
        $vxx = self::fe_sq($h->X);
        $vxx = self::fe_mul($vxx$v);
        $check = self::fe_sub($vxx$u); /* vx^2 - u */

        # if (fe_isnonzero(check)) {         # fe_add(check,vxx,u); /* vx^2+u */         # if (fe_isnonzero(check)) {         # return -1;         # }         # fe_mul(h->X,h->X,sqrtm1);         # }         if (self::fe_isnonzero($check)) {
            $check = self::fe_add($vxx$u); /* vx^2 + u */
            if (self::fe_isnonzero($check)) {
                throw new RangeException('Internal check failed.');
            }
            $h->X = self::fe_mul(
                $h->X,
                ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray(self::$sqrtm1)
            );
        }

        # if (fe_isnegative(h->X) == (s[31] >> 7)) {
Home | Imprint | This part of the site doesn't use cookies.