You are here

public static function ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519 in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519()

Convert an Ed25519 secret key to a Curve25519 secret key

@psalm-suppress MixedArgument

Parameters

string $sk:

Return value

string

Throws

SodiumException

TypeError

2 calls to ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519()
php72compat.php in vendor/paragonie/sodium_compat/lib/php72compat.php
sodium_compat.php in vendor/paragonie/sodium_compat/lib/sodium_compat.php

File

vendor/paragonie/sodium_compat/src/Compat.php, line 2925

Class

ParagonIE_Sodium_Compat

Code

public static function crypto_sign_ed25519_sk_to_curve25519($sk) {

  /* Type checks: */
  ParagonIE_Sodium_Core_Util::declareScalarType($sk, 'string', 1);

  /* Input validation: */
  if (ParagonIE_Sodium_Core_Util::strlen($sk) < self::CRYPTO_SIGN_SEEDBYTES) {
    throw new SodiumException('Argument 1 must be at least CRYPTO_SIGN_SEEDBYTES long.');
  }
  if (self::useNewSodiumAPI()) {
    if (is_callable('crypto_sign_ed25519_sk_to_curve25519')) {
      return sodium_crypto_sign_ed25519_sk_to_curve25519($sk);
    }
  }
  if (self::use_fallback('crypto_sign_ed25519_sk_to_curve25519')) {
    return (string) call_user_func('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519', $sk);
  }
  $h = hash('sha512', ParagonIE_Sodium_Core_Util::substr($sk, 0, 32), true);
  $h[0] = ParagonIE_Sodium_Core_Util::intToChr(ParagonIE_Sodium_Core_Util::chrToInt($h[0]) & 248);
  $h[31] = ParagonIE_Sodium_Core_Util::intToChr(ParagonIE_Sodium_Core_Util::chrToInt($h[31]) & 127 | 64);
  return ParagonIE_Sodium_Core_Util::substr($h, 0, 32);
}