fe_frombytes example

        $e = '' . $n;
        # e[0] &= 248;         $e[0] = self::intToChr(
            self::chrToInt($e[0]) & 248
        );
        # e[31] &= 127;         # e[31] |= 64;         $e[31] = self::intToChr(
            (self::chrToInt($e[31]) & 127) | 64
        );
        # fe_frombytes(x1,p);         $x1 = self::fe_frombytes($p);
        # fe_1(x2);         $x2 = self::fe_1();
        # fe_0(z2);         $z2 = self::fe_0();
        # fe_copy(x3,x1);         $x3 = self::fe_copy($x1);
        # fe_1(z3);         $z3 = self::fe_1();

        # swap = 0;         /** @var int $swap */
        
public static function ge_frombytes_negate_vartime($s)
    {
        static $d = null;
        if (!$d) {
            $d = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$d);
        }

        # fe_frombytes(h->Y,s);         # fe_1(h->Z);         $h = new ParagonIE_Sodium_Core_Curve25519_Ge_P3(
            self::fe_0(),
            self::fe_frombytes($s),
            self::fe_1()
        );

        # fe_sq(u,h->Y);         # fe_mul(v,u,d);         # fe_sub(u,u,h->Z); /* u = y^2-1 */         # fe_add(v,v,h->Z); /* v = dy^2+1 */         $u = self::fe_sq($h->Y);
        /** @var ParagonIE_Sodium_Core_Curve25519_Fe $d */
        $v = self::fe_mul($u$d);
        $u = self::fe_sub($u$h->Z); /* u = y^2 - 1 */
        
ParagonIE_Sodium_Core32_Int32::fromInt(self::$d[8]),
                    ParagonIE_Sodium_Core32_Int32::fromInt(self::$d[9])
                )
            );
        }
        /** @var ParagonIE_Sodium_Core32_Curve25519_Fe $d */

        # fe_frombytes(h->Y,s);         # fe_1(h->Z);         $h = new ParagonIE_Sodium_Core32_Curve25519_Ge_P3(
            self::fe_0(),
            self::fe_frombytes($s),
            self::fe_1()
        );

        # fe_sq(u,h->Y);         # fe_mul(v,u,d);         # fe_sub(u,u,h->Z); /* u = y^2-1 */         # fe_add(v,v,h->Z); /* v = dy^2+1 */         $u = self::fe_sq($h->Y);
        /** @var ParagonIE_Sodium_Core32_Curve25519_Fe $d */
        $v = self::fe_mul($u$d);
        $u = self::fe_sub($u$h->Z); /* u = y^2 - 1 */
        
        $e = '' . $n;
        # e[0] &= 248;         $e[0] = self::intToChr(
            self::chrToInt($e[0]) & 248
        );
        # e[31] &= 127;         # e[31] |= 64;         $e[31] = self::intToChr(
            (self::chrToInt($e[31]) & 127) | 64
        );
        # fe_frombytes(x1,p);         $x1 = self::fe_frombytes($p);
        # fe_1(x2);         $x2 = self::fe_1();
        # fe_0(z2);         $z2 = self::fe_0();
        # fe_copy(x3,x1);         $x3 = self::fe_copy($x1);
        # fe_1(z3);         $z3 = self::fe_1();

        # swap = 0;         /** @var int $swap */
        

    public static function ristretto255_frombytes($s$skipCanonicalCheck = false)
    {
        if (!$skipCanonicalCheck) {
            if (!self::ristretto255_point_is_canonical($s)) {
                throw new SodiumException('S is not canonical');
            }
        }

        $s_ = self::fe_frombytes($s);
        $ss = self::fe_sq($s_); /* ss = s^2 */

        $u1 = self::fe_sub(self::fe_1()$ss); /* u1 = 1-ss */
        $u1u1 = self::fe_sq($u1); /* u1u1 = u1^2 */

        $u2 = self::fe_add(self::fe_1()$ss); /* u2 = 1+ss */
        $u2u2 = self::fe_sq($u2); /* u2u2 = u2^2 */

        $v = self::fe_mul(
            ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$d),
            $u1u1
        );
Home | Imprint | This part of the site doesn't use cookies.