The php Function Sodium_Crypto_Scalarmult_Base
The php function sodium_crypto_scalarmult_base generates a salt, a hash algorithm and an optional additional nonce. The resulting hash is then used to verify the contents of an encrypted message, which is often done in conjunction with password_verify() or similar. This prevents the attacker from obtaining a valid or usable plaintext if they intercepted the ciphertext before it was decrypted and verified. The hash includes the salt, so it also provides a means to detect tampering or replay attacks on an authenticated message. This functionality is not available with approaches like mcrypt and most of the ciphers offered by OpenSSL.
In addition to an authenticated asymmetric encryption and decryption, this function supports MAC authentication for messages. This ensures that the message has not been modified or tampered with since it was generated, and is similar to the HMAC functionality in mcrypt and most of the ciphers from OpenSSL.
To use this function, a sender must first create a key pair, containing their private key and recipient's public key. Once the key pair is created, an authentication tag can be generated for a message using their private key and a nonce value (which must be generated each time). This authentication tag is then stored alongside the encrypted text, so that only the message's public key can decrypt it.
The second argument to the function, $additional_data, can be used to provide any other information that you wish to include in the MAC. This additional data will not be encrypted, and may be transmitted alongside the ciphertext in cases where it is required for authenticity. Lastly, the function can take an optional opslimit and memlimit parameter, which can be used to control how much memory is consumed by the function, as well as limit the number of times it can be called from an interactive script or program.