You are here

public static function ParagonIE_Sodium_Core32_Ed25519::pk_to_curve25519 in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core32/Ed25519.php \ParagonIE_Sodium_Core32_Ed25519::pk_to_curve25519()

Parameters

string $pk:

Return value

string

Throws

SodiumException

TypeError

1 call to ParagonIE_Sodium_Core32_Ed25519::pk_to_curve25519()
ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519 in vendor/paragonie/sodium_compat/src/Compat.php
Convert an Ed25519 public key to a Curve25519 public key

File

vendor/paragonie/sodium_compat/src/Core32/Ed25519.php, line 112

Class

ParagonIE_Sodium_Core32_Ed25519
Class ParagonIE_Sodium_Core32_Ed25519

Code

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));

  # 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);
}