1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <fcntl.h>
25 #include <string.h>
26 #include <stdlib.h>
27
main(int argc,char ** argv)28 int main(int argc, char **argv)
29 {
30 int i,j;
31 char buffer[0x100];
32 unsigned int buf[32];
33 int *tmp = buf;
34 FILE *fp1 = NULL;
35 char *input_file = argv[1];
36
37 printf("==================================================================================\n");
38 if (argc != 2) {
39 printf("input err!!!!!!!!!!!!!!!! \n");
40 printf("usage: %s filename\n",argv[0]);
41 exit(-1);
42 }
43 printf("input_file:%s\n",input_file);
44
45 fp1 = fopen(input_file, "r");
46 if (fp1 == NULL) {
47 printf("open file failed!\n");
48 return -1;
49 }
50
51 sprintf(buffer,"cat %s",input_file);
52 printf("%s\n",buffer);
53 printf("==================================================================================\n");
54 system(buffer);
55 printf("==================================================================================\n");
56
57 fscanf(fp1,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
58 tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8, tmp + 9, tmp + 10, tmp + 11,
59 tmp + 12, tmp + 13, tmp + 14, tmp + 15);
60 tmp += 16;
61
62 fscanf(fp1,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
63 tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8, tmp + 9, tmp + 10, tmp + 11,
64 tmp + 12, tmp + 13, tmp + 14, tmp + 15);
65 printf("==================================================================================\n");
66 printf("SHA256:\n");
67 for (i = 0; i < 32; i++)
68 printf("%02x", buf[i]);
69 printf("\n");
70 printf("==================================================================================\n");
71
72 printf("==================================================================================\n");
73 printf("REG VALUE:\n");
74 for (i = 0; i < 8; i++) {
75 for (j = 3; j >= 0; j--) {
76 if (j == 3)
77 printf("rootkey_hash[%0d]=mw 0x100900%02x 0x", i, (i * 4) + 0xc);
78 printf("%02x", buf[i * 4 + j]);
79 if (j == 0)
80 printf("\n");
81 }
82 }
83 printf("==================================================================================\n");
84
85 fclose(fp1);
86 return 0;
87 }
88
89