addcerts.c
1.24 KB
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
#include<stdio.h>
#include <bbtoolsapi.h>
int main(int argc, char **argv){
int i;
FILE *file1ptr;
FILE *file2ptr;
FILE *file3ptr;
int numcerts1, numcerts2, numcerts3;
unsigned long tempcert[SIZE_RSA_CERTBLOB_WORDS];
if(argc < 4){
fprintf(stderr,"usage : %s cert1fname cert2fname outputfname \n", argv[0]);
exit(1);
}
file1ptr = fopen(argv[1], "r");
file2ptr = fopen(argv[2], "r");
if((file1ptr ==0) || (file2ptr ==0)){
fprintf(stderr,"cannot open input cert file \n");
exit(1);
}
fread(&numcerts1, 4, 1, file1ptr);
fread(&numcerts2, 4, 1, file2ptr);
numcerts3 = htonl(numcerts1) + htonl(numcerts2);
file3ptr = fopen(argv[3], "w");
if(file3ptr ==0){
fprintf(stderr,"cannot open output cert file \n");
exit(1);
}
numcerts3 = htonl(numcerts3);
fwrite(&numcerts3, 4, 1, file3ptr);
for(i =0; i< htonl(numcerts1); i++){
fread(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file1ptr);
fwrite(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file3ptr);
}
for(i =0; i< htonl(numcerts2); i++){
fread(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file2ptr);
fwrite(tempcert, 4, SIZE_RSA_CERTBLOB_WORDS, file3ptr);
}
fclose(file1ptr);
fclose(file2ptr);
fclose(file3ptr);
return 0;
}