Exemple #1
0
 /**
  * Diffie-Hellman, ECDHE, etc.
  * 
  * Get a shared secret from a private key you possess and a public key for
  * the intended message recipient
  * 
  * @param EncryptionSecretKey $privateKey
  * @param EncryptionPublicKey $publicKey
  * @param bool $get_as_object Get as a Key object?
  * @return string
  */
 public static function getSharedSecret(Key $privateKey, Key $publicKey, bool $get_as_object = false)
 {
     if ($get_as_object) {
         return new EncryptionKey(\Sodium\crypto_scalarmult($privateKey->getRawKeyMaterial(), $publicKey->getRawKeyMaterial()));
     }
     return \Sodium\crypto_scalarmult($privateKey->getRawKeyMaterial(), $publicKey->getRawKeyMaterial());
 }
Exemple #2
0
 /**
  * Split a key using HKDF-BLAKE2b
  *
  * @param Key $master
  * @param string $salt
  * @param Config $config
  * @return string[]
  */
 protected static function splitKeys(Key $master, string $salt = '', Config $config = null) : array
 {
     $binary = $master->getRawKeyMaterial();
     return [Util::hkdfBlake2b($binary, \Sodium\CRYPTO_SECRETBOX_KEYBYTES, $config->HKDF_SBOX, $salt), Util::hkdfBlake2b($binary, \Sodium\CRYPTO_AUTH_KEYBYTES, $config->HKDF_AUTH, $salt)];
 }