• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 
3 // Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
4 
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #include <fcntl.h>
12 #include <string.h>
13 #include <stdlib.h>
14 
main(int argc,char ** argv)15 int main(int argc, char **argv)
16 {
17 	int i,j;
18 	char buffer[0x100];
19 	unsigned int buf[32];
20 	int *tmp = buf;
21 	FILE *fp1 = NULL;
22 	char *input_file = argv[1];
23 
24 	printf("==================================================================================\n");
25 	if (argc != 2) {
26 		printf("input err!!!!!!!!!!!!!!!! \n");
27 		printf("usage: %s filename\n",argv[0]);
28 		exit(-1);
29 	}
30 	printf("input_file:%s\n",input_file);
31 
32 	fp1 = fopen(input_file, "r");
33 	if (fp1 == NULL) {
34 		printf("open file failed!\n");
35 		return -1;
36 	}
37 
38 	sprintf(buffer,"cat %s",input_file);
39 	printf("%s\n",buffer);
40 	printf("==================================================================================\n");
41 	system(buffer);
42 	printf("==================================================================================\n");
43 
44 	fscanf(fp1,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
45 			tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8, tmp + 9, tmp + 10, tmp + 11,
46 			tmp + 12, tmp + 13, tmp + 14, tmp + 15);
47 	tmp += 16;
48 
49 	fscanf(fp1,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
50 			tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8, tmp + 9, tmp + 10, tmp + 11,
51 			tmp + 12, tmp + 13, tmp + 14, tmp + 15);
52 	printf("==================================================================================\n");
53 	printf("SHA256:\n");
54 	for (i = 0; i < 32; i++)
55 		printf("%02x", buf[i]);
56 	printf("\n");
57 	printf("==================================================================================\n");
58 
59 	printf("==================================================================================\n");
60 	printf("REG VALUE:\n");
61 	for (i = 0; i < 8; i++) {
62 		for (j = 3; j >= 0; j--) {
63 			if (j == 3)
64 				printf("rootkey_hash[%0d]=mw 0x100900%02x 0x", i, (i * 4) + 0xc);
65 			printf("%02x", buf[i * 4 + j]);
66 			if (j == 0)
67 				printf("\n");
68 		}
69 	}
70 	printf("==================================================================================\n");
71 
72 	fclose(fp1);
73 	return 0;
74 }
75 
76