@@ -240,20 +240,19 @@ public function crypto_box_open($ciphertext, $length, $nonce, $publickey, $priva
240
240
* Generates a secret key and a corresponding public key.
241
241
*
242
242
* @param mixed 32 byte random string
243
- * @param string hash algorithm
244
243
* @return array private key, public key
245
244
*/
246
- public function crypto_sign_keypair ($ seed = null , $ algo = ' sha512 ' ) {
245
+ public function crypto_sign_keypair ($ seed = null ) {
247
246
if ($ seed === null ) {
248
247
$ sk = FieldElement::fromString (Salt::randombytes ());
249
248
} else {
250
249
$ sk = Salt::decodeInput ($ seed );
251
- if ($ sk !== Salt::sign_PRIVATEKEY ) {
250
+ if ($ sk-> count () !== Salt::sign_PUBLICKEY ) {
252
251
throw new SaltException ('crypto_sign_keypair: seed must be 32 byte ' );
253
252
}
254
253
}
255
254
256
- $ azDigest = hash ($ algo , $ sk ->toString (), true );
255
+ $ azDigest = hash (' sha512 ' , $ sk ->toString (), true );
257
256
$ az = FieldElement::fromString ($ azDigest );
258
257
$ az [0 ] &= 248 ;
259
258
$ az [31 ] &= 63 ;
@@ -278,10 +277,9 @@ public function crypto_sign_keypair($seed = null, $algo = 'sha512') {
278
277
* @param mixed message to be signed
279
278
* @param int message length to be signed
280
279
* @param mixed private key
281
- * @param string hash algorithm
282
280
* @return FieldElement signed message
283
281
*/
284
- public function crypto_sign ($ msg , $ mlen , $ secretkey, $ algo = ' sha512 ' ) {
282
+ public function crypto_sign ($ msg , $ mlen , $ secretkey ) {
285
283
$ sk = Salt::decodeInput ($ secretkey );
286
284
287
285
if ($ sk ->count () !== Salt::sign_PRIVATEKEY) {
@@ -290,7 +288,7 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
290
288
291
289
$ pk = $ sk ->slice (32 , 32 );
292
290
293
- $ azDigest = hash ($ algo , $ sk ->slice (0 ,32 )->toString (), true );
291
+ $ azDigest = hash (' sha512 ' , $ sk ->slice (0 ,32 )->toString (), true );
294
292
$ az = FieldElement::fromString ($ azDigest );
295
293
$ az [0 ] &= 248 ;
296
294
$ az [31 ] &= 63 ;
@@ -302,7 +300,7 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
302
300
$ sm ->copy ($ m , $ mlen , 64 );
303
301
$ sm ->copy ($ az , 32 , 32 , 32 );
304
302
305
- $ nonceDigest = hash ($ algo , $ sm ->slice (32 , $ mlen +32 )->toString (), true );
303
+ $ nonceDigest = hash (' sha512 ' , $ sm ->slice (32 , $ mlen +32 )->toString (), true );
306
304
$ nonce = FieldElement::fromString ($ nonceDigest );
307
305
308
306
$ sm ->copy ($ pk , 32 , 32 );
@@ -313,7 +311,7 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
313
311
$ ed ->geScalarmultBase ($ R , $ nonce );
314
312
$ ed ->GeExtendedtoBytes ($ sm , $ R );
315
313
316
- $ hramDigest = hash ($ algo , $ sm ->toString (), true );
314
+ $ hramDigest = hash (' sha512 ' , $ sm ->toString (), true );
317
315
$ hram = FieldElement::fromString ($ hramDigest );
318
316
$ ed ->scReduce ($ hram );
319
317
@@ -330,10 +328,9 @@ public function crypto_sign($msg, $mlen, $secretkey, $algo = 'sha512') {
330
328
* @param mixed signed message
331
329
* @param int signed message length
332
330
* @param mixed signer's public key
333
- * @param string hash algorithm
334
331
* @return mixed
335
332
*/
336
- public function crypto_sign_open ($ signedmsg , $ smlen , $ publickey, $ algo = ' sha512 ' ) {
333
+ public function crypto_sign_open ($ signedmsg , $ smlen , $ publickey ) {
337
334
$ sm = Salt::decodeInput ($ signedmsg );
338
335
$ pk = Salt::decodeInput ($ publickey );
339
336
@@ -352,7 +349,7 @@ public function crypto_sign_open($signedmsg, $smlen, $publickey, $algo = 'sha512
352
349
for ($ i = 0 ;$ i < 32 ;++$ i ) $ d |= $ pk [$ i ];
353
350
if ($ d === 0 ) return false ;
354
351
355
- $ hs = hash_init ($ algo );
352
+ $ hs = hash_init (' sha512 ' );
356
353
hash_update ($ hs , $ sm ->slice (0 , 32 )->toString ());
357
354
hash_update ($ hs , $ pk ->toString ());
358
355
hash_update ($ hs , $ sm ->slice (64 , $ smlen -64 )->toString ());
@@ -584,12 +581,11 @@ public static function box_keypair() {
584
581
*
585
582
* @param mixed message to be signed
586
583
* @param mixed sender's secret key
587
- * @param string optional hash algorithm
588
584
* @return FieldElement 64 byte signature
589
585
*/
590
- public static function sign ($ msg , $ secretkey, $ algo = ' sha512 ' ) {
586
+ public static function sign ($ msg , $ secretkey ) {
591
587
$ 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 );
593
589
return $ sm ->slice (0 , 64 );
594
590
}
595
591
@@ -602,25 +598,24 @@ public static function sign($msg, $secretkey, $algo = 'sha512') {
602
598
* @param string optional hash algorithm
603
599
* @return bool
604
600
*/
605
- public static function sign_verify ($ msg , $ signature , $ publickey, $ algo = ' sha512 ' ) {
601
+ public static function sign_verify ($ msg , $ signature , $ publickey ) {
606
602
$ sm = Salt::decodeInput ($ signature );
607
603
$ m = Salt::decodeInput ($ msg );
608
604
$ sm ->setSize ($ sm ->count () + $ m ->count ());
609
605
$ sm ->copy ($ m , $ m ->count , 64 );
610
606
$ 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 );
612
608
return ($ ret !== false );
613
609
}
614
610
615
611
/**
616
612
* Generates a secret key and a corresponding public key.
617
613
*
618
614
* @param mixed optional random 32 byte
619
- * @param string optional hash algorithm
620
615
* @return array secret key, public key
621
616
*/
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 );
624
619
}
625
620
626
621
/**
0 commit comments