Exemple #1
0
 /**
  * Generates a secret key and a corresponding public key.
  *
  * @param  mixed   32 byte random string
  * @return array   private key, public key
  */
 public function crypto_sign_keypair($seed = null)
 {
     if ($seed === null) {
         $sk = FieldElement::fromString(Salt::randombytes());
     } else {
         $sk = Salt::decodeInput($seed);
         if ($sk->count() !== Salt::sign_PUBLICKEY) {
             throw new SaltException('crypto_sign_keypair: seed must be 32 byte');
         }
     }
     $azDigest = hash('sha512', $sk->toString(), true);
     $az = FieldElement::fromString($azDigest);
     $az[0] &= 248;
     $az[31] &= 63;
     $az[31] |= 64;
     $ed = Ed25519::instance();
     $A = new GeExtended();
     $pk = new FieldElement(32);
     $ed->geScalarmultBase($A, $az);
     $ed->GeExtendedtoBytes($pk, $A);
     $sk->setSize(64);
     $sk->copy($pk, 32, 32);
     return array($sk, $pk);
 }
Exemple #2
0
<?php

include "../autoload.php";
$key = Salt::randombytes(32);
$nonce = Salt::randombytes(24);
$msg = 'The Salt::secretbox() function encrypts and authenticates a message using secret key and a nonce.';
$chipertext = Salt::secretbox($msg, $nonce, $key);
$plaintext = Salt::secretbox_open($chipertext, $nonce, $key);
if (!$plaintext) {
    echo 'This is a bug';
} else {
    echo $plaintext->toString();
}
echo "\n";