-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmrandom.c
57 lines (44 loc) · 1007 Bytes
/
mrandom.c
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
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
void random_bytes(unsigned char *buf, int len)
{
int i;
for (i = 0; i < len; ++i)
{
//buf[i] = mrand48() >> 24;
buf[i] = (rand()%16);
printf("buf[%d] = %d:%x\n", i, buf[i], buf[i]);
//printf("buf[%d] = %x\n", i, buf[i]);
}
}
void get_rnd_string(char *buf,unsigned char orig[], int len)
{
int i=0;
for(i=0; i<len; i++)
{
sprintf(buf+i,"%x",orig[i]);
}
}
#define DEV_RND_LEN 16
unsigned char pre_dev_rnd[DEV_RND_LEN]= {0};
unsigned char cur_dev_rnd[DEV_RND_LEN]= {0};
void new_dev_rnd()
{
static int flag = 0;
memcpy(pre_dev_rnd,cur_dev_rnd,DEV_RND_LEN);
random_bytes(cur_dev_rnd,DEV_RND_LEN);
if(flag ==0)
{
memcpy(pre_dev_rnd,cur_dev_rnd,DEV_RND_LEN);
flag = 1;
}
return;
}
int main()
{
new_dev_rnd();
char dev_rnd[64] = {0};
get_rnd_string(dev_rnd, cur_dev_rnd, 16);
printf("dev_rnd = %s\n", dev_rnd);
return 0;
}