Exemplo n.º 1
0
int tm_entropy_add (const uint8_t* buf, size_t buf_size)
{
	fortuna_add_entropy(buf, buf_size);

	// Doesn't fail, by default.
	return 0;
}
Exemplo n.º 2
0
static void system_reseed(void) {
    uint8_t buf[1024];
    int n;
    time_t t;
    int skip = 1;

    t = time(NULL);

    if (seed_time == 0)
        skip = 0;
    else if ((t - seed_time) < SYSTEM_RESEED_MIN)
        skip = 1;
    else if ((t - seed_time) > SYSTEM_RESEED_MAX)
        skip = 0;
    else if (check_time == 0 || (t - check_time) > SYSTEM_RESEED_CHECK_TIME) {
        check_time = t;

        /* roll dice */
        prng_get_random_bytes(buf, 1);
        skip = buf[0] >= SYSTEM_RESEED_CHANCE;
    }
    /* clear 1 byte */
    memset(buf, 0, sizeof(buf));

    if (skip)
        return;

    n = prng_acquire_system_randomness(buf);
    if (n > 0)
        fortuna_add_entropy(buf, n);

    seed_time = t;
    memset(buf, 0, sizeof(buf));
}
int
px_add_entropy(const uint8 *data, unsigned count)
{
	system_reseed();
	fortuna_add_entropy(data, count);
	return 0;
}
Exemplo n.º 4
0
//generate 6 different functions and store in memory
void generateRoundFunctions(unsigned char * seed, unsigned int * bufint, int blocks)
{
	int err;
	int i=0;
	int j=0;

	unsigned char buf[4];
	
	//bufint = malloc(blocks*sizeof(unsigned int));

	
	int index = 0;
	prng_state prng; 
	
	if ((err = fortuna_start(&prng)) != CRYPT_OK) {
		printf("start error: %s\n", error_to_string(err));
	}
	if ((err = fortuna_add_entropy(seed, strlen(seed), &prng))!= CRYPT_OK) {
		printf("Add entropy error: %s\n", error_to_string(err));
	}
	if ((err = fortuna_ready(&prng)) != CRYPT_OK) {
		printf("Ready error: %s\n", error_to_string(err));
	}
		

	for(i=0;i<blocks;i++){
			
		fortuna_read(buf,sizeof(buf),&prng);
		bufint[i] = *(unsigned int *)buf;	
	}

}
Exemplo n.º 5
0
/*
 * Add entropy
 */
 void
 random_add(void *xp){
	Proc *up = externup();

	if(waserror()){
		qunlock(&rl);
		nexterror();
	}

	qlock(&rl);
	fortuna_add_entropy(xp, sizeof(xp));
	qunlock(&rl);

	poperror();
 }
Exemplo n.º 6
0
static int sqlcipher_ltc_add_random(void *ctx, void *buffer, int length) {
  int rc = 0;
  int data_to_read = length;
  int block_sz = data_to_read < FORTUNA_MAX_SZ ? data_to_read : FORTUNA_MAX_SZ;
  const unsigned char * data = (const unsigned char *)buffer;
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
  sqlite3_mutex_enter(ltc_rand_mutex);
#endif
    while(data_to_read > 0){
      rc = fortuna_add_entropy(data, block_sz, &prng);
      rc = rc != CRYPT_OK ? SQLITE_ERROR : SQLITE_OK;
      if(rc != SQLITE_OK){
        break;
      }
      data_to_read -= block_sz;
      data += block_sz;
      block_sz = data_to_read < FORTUNA_MAX_SZ ? data_to_read : FORTUNA_MAX_SZ;
    }
    fortuna_ready(&prng);
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
  sqlite3_mutex_leave(ltc_rand_mutex);
#endif
  return rc;
}
Exemplo n.º 7
0
static int sqlcipher_ltc_add_random(void *ctx, void *buffer, int length) {
  ltc_ctx *ltc = (ltc_ctx*)ctx;
  int rc = fortuna_add_entropy(buffer, length, &(ltc->prng));
  return rc != CRYPT_OK ? SQLITE_ERROR : SQLITE_OK;
}