@@ -240,20 +240,19 @@ public function crypto_box_open($ciphertext, $length, $nonce, $publickey, $priva
240240 * Generates a secret key and a corresponding public key.
241241 *
242242 * @param mixed 32 byte random string
243- * @param string hash algorithm
244243 * @return array private key, public key
245244 */
246- public function crypto_sign_keypair ($ seed = null , $ algo = ' sha512 ' ) {
245+ public function crypto_sign_keypair ($ seed = null ) {
247246 if ($ seed === null ) {
248247 $ sk = FieldElement::fromString (Salt::randombytes ());
249248 } else {
250249 $ sk = Salt::decodeInput ($ seed );
251- if ($ sk !== Salt::sign_PRIVATEKEY ) {
250+ if ($ sk-> count () !== Salt::sign_PUBLICKEY ) {
252251 throw new SaltException ('crypto_sign_keypair: seed must be 32 byte ' );
253252 }
254253 }
255254
256- $ azDigest = hash ($ algo , $ sk ->toString (), true );
255+ $ azDigest = hash (' sha512 ' , $ sk ->toString (), true );
257256 $ az = FieldElement::fromString ($ azDigest );
258257 $ az [0 ] &= 248 ;
259258 $ az [31 ] &= 63 ;
@@ -278,10 +277,9 @@ public function crypto_sign_keypair($seed = null, $algo = 'sha512') {
278277 * @param mixed message to be signed
279278 * @param int message length to be signed
280279 * @param mixed private key
281- * @param string hash algorithm
282280 * @return FieldElement signed message
283281 */
284- public function crypto_sign ($ msg , $ mlen , $ secretkey, $ algo = ' sha512 ' ) {
282+ public function crypto_sign ($ msg , $ mlen , $ secretkey ) {
285283 $ sk = Salt::decodeInput ($ secretkey );
286284
287285 if ($ sk ->count () !== Salt::sign_PRIVATEKEY) {
@@ -290,7 +288,7 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
290288
291289 $ pk = $ sk ->slice (32 , 32 );
292290
293- $ azDigest = hash ($ algo , $ sk ->slice (0 ,32 )->toString (), true );
291+ $ azDigest = hash (' sha512 ' , $ sk ->slice (0 ,32 )->toString (), true );
294292 $ az = FieldElement::fromString ($ azDigest );
295293 $ az [0 ] &= 248 ;
296294 $ az [31 ] &= 63 ;
@@ -302,7 +300,7 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
302300 $ sm ->copy ($ m , $ mlen , 64 );
303301 $ sm ->copy ($ az , 32 , 32 , 32 );
304302
305- $ nonceDigest = hash ($ algo , $ sm ->slice (32 , $ mlen +32 )->toString (), true );
303+ $ nonceDigest = hash (' sha512 ' , $ sm ->slice (32 , $ mlen +32 )->toString (), true );
306304 $ nonce = FieldElement::fromString ($ nonceDigest );
307305
308306 $ sm ->copy ($ pk , 32 , 32 );
@@ -313,7 +311,7 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
313311 $ ed ->geScalarmultBase ($ R , $ nonce );
314312 $ ed ->GeExtendedtoBytes ($ sm , $ R );
315313
316- $ hramDigest = hash ($ algo , $ sm ->toString (), true );
314+ $ hramDigest = hash (' sha512 ' , $ sm ->toString (), true );
317315 $ hram = FieldElement::fromString ($ hramDigest );
318316 $ ed ->scReduce ($ hram );
319317
@@ -330,10 +328,9 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
330328 * @param mixed signed message
331329 * @param int signed message length
332330 * @param mixed signer's public key
333- * @param string hash algorithm
334331 * @return mixed
335332 */
336- public function crypto_sign_open ($ signedmsg , $ smlen , $ publickey, $ algo = ' sha512 ' ) {
333+ public function crypto_sign_open ($ signedmsg , $ smlen , $ publickey ) {
337334 $ sm = Salt::decodeInput ($ signedmsg );
338335 $ pk = Salt::decodeInput ($ publickey );
339336
@@ -352,7 +349,7 @@ public function crypto_sign_open($signedmsg, $smlen, $publickey, $algo = 'sha512
352349 for ($ i = 0 ;$ i < 32 ;++$ i ) $ d |= $ pk [$ i ];
353350 if ($ d === 0 ) return false ;
354351
355- $ hs = hash_init ($ algo );
352+ $ hs = hash_init (' sha512 ' );
356353 hash_update ($ hs , $ sm ->slice (0 , 32 )->toString ());
357354 hash_update ($ hs , $ pk ->toString ());
358355 hash_update ($ hs , $ sm ->slice (64 , $ smlen -64 )->toString ());
@@ -584,12 +581,11 @@ public static function box_keypair() {
584581 *
585582 * @param mixed message to be signed
586583 * @param mixed sender's secret key
587- * @param string optional hash algorithm
588584 * @return FieldElement 64 byte signature
589585 */
590- public static function sign ($ msg , $ secretkey, $ algo = ' sha512 ' ) {
586+ public static function sign ($ msg , $ secretkey ) {
591587 $ m = Salt::decodeInput ($ msg );
592- $ sm = Salt::instance ()->crypto_sign ($ m , $ m ->count (), $ secretkey, $ algo );
588+ $ sm = Salt::instance ()->crypto_sign ($ m , $ m ->count (), $ secretkey );
593589 return $ sm ->slice (0 , 64 );
594590 }
595591
@@ -602,25 +598,24 @@ public static function sign($msg, $secretkey, $algo = 'sha512') {
602598 * @param string optional hash algorithm
603599 * @return bool
604600 */
605- public static function sign_verify ($ msg , $ signature , $ publickey, $ algo = ' sha512 ' ) {
601+ public static function sign_verify ($ msg , $ signature , $ publickey ) {
606602 $ sm = Salt::decodeInput ($ signature );
607603 $ m = Salt::decodeInput ($ msg );
608604 $ sm ->setSize ($ sm ->count () + $ m ->count ());
609605 $ sm ->copy ($ m , $ m ->count , 64 );
610606 $ pk = Salt::decodeInput ($ publickey );
611- $ ret = Salt::instance ()->crypto_sign_open ($ sm , $ sm ->count (), $ pk, $ algo );
607+ $ ret = Salt::instance ()->crypto_sign_open ($ sm , $ sm ->count (), $ pk );
612608 return ($ ret !== false );
613609 }
614610
615611 /**
616612 * Generates a secret key and a corresponding public key.
617613 *
618614 * @param mixed optional random 32 byte
619- * @param string optional hash algorithm
620615 * @return array secret key, public key
621616 */
622- public static function sign_keypair ($ seed = null , $ algo = ' sha512 ' ) {
623- return Salt::instance ()->crypto_sign_keypair ($ seed, $ algo );
617+ public static function sign_keypair ($ seed = null ) {
618+ return Salt::instance ()->crypto_sign_keypair ($ seed );
624619 }
625620
626621 /**
0 commit comments