Example #1
0
err_status_t
ctr_prng_get_octet_string(void *dest, uint32_t len) {
  err_status_t status;

  /* 
   * if we need to re-initialize the prng, do so now 
   *
   * avoid 32-bit overflows by subtracting instead of adding
   */
  if (ctr_prng.octet_count > MAX_PRNG_OUT_LEN - len) {
    status = ctr_prng_init(ctr_prng.rand);    
    if (status)
      return status;
  }
  ctr_prng.octet_count += len;

  /*
   * write prng output 
   */
  status = aes_icm_output(&ctr_prng.state, (uint8_t*)dest, len);
  if (status)
    return status;
  
  return err_status_ok;
}
Example #2
0
err_status_t
ctr_prng_get_octet_string(void *dest, int len) {
  err_status_t status;

  /* 
   * if we need to re-initialize the prng, do so now 
   *
   * we cast to a 64-bit integer in order to avoid overflows
   */
  if ((uint64_t) ctr_prng.octet_count + len > MAX_PRNG_OUT_LEN) {
    status = ctr_prng_init(ctr_prng.rand);    
    if (status)
      return status;
  }
  ctr_prng.octet_count += len;

  /*
   * write prng output 
   */
  status = aes_icm_output(&ctr_prng.state, dest, len);
  if (status)
    return status;
  
  return err_status_ok;
}