host/prandom.c
/** Generate an insecure one-time password.
  * \param otp The generated one-time password will be written here. This must
  *            be a character array with enough space to store #OTP_LENGTH
  *            characters. The OTP will be null-terminated.
  * \warning The password generated by this function has dubious security
  *          properties. Do not use the password for anything private.
  */
Generate an insecure one-time password.
\param otp The generated one-time password will be written here. This must
be a character array with enough space to store #OTP_LENGTH
characters. The OTP will be null-terminated.
\warning The password generated by this function has dubious security
properties. Do not use the password for anything private.
Generate an insecure one - time password . \ param otp The generated one - time password will be written here . This must be a character array with enough space to store #OTP_LENGTH characters . The OTP will be null - terminated . \ warning The password generated by this function has dubious security properties . Do not use the password for anything private .
void generateInsecureOTP(char *otp)
{
    uint8_t random_bytes[32];
    uint8_t dummy_pool_state[ENTROPY_POOL_LENGTH];
    unsigned int i;
    if (getRandom256(random_bytes))
    {
        memset(dummy_pool_state, 42, sizeof(dummy_pool_state));
        if (getRandom256TemporaryPool(random_bytes, dummy_pool_state))
        {
            memset(random_bytes, 42, sizeof(random_bytes));
        }
    }
#if OTP_LENGTH > 32
#error "OTP_LENGTH too big"
#endif  
    for (i = 0; i < (OTP_LENGTH -1); i++)
    {
        otp[i] = (char)('0' + (random_bytes[i] % 10));
    }
    otp[OTP_LENGTH - 1] = '\0';
}
void generateInsecureOTP ( char * otp ) { uint8_t random_bytes [ 32 ] ; uint8_t dummy_pool_state [ ENTROPY_POOL_LENGTH ] ; unsigned int i ; if ( getRandom256 ( random_bytes ) ) { memset ( dummy_pool_state , 42 , sizeof ( dummy_pool_state ) ) ; if ( getRandom256TemporaryPool ( random_bytes , dummy_pool_state ) ) { memset ( random_bytes , 42 , sizeof ( random_bytes ) ) ; } } #if OTP_LENGTH > 32 #error  "OTP_LENGTH too big" #endif for ( i = 0 ; i < ( OTP_LENGTH - 1 ) ; i ++ ) { otp [ i ] = ( char ) ( ' ' + ( random_bytes [ i ] % 10 ) ) ; } otp [ OTP_LENGTH - 1 ] = ' \0 ' ; }
Generate an insecure one-time password.
Generate an insecure one - time password .
/*
         * Sometimes an OTP maybe required when the entropy pool hasn't been
         * initialized yet (eg. when formating storage). In those cases, use
         * a RAM-based dummy entropy pool. This has poor security properties,
         * but then again, this function is called generateInsecureOTP()for
         * a reason.
         */ /*
             * This function must return something, even if it is not quite
             * random.
             */ /* #if OTP_LENGTH > 32 */ /*
         * Each character is approximately uniformly distributed between 0 and
         * 9 (inclusive). Here, "approximately" doesn't matter because this
         * function is insecure.
         */