Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
is_zero example
public
static
function
scalar_random
(
)
{
do
{
$r
= ParagonIE_Sodium_Compat::
randombytes_buf
(
self::SCALAR_BYTES
)
;
$r
[
self::SCALAR_BYTES - 1
]
= self::
intToChr
(
self::
chrToInt
(
$r
[
self::SCALAR_BYTES - 1
]
)
& 0x1f
)
;
}
while
(
!self::
check_S_lt_L
(
$r
)
|| ParagonIE_Sodium_Compat::
is_zero
(
$r
)
)
;
return
$r
;
}
/** * @param string $s * @return string * @throws SodiumException */
public
static
function
scalar_negate
(
$s
)
{
$result
= self::
ristretto255_frombytes
(
$p
)
;
if
(
$result
[
'res'
]
!== 0
)
{
throw
new
SodiumException
(
'Could not multiply points'
)
;
}
$P
=
$result
[
'h'
]
;
$t
= self::
stringToIntArray
(
$n
)
;
$t
[
31
]
&= 0x7f;
$Q
= self::
ge_scalarmult
(
self::
intArrayToString
(
$t
)
,
$P
)
;
$q
= self::
ristretto255_p3_tobytes
(
$Q
)
;
if
(
ParagonIE_Sodium_Compat::
is_zero
(
$q
)
)
{
throw
new
SodiumException
(
'An unknown error has occurred'
)
;
}
return
$q
;
}
/** * @param string $n * @return string * @throws SodiumException */
public
static
function
scalarmult_ristretto255_base
(
$n
)
{