【发布时间】:2016-04-03 05:44:31
【问题描述】:
我有以下代码使用 ISAAC 生成随机数:
int main()
{
/* Initialize the structure to 0 */
randctx ctx;
ctx.randa = ctx.randb = ctx.randc = (ub4)0;
/* Initialize the seed */
for (ub4 i=0; i<256; ++i) {
ctx.randrsl[i] = i;
}
/* Initialize the random numbers from the seed */
randinit(&ctx, TRUE);
printf("%.8lx\n", rand(&ctx));
}
上面的代码是从How to use ISAAC in C得到的
我还需要从 /dev/random 读取代码以获取种子:
int myFile = open("/dev/random", O_RDONLY);
uint32_t rand;
uint32_t randomNum = read(myFile, &rand, sizeof(rand)) ;
printf(" %u \n", rand);
close(myFile);
如何向 ISAAC 提供种子(即 rand)?
谢谢
【问题讨论】:
标签: c random cryptography