pike.git / src / post_modules / Nettle / nettle.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/nettle.cmod:322:    /*! @decl string(8bit) random_string(int(0..) len)    *!    *! Generates @[len] amount of pseudo random data. In contrast with    *! the Fortuna PseudoRandomData function, which only allows 2^20    *! bytes of random data per call, the necessary rekey operations    *! are here performed internally, so no such restrictions apply.    */    PIKEFUN string(8bit) random_string(int len)    {    int stored = 0; +  struct pike_string *s; +  uint8_t *str;       if(len<0) Pike_error("Length has to be positive.\n"); -  struct pike_string *s = begin_shared_string(len); -  uint8_t *str = (uint8_t *)s->str; +  +  s = begin_shared_string(len); +  str = (uint8_t *)s->str; +     while( (len-stored) >= 16 )    {    fortuna_generate(str);    stored += 16;    str += 16;       if( !(stored % (1<<20)) )    fortuna_rekey();    }