函式名稱:sodium_crypto_core_ristretto255_scalar_negate()
函式描述:該函式用於對Ristretto255標量進行取反操作。
適用版本:PHP 7.2.0及以上版本。
用法:
sodium_crypto_core_ristretto255_scalar_negate(string $scalar): string
引數:
- $scalar: 需要取反的Ristretto255標量,必須是一個32位元組的字串。
返回值:
- 返回一個32位元組的字串,表示取反後的Ristretto255標量。
示例:
// 生成一個隨機的Ristretto255標量
$scalar = random_bytes(SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES);
echo '原始標量: ' . bin2hex($scalar) . PHP_EOL;
// 對標量進行取反操作
$negatedScalar = sodium_crypto_core_ristretto255_scalar_negate($scalar);
echo '取反後的標量: ' . bin2hex($negatedScalar) . PHP_EOL;
輸出示例:
原始標量: 3f1d7a0b65e5f0a7d5a4b6a5a2b6d8a5c1e9b5a6b2b3c4d5e6f7a8b9c0d1e2f3
取反後的標量: c0e285f49a1a0f582a5b9a5d5d49f57a3e1645964d4b3b2a1c0d1e2f3
注意事項:
- 在使用該函式之前,必須先呼叫sodium_crypto_core_ristretto255_scalar_invert()函式對標量進行求逆操作。
- 函式使用前需要確保已經載入了sodium擴充套件模組,並且PHP版本符合要求。