• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 #define MaxCols 80
29 
getlinetxt(FILE * fp,int line,char * stri)30 int getlinetxt(FILE *fp,int line,char *stri){
31     int i;
32     fseek(fp,0,0);
33     for(i=0;i<line;i++)
34         if(fgets(stri,MaxCols,fp)==NULL)
35             return -2;
36     return strlen(stri);
37 }
38 
main(int argc,char ** argv)39 int main(int argc, char **argv)
40 {
41 	int i,j;
42 	char buffer[0x100];
43 	int buf[32];
44 	int *tmp = buf;
45 	FILE *fp1 = NULL;
46 	char *input_file = argv[1];
47 
48 	printf("==================================================================================\n");
49 	if (argc != 2) {
50 		printf("input err!!!!!!!!!!!!!!!! \n");
51 		printf("usage: %s filename\n",argv[0]);
52 		exit(-1);
53 	}
54 	printf("input_file:%s\n",input_file);
55 
56 	fp1 = fopen(input_file, "r");
57 	if (fp1 == NULL) {
58 		printf("open file failed!\n");
59 		return -1;
60 	}
61 
62     int ii;
63     char tmp_buf[80];
64 #define MAX_ROW 100
65     for(ii=0;ii<MAX_ROW;ii++) {
66         getlinetxt(fp1,ii,tmp_buf);
67             if(memcmp(tmp_buf,"KEY=",4))
68                 continue;
69             else
70                 break;
71     }
72     if(memcmp(tmp_buf,"KEY=",4)) {
73         printf("ERROR: not find KEY=XXXX string!!!\n");
74 	    fclose(fp1);
75     }
76     tmp_buf[79]='\0';
77 
78 	sscanf(tmp_buf,"KEY=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
79 			tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5, tmp + 6, tmp + 7, tmp + 8, tmp + 9, tmp + 10, tmp + 11, tmp + 12, tmp + 13, tmp + 14, tmp + 15,
80 			tmp + 16 + 0, tmp + 16 + 1, tmp + 16 + 2, tmp + 16 + 3, tmp + 16 + 4, tmp + 16 + 5, tmp + 16 + 6, tmp + 16 + 7, tmp + 16 + 8, tmp + 16 + 9, tmp + 16 + 10, tmp + 16 + 11, tmp + 16 + 12, tmp + 16 + 13, tmp + 16 + 14, tmp + 16 + 15
81             );
82 #if 1
83 	printf("==================================================================================\n");
84 	printf("AES KEY:\n");
85 	for (i = 0; i < 32; i++)
86 		printf("%02x", buf[i]);
87 	printf("\n");
88 	printf("==================================================================================\n");
89 #endif
90 	printf("==================================================================================\n");
91 	printf("AES KEY REG VALUE:\n");
92 	for (i = 0; i < 8; i++) {
93 		for (j = 3; j >= 0; j--) {
94 			if (j == 3)
95 				printf("mw 0x100900%02x 0x", (i * 4) + 0xc);
96 			printf("%02x", buf[i * 4 + j]);
97 			if (j == 0)
98 				printf("\n");
99 		}
100 	}
101 	printf("==================================================================================\n");
102 
103 	fclose(fp1);
104 	return 0;
105 }
106 
107