diff --git a/trunk/Makefile.sharp b/trunk/Makefile.sharp index d1d01b8..c4ae3b0 100644 --- a/trunk/Makefile.sharp +++ b/trunk/Makefile.sharp @@ -10,8 +10,8 @@ OBJS = $(notdir $(SRCS:.c=.o)) ifeq ($(DEV_CYGWIN),TRUE) -CC := C:/Cygwin/bin/gcc -LD = C:/Cygwin/bin/gcc +CC := C:/Cygwin/bin/gcc-3 +LD = C:/Cygwin/bin/gcc-3 CFLAGS += -mno-cygwin -DDEV_CYGWIN -Wall -I./ LDFLAGS += -Wl,--subsystem,console -mwindows -mno-cygwin -L./ LDLIBS += -lgenid diff --git a/trunk/Makefile.testSharpID b/trunk/Makefile.testSharpID index ae9f62f..273f174 100644 --- a/trunk/Makefile.testSharpID +++ b/trunk/Makefile.testSharpID @@ -108,8 +108,8 @@ LDLIBS = -lcrypto -lssl MERGE_PROG = merge_lib_objs.plx ifeq ($(DEV_CYGWIN),TRUE) -CC := C:/Cygwin/bin/gcc -LD = C:/Cygwin/bin/gcc +CC := C:/Cygwin/bin/gcc-3 +LD = C:/Cygwin/bin/gcc-3 CFLAGS += -mno-cygwin -DDEV_CYGWIN LDFLAGS += -Wl,--subsystem,console -mno-cygwin TARGET_DEL = $(TARGET).exe diff --git a/trunk/cr_generate_id_private.h b/trunk/cr_generate_id_private.h index e4490e1..087848b 100644 --- a/trunk/cr_generate_id_private.h +++ b/trunk/cr_generate_id_private.h @@ -137,10 +137,9 @@ extern "C" { #define ENCRYPT_AES 1 // 定義を有効でFIX.(これが未定義の場合、IDの暗号化がRSAになる。) -#define CR_GEN_ID_VERSION 6 // シャープへのリリースごとにUPする。 +#define CR_GEN_ID_VERSION 5 // シャープへのリリースごとにUPする。 // 2010/02/02 Release ver.4 // 2010/03/15 Release ver.5 -// TBD -----------------------------------> // 2013/06/XX Release ver.6 #ifdef USE_HSM #define CR_GEN_ID_MAGICCODE 0xdeadb00f; /* 最終的にはこちらで動作。0xdeadbeefにするとRSAでコケる。 */ #else // !USE_HSM diff --git a/trunk/main3.c b/trunk/main3.c index 73ae699..fe0df9c 100644 --- a/trunk/main3.c +++ b/trunk/main3.c @@ -1,3 +1,27 @@ +/* + testSharpID 縺ォ蟇セ蠢懊@縺溘ヵ繧ゥ繝シ繝槭ャ繝医〒 ID 縺ョ蜃コ蜉帙r陦後>縺セ縺吶 + + *豕ィ諢1* HSM 縺ョ菴ソ縺医k迺ー蠅(Linux) 縺ァ蜃コ蜉帙@縺溘ヵ繧。繧、繝ォ繧 Windows(Cygwin) 縺ァ讀懆ィシ縺吶k蝣エ蜷医 + 譁蟄励さ繝シ繝峨r Shift-JIS 縺ョ CR+LF 縺ィ縺励※隗」驥医☆繧九◆繧√≧縺セ縺上>縺阪∪縺帙s(2縺、繧√ョ繝ャ繧ウ繝シ繝峨〒繧ウ繧ア繧) + Windows 蛛エ縺ァ讀懆ィシ縺吶k蝣エ蜷医ッ LF 縺ィ縺励※菫晏ュ倥@縺ェ縺翫☆蠢隕√′縺ゅj縺セ縺吶 + + *豕ィ諢2* + testSharpID 縺ァ讀懆ィシ縺吶k蝣エ蜷医ッ逵溘ョ骰オ縺ァ陦後≧蠢隕√′縺ゅj縺セ縺吶 + 縺昴ョ縺溘a testSharpID 縺ォ縺翫>縺ヲ + + (1) dummyKey 繝輔か繝ォ繝縺ョ dev, prod 縺昴l縺槭l縺ォ蟇セ縺励※ + eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der 繧貞キョ縺玲崛縺医k (莉悶ッ縺昴ョ縺セ縺セ縺ァ OK) + + (2) realKey 繝輔か繝ォ繝縺ョ dev, prod 縺昴l縺槭l縺ォ蟇セ縺励※ + eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der 繧堤スョ縺上 + dummyKey 繝輔か繝ォ繝縺ョ dev, prod 縺ョ NCT2_priv.der, NCT2_priv.pem, NCT2_pub.pem 繧堤スョ縺上 + 荳願ィ倥r陦後▲縺滉ク翫〒 Makefile.testSharpID 縺ョ ifeq ($(USE_DUMMY_KEY),TRUE) endif 縺ョ髢薙↓縺ゅk + DEV_DER_KEY_DIR = ./dummyKey/dev -> ./realKey/dev + PROD_DER_KEY_DIR = ./dummyKey/prod -> ./realKey/prod + 縺ィ螟画峩縺吶k縲 + + 縺ョ縺縺・繧後°縺ョ蟇セ蠢懊r縺励∪縺吶 +*/ #define RAND_MAX 0xffffffff #include @@ -32,138 +56,152 @@ static struct termios initial_setting, new_setting; static int peek_character = -1; void keyboard_initialize( void ) { - tcgetattr( 0, &initial_setting ); - new_setting = initial_setting; - new_setting.c_lflag &= ~ICANON; - new_setting.c_lflag &= ~ECHO; - new_setting.c_lflag &= ~ISIG; - new_setting.c_cc[VMIN] = 0; - new_setting.c_cc[VTIME] = 0; - tcsetattr( 0, TCSANOW, &initial_setting ); + tcgetattr( 0, &initial_setting ); + new_setting = initial_setting; + new_setting.c_lflag &= ~ICANON; + new_setting.c_lflag &= ~ECHO; + new_setting.c_lflag &= ~ISIG; + new_setting.c_cc[VMIN] = 0; + new_setting.c_cc[VTIME] = 0; + tcsetattr( 0, TCSANOW, &initial_setting ); } // keyboard_initialize void keyboard_finalize( void ) { - tcsetattr( 0, TCSANOW, &initial_setting ); + tcsetattr( 0, TCSANOW, &initial_setting ); } // keyboard_finalize int kbhit( void ) { - char ch; - int nread; + char ch; + int nread; if ( peek_character != -1 ) - return 1; - new_setting.c_cc[VMIN] = 0; - tcsetattr( 0, TCSANOW, &new_setting ); - nread = read( 0, &ch, 1 ); - new_setting.c_cc[VMIN] = 1; - tcsetattr( 0, TCSANOW, &new_setting ); + { + return 1; + } + new_setting.c_cc[VMIN] = 0; + tcsetattr( 0, TCSANOW, &new_setting ); + nread = read( 0, &ch, 1 ); + new_setting.c_cc[VMIN] = 1; + tcsetattr( 0, TCSANOW, &new_setting ); - if ( nread == 1 ) - { - peek_character = ch; - return 1; - } + if ( nread == 1 ) + { + peek_character = ch; + return 1; + } - return 0; -} // kbhit + return 0; +} // kbhit int getch( void ) { - char ch; - - if ( peek_character != -1 ) - { - ch = peek_character; - peek_character = -1; - return ch; - } - read( 0, &ch, 1 ); - return ch; -} // readch + char ch; + + if ( peek_character != -1 ) + { + ch = peek_character; + peek_character = -1; + return ch; + } + read( 0, &ch, 1 ); + return ch; +} // readch #endif // DEV_CYGWIN // char *str = "0x11111111"; static int str_to_u32(u32 *num, const char *str) { - u32 c; - int shift = 0; - char *s; - int hex_mode = 0; + u32 c; + int shift = 0; + char *s; + int hex_mode = 0; - *num = 0; + *num = 0; - if( *str == '0' && *(str+1) == 'x' ) { - hex_mode = 1; - s = (char *)(str + 2); - } - else { - s = (char *)str; - } + if( *str == '0' && *(str+1) == 'x' ) + { + hex_mode = 1; + s = (char *)(str + 2); + } + else + { + s = (char *)str; + } - while( *s != '\0' ) { + while( *s != '\0' ) + { - if( shift > 8 ) { - return -1; /* error */ - } + if( shift > 8 ) + { + return -1; /* error */ + } - if( hex_mode ) { - if( '0' <= *s && *s <= '9' ) { - c = (u32)(*s - '0'); - } - else if( 'a' <= *s && *s <= 'f' ) { - c = (u32)(*s - 'a') + 10; - } - else if( 'A' <= *s && *s <= 'F' ) { - c = (u32)(*s - 'A') + 10; - } - else { - return -1; /* error */ - } - *num <<= 4; - *num |= c; + if( hex_mode ) + { + if( '0' <= *s && *s <= '9' ) + { + c = (u32)(*s - '0'); + } + else if( 'a' <= *s && *s <= 'f' ) + { + c = (u32)(*s - 'a') + 10; + } + else if( 'A' <= *s && *s <= 'F' ) + { + c = (u32)(*s - 'A') + 10; + } + else + { + return -1; /* error */ + } + *num <<= 4; + *num |= c; + } + else + { + if( '0' <= *s && *s <= '9' ) + { + c = (u32)(*s - '0'); + } + else + { + return -1; /* error */ + } + *num *= 10; + *num += c; + } + shift++; + s++; } - else { - if( '0' <= *s && *s <= '9' ) { - c = (u32)(*s - '0'); - } - else { - return -1; /* error */ - } - *num *= 10; - *num += c; - } - shift++; - s++; - } - return 0; + return 0; } static double gettimeofday_sec(void) { - struct timeval tv; + struct timeval tv; #if 0 - struct timeval { - time_t tv_sec; /* 遘 */ - suseconds_t tv_usec; /* 繝槭う繧ッ繝ュ遘 */ - }; + struct timeval + { + time_t tv_sec; /* 遘 */ + suseconds_t tv_usec; /* 繝槭う繧ッ繝ュ遘 */ + }; - struct timezone { - int tz_minuteswest; /* 繧ー繝ェ繝九ャ繧ク讓呎コ匁凾縺ィ縺ョ蟾ョ (隘ソ譁ケ縺ォ蛻蜊倅ス) */ - int tz_dsttime; /* 螟乗凾髢楢ェソ謨エ縺ョ蝙 */ - }; - - int gettimeofday(struct timeval *tv, struct timezone *tz); + struct timezone + { + int tz_minuteswest; /* 繧ー繝ェ繝九ャ繧ク讓呎コ匁凾縺ィ縺ョ蟾ョ (隘ソ譁ケ縺ォ蛻蜊倅ス) */ + int tz_dsttime; /* 螟乗凾髢楢ェソ謨エ縺ョ蝙 */ + }; + int gettimeofday(struct timeval *tv, struct timezone *tz); #endif - - gettimeofday(&tv, NULL); - return tv.tv_sec + (double)tv.tv_usec*1e-6; + gettimeofday(&tv, NULL); + return tv.tv_sec + (double)tv.tv_usec*1e-6; } int main(int ac, char *argv[]) @@ -218,7 +256,14 @@ int main(int ac, char *argv[]) } else { - sprintf( path, "output/outputSharpID.txt" ); + if (bonding_option == BONDING_OPTION_DEV) + { + sprintf( path, "output/outputSharpID_Dev.txt" ); + } + else + { + sprintf( path, "output/outputSharpID_Prod.txt" ); + } } // 繝輔ぃ繧、繝ォ繧帝幕縺 @@ -316,8 +361,16 @@ int main(int ac, char *argv[]) } // 譖ク縺崎セシ縺ソ - fprintf( fp, "%08X, %08X %08X, %08X %08X, ", - (unsigned int)device_id[0], (unsigned int)device_id[2], (unsigned int)device_id[1], (unsigned int)device_id[4], (unsigned int)device_id[3] ); + { + int i; + fprintf( fp, "%08X, %08X %08X, %08X %08X, ", + (unsigned int)device_id[0], (unsigned int)device_id[2], (unsigned int)device_id[1], (unsigned int)device_id[4], (unsigned int)device_id[3] ); + for (i = 0; i < CR_ID_BUF_SIZE; i++ ) + { + fprintf( fp, "%02X", id[i] ); + } + fprintf( fp, "\n" ); + } if (kbhit()) { @@ -335,46 +388,11 @@ int main(int ac, char *argv[]) goto end; } } - else - { - cr_print_flag = 0; + else + { + cr_print_flag = 0; + } } - } - - if( ac == 4 ) { - if( 0 == str_to_u32(&device_id[0], argv[1]) && 0 == str_to_u32(&device_id[1], argv[2]) ) { - printf("ID[0] = 0x%08x\n", (unsigned int)device_id[0]); - printf("ID[1] = 0x%08x%08x\n", (unsigned int)device_id[2], (unsigned int)device_id[1] ); - printf("ID[2] = 0x%08x%08x\n", (unsigned int)device_id[4], (unsigned int)device_id[3] ); - fp = fopen( argv[3], "wb" ); - if( fp == NULL ) { - fprintf(stderr, "failed to fopen %s\n",argv[3]); - } - else { - time_start = gettimeofday_sec(); - if( 0 != cr_generate_id( device_id, id, bonding_option ) ) - { - fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n", - (int)device_id[0], (int)device_id[1], (int)device_id[2]); - } - else { - time_end = gettimeofday_sec(); - fwrite(id, CR_ID_BUF_SIZE, 1, fp); - } - fclose(fp); - } - } - else { - goto err_print; - } - } - else { - err_print: - fprintf(stderr,"Invalid argument!\n"); - fprintf(stderr,"Usage: %s\n", argv[0]); - fprintf(stderr,"Usage: %s device_id(32bit) filename.dat\n", argv[0]); - - } end: // 繝輔ぃ繧、繝ォ縺ョ繧ッ繝ュ繝シ繧コ