Skip to content

Commit

Permalink
added ED25519_NONDETERMINISTIC check
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Jul 26, 2019
1 parent 7b2a570 commit ae87a8b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/selftest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,32 +132,51 @@ function flipkey_test( $t, $sig, $msg, $publicKey, $curve25519, $text )
$t->test( false === $verify );
}

$R = null;
$sameR = 0;
for( $i = 1; $i <= 12; $i++ )
{
$t->pretest( "sign/verify #$i" );
{
$sig = $curve25519->sign( $msg, $privateKey );
$sameR = isset( $R ) ? $R === substr( $sig, 0, 32 ) : false;
$sameR |= isset( $R ) ? $R === substr( $sig, 0, 32 ) : 0;
$R = substr( $sig, 0, 32 );
$t->test( $curve25519->verify( $sig, $msg, $publicKey ) === true && !$sameR );
$t->test( $curve25519->verify( $sig, $msg, $publicKey ) === true );
}
}

$t->pretest( "sign/verify (same R not used)" );
$t->test( !$sameR );

$t->pretest( 'getSodiumPublicKeyFromPrivateKey' );
{
$sodiumPublicKey = $curve25519->getSodiumPublicKeyFromPrivateKey( $privateKey );
$t->test( $sodiumPublicKey !== $base58->decode( 'EENPV1mRhUD9gSKbcWt84cqnfSGQP5LkCu5gMBfAanYH' ) );
}

$R = null;
$sameR = 0;
for( $i = 1; $i <= 12; $i++ )
{
$t->pretest( "sign/verify (sodium) #$i" );
{
$sig = $curve25519->sign_sodium( $msg, $privateKey );
$sameR |= isset( $R ) ? $R === substr( $sig, 0, 32 ) : 0;
$R = substr( $sig, 0, 32 );
$t->test( $curve25519->verify( $sig, $msg, $sodiumPublicKey ) === true );
}
}

if( defined( 'CURVE25519_SODIUM_SUPPORT' ) )
{
$t->pretest( "sign/verify (sodium with ED25519_NONDETERMINISTIC)" );
$t->test( !$sameR );
}
else if( $sameR )
{
echo 'WARNING: sodium without ED25519_NONDETERMINISTIC' . PHP_EOL;
}

$t->pretest( "sign/verify (rseed) without define()" );
{
$t->test( false === $curve25519->sign( $msg, $privateKey, '123' ) );
Expand Down

0 comments on commit ae87a8b

Please sign in to comment.