Beispiel #1
0
 //Generates a vector of secret key
 //Mainly used in testing
 keyV skvGen(size_t rows ) {
     CHECK_AND_ASSERT_THROW_MES(rows > 0, "0 keys requested");
     keyV rv(rows);
     size_t i = 0;
     crypto::rand(rows * sizeof(key), (uint8_t*)&rv[0]);
     for (i = 0 ; i < rows ; i++) {
         sc_reduce32(rv[i].bytes);
     }
     return rv;
 }
Beispiel #2
0
  /* 
   * generate public and secret keys from a random 256-bit integer
   * TODO: allow specifiying random value (for wallet recovery)
   * 
   */
  secret_key crypto_ops::generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover) {
    boost::lock_guard<boost::mutex> lock(random_lock);
    ge_p3 point;

    secret_key rng;

    if (recover)
    {
      rng = recovery_key;
    }
    else
    {
      random_scalar(rng);
    }
    sec = rng;
    sc_reduce32(&sec);  // reduce in case second round of keys (sendkeys)

    ge_scalarmult_base(&point, &sec);
    ge_p3_tobytes(&pub, &point);

    return rng;
  }
 static inline void hash_to_scalar(const void *data, size_t length, ec_scalar &res) {
   cn_fast_hash(data, length, reinterpret_cast<hash &>(res));
   sc_reduce32(&res);
 }
 //generates a random scalar which can be used as a secret key or mask
 void skGen(key &sk) {
     sk = crypto::rand<key>();
     sc_reduce32(sk.bytes);
 }
 key hash_to_scalar(const keyV &keys) {
     key rv = cn_fast_hash(keys);
     sc_reduce32(rv.bytes);
     return rv;
 }
 key hash_to_scalar(ctkeyV PC) {
     key rv = cn_fast_hash(PC);
     sc_reduce32(rv.bytes);
     return rv;
 }
 key hash_to_scalar128(const void * in) {
     key hash = cn_fast_hash128(in);
     sc_reduce32(hash.bytes);
     return hash;
 }
 key hash_to_scalar(const key & in) {
    key hash = cn_fast_hash(in);
    sc_reduce32(hash.bytes);
    return hash;
 }
 void hash_to_scalar(key & hash, const key & in) {
     cn_fast_hash(hash, in);
     sc_reduce32(hash.bytes);
 }
 void hash_to_scalar(key &hash, const void * data, const std::size_t l) {
     cn_fast_hash(hash, data, l);
     sc_reduce32(hash.bytes);
 }
 //generates a random scalar which can be used as a secret key or mask
 key skGen() {
     key sk = crypto::rand<key>();
     sc_reduce32(sk.bytes);
     return sk;
 }