-
Notifications
You must be signed in to change notification settings - Fork 8
/
crypto.c
139 lines (117 loc) · 3.78 KB
/
crypto.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct crypto_struct {
char name[40];
char driver[40];
char module[40];
int priority;
int refcnt;
char selftest[40];
char internal[40];
char type[40];
int block_size;
int min_keysize;
int max_keysize;
int ivsize;
char geniv[40];
int chunksize;
int walksize;
int digest_size;
};
void parse_name_val(char *buf, char *name, char *val)
{
int j;
int namelen = strlen(name);
j = namelen;
while (buf[j] != '\0') {
if ((buf[j] == ':') || (buf[j] == ' ')) {
j ++;
} else {
break;
}
}
strcpy(val, &buf[j]);
}
int main()
{
FILE *fp;
const char *crypto = "/proc/crypto";
struct crypto_struct cr[80];
int j;
int i;
fp = fopen(crypto, "r");
if (!fp) {
return -1;
}
char tmp[40];
char buf[1024];
j = 0;
i = -1;
while (fgets(buf, sizeof(buf), fp)) {
buf[strlen(buf) - 1] = '\0';
if (strstr(buf, "name")) {
i ++;
parse_name_val(buf, "name", cr[i].name);
} else if (strstr(buf, "driver")) {
parse_name_val(buf, "driver", cr[i].driver);
} else if (strstr(buf, "module")) {
parse_name_val(buf, "module", cr[i].module);
} else if (strstr(buf, "priority")) {
parse_name_val(buf, "priority", tmp);
cr[i].priority = atoi(tmp);
} else if (strstr(buf, "refcnt")) {
parse_name_val(buf, "refcnt", tmp);
cr[i].refcnt = atoi(tmp);
} else if (strstr(buf, "selftest")) {
parse_name_val(buf, "selftest", cr[i].selftest);
} else if (strstr(buf, "internal")) {
parse_name_val(buf, "internal", cr[i].internal);
} else if (strstr(buf, "type")) {
parse_name_val(buf, "type", cr[i].type);
} else if (strstr(buf, "blocksize")) {
parse_name_val(buf, "blocksize", tmp);
cr[i].block_size = atoi(tmp);
} else if (strstr(buf, "digestsize")) {
parse_name_val(buf, "digestsize", tmp);
cr[i].digest_size = atoi(tmp);
} else if (strstr(buf, "ivsize")) {
parse_name_val(buf, "ivsize", tmp);
cr[i].ivsize = atoi(tmp);
} else if (strstr(buf, "chunksize")) {
parse_name_val(buf, "chunksize", tmp);
cr[i].chunksize = atoi(tmp);
} else if (strstr(buf, "walksize")) {
parse_name_val(buf, "walksize", tmp);
cr[i].walksize = atoi(tmp);
} else if (strstr(buf, "min keysize")) {
parse_name_val(buf, "min keysize", tmp);
cr[i].min_keysize = atoi(tmp);
} else if (strstr(buf, "max keysize")) {
parse_name_val(buf, "max keysize", tmp);
cr[i].max_keysize = atoi(tmp);
}
}
int crypto_len = i;
printf("crypto: {\n");
for (i = 0; i < crypto_len; i ++) {
printf("\t name: %s\n", cr[i].name);
printf("\t driver: %s\n", cr[i].driver);
printf("\t module: %s\n", cr[i].module);
printf("\t priority: %d\n", cr[i].priority);
printf("\t refcnt: %d\n", cr[i].refcnt);
printf("\t selftest: %s\n", cr[i].selftest);
printf("\t internal: %s\n", cr[i].internal);
printf("\t type: %s\n", cr[i].type);
printf("\t blocksize: %d\n", cr[i].block_size);
printf("\t digest size: %d\n", cr[i].digest_size);
printf("\t ivsize: %d\n", cr[i].ivsize);
printf("\t chunksize: %d\n", cr[i].chunksize);
printf("\t walksize: %d\n", cr[i].walksize);
printf("\t min keysize: %d\n", cr[i].min_keysize);
printf("\t max keysize: %d\n", cr[i].max_keysize);
printf("\n");
}
printf("}\n");
fclose(fp);
}