-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpseudo_random.c
More file actions
48 lines (36 loc) · 933 Bytes
/
Copy pathpseudo_random.c
File metadata and controls
48 lines (36 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/////////////////////////////////////////////////////////////////////
//
// 疑似乱数生成器
//
// byte_lenバイトの乱数を生成し、それを返す
//
#include <stdio.h>
#include <openssl/evp.h>
unsigned char *pseudo_random(int byte_len)
{
int i,k;
unsigned char *prandom;
RAND_poll();
RAND_load_file("/dev/random",1024);
while (RAND_status() == 0) {
printf("status = 0\n");
RAND_load_file("/dev/random",1024);
}
prandom = (unsigned char *)malloc(sizeof(unsigned char) * byte_len);
RAND_bytes(prandom, byte_len);
printf("prandom = ");
for(i = 0; i < byte_len; i++)
{
printf("%02x", prandom[i]);
}
putchar('\n');
return prandom;
}
/* int main(void){ */
/* int num; */
/* unsigned char *r; */
/* printf("何バイトの乱数を生成します?:"); */
/* scanf("%d", &num); */
/* r = pseudo_random(num); */
/* return 0; */
/* } */