sodium_crypto_core_ristretto255_sub subtracts one encoded Ristretto255 point from another and returns the encoded difference.
The examples explain the data format, expected results and the difference between this API and nearby cryptographic operations.
What It Does
The operation is intended for: sodium_crypto_core_ristretto255_sub subtracts one encoded Ristretto255 point from another and returns the encoded difference.
The sodium extension must be enabled.
Syntax and Return Value
sodium_crypto_core_ristretto255_sub(string $p, string $q): string
| Parameter | Purpose |
|---|---|
| $p (string) | Use the PHP signature above to determine the exact expected input type; validate untrusted inputs before calling. |
| $q (string) | Use the PHP signature above to determine the exact expected input type; validate untrusted inputs before calling. |
The declared return type is shown above. Errors can include false results or exceptions depending on this API: Only accept valid encodings and the required fixed byte lengths. These primitives are not safe standalone high-level encryption protocols.
Example 1: Basic Operation
This is low-level group arithmetic; validate byte encodings and never infer an encryption guarantee.
<?php
$p = sodium_crypto_core_ristretto255_from_hash(random_bytes(64));
$q = sodium_crypto_core_ristretto255_from_hash(random_bytes(64));
$result = sodium_crypto_core_ristretto255_sub($p, $q);
var_dump(sodium_crypto_core_ristretto255_is_valid_point($result));
Example 2: A Different Use Case
Check a group identity with a second operation or inspect an encoded point in hex.
<?php
// Check the alternative case.
$p = sodium_crypto_core_ristretto255_from_hash(random_bytes(64));
$q = sodium_crypto_core_ristretto255_from_hash(random_bytes(64));
$result = sodium_crypto_core_ristretto255_sub($p, $q);
var_dump(hash_equals(sodium_crypto_core_ristretto255_sub(sodium_crypto_core_ristretto255_add($p, $q), $q), $p));
Practical Example: Checking the Result
Check a group identity with a second operation or inspect an encoded point in hex.
<?php
// Verify the expected behavior before using results.
$p = sodium_crypto_core_ristretto255_from_hash(random_bytes(64));
$q = sodium_crypto_core_ristretto255_from_hash(random_bytes(64));
$result = sodium_crypto_core_ristretto255_sub($p, $q);
echo bin2hex($result);
Important Behavior and Edge Cases
Only accept valid encodings and the required fixed byte lengths. These primitives are not safe standalone high-level encryption protocols.
The scalar and point encodings are binary, fixed-size values. Group arithmetic is not itself an application-level encryption protocol.
Comparison with Related Functions
| Approach | Key distinction |
|---|---|
| sodium_crypto_core_ristretto255_sub | sodium_crypto_core_ristretto255_sub subtracts one encoded Ristretto255 point from another and returns the encoded difference. |
| Related technique | Use high-level signing, AEAD, or key-exchange interfaces unless implementing a reviewed protocol. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Confusing this operation with a neighboring cryptographic or security mechanism | Use high-level signing, AEAD, or key-exchange interfaces unless implementing a reviewed protocol. |
| Ignoring a security prerequisite or failure case | Only accept valid encodings and the required fixed byte lengths. These primitives are not safe standalone high-level encryption protocols. |
Key Takeaways
- sodium_crypto_core_ristretto255_sub subtracts one encoded Ristretto255 point from another and returns the encoded difference.
- Only accept valid encodings and the required fixed byte lengths. These primitives are not safe standalone high-level encryption protocols.
- Use high-level signing, AEAD, or key-exchange interfaces unless implementing a reviewed protocol.
Apply this behavior to a real application only after confirming the required extension, configuration and failure handling on the deployment runtime.