mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
genid:フォーマットは変更されないためバージョンを上げるのを中止。
outputSharpID:small fix git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@210 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
4b691fc8dd
commit
d3a9fa08e9
@ -10,8 +10,8 @@ OBJS = $(notdir $(SRCS:.c=.o))
|
|||||||
|
|
||||||
ifeq ($(DEV_CYGWIN),TRUE)
|
ifeq ($(DEV_CYGWIN),TRUE)
|
||||||
|
|
||||||
CC := C:/Cygwin/bin/gcc
|
CC := C:/Cygwin/bin/gcc-3
|
||||||
LD = C:/Cygwin/bin/gcc
|
LD = C:/Cygwin/bin/gcc-3
|
||||||
CFLAGS += -mno-cygwin -DDEV_CYGWIN -Wall -I./
|
CFLAGS += -mno-cygwin -DDEV_CYGWIN -Wall -I./
|
||||||
LDFLAGS += -Wl,--subsystem,console -mwindows -mno-cygwin -L./
|
LDFLAGS += -Wl,--subsystem,console -mwindows -mno-cygwin -L./
|
||||||
LDLIBS += -lgenid
|
LDLIBS += -lgenid
|
||||||
|
|||||||
@ -108,8 +108,8 @@ LDLIBS = -lcrypto -lssl
|
|||||||
MERGE_PROG = merge_lib_objs.plx
|
MERGE_PROG = merge_lib_objs.plx
|
||||||
|
|
||||||
ifeq ($(DEV_CYGWIN),TRUE)
|
ifeq ($(DEV_CYGWIN),TRUE)
|
||||||
CC := C:/Cygwin/bin/gcc
|
CC := C:/Cygwin/bin/gcc-3
|
||||||
LD = C:/Cygwin/bin/gcc
|
LD = C:/Cygwin/bin/gcc-3
|
||||||
CFLAGS += -mno-cygwin -DDEV_CYGWIN
|
CFLAGS += -mno-cygwin -DDEV_CYGWIN
|
||||||
LDFLAGS += -Wl,--subsystem,console -mno-cygwin
|
LDFLAGS += -Wl,--subsystem,console -mno-cygwin
|
||||||
TARGET_DEL = $(TARGET).exe
|
TARGET_DEL = $(TARGET).exe
|
||||||
|
|||||||
@ -137,10 +137,9 @@ extern "C" {
|
|||||||
|
|
||||||
#define ENCRYPT_AES 1 // 定義を有効でFIX.(これが未定義の場合、IDの暗号化がRSAになる。)
|
#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/02/02 Release ver.4
|
||||||
// 2010/03/15 Release ver.5
|
// 2010/03/15 Release ver.5
|
||||||
// TBD -----------------------------------> // 2013/06/XX Release ver.6
|
|
||||||
#ifdef USE_HSM
|
#ifdef USE_HSM
|
||||||
#define CR_GEN_ID_MAGICCODE 0xdeadb00f; /* 最終的にはこちらで動作。0xdeadbeefにするとRSAでコケる。 */
|
#define CR_GEN_ID_MAGICCODE 0xdeadb00f; /* 最終的にはこちらで動作。0xdeadbeefにするとRSAでコケる。 */
|
||||||
#else // !USE_HSM
|
#else // !USE_HSM
|
||||||
|
|||||||
290
trunk/main3.c
290
trunk/main3.c
@ -1,3 +1,27 @@
|
|||||||
|
/*
|
||||||
|
testSharpID に対応したフォーマットで ID の出力を行います。
|
||||||
|
|
||||||
|
*注意1* HSM の使える環境(Linux) で出力したファイルを Windows(Cygwin) で検証する場合、
|
||||||
|
文字コードを Shift-JIS の CR+LF として解釈するためうまくいきません(2つめのレコードでコケる)
|
||||||
|
Windows 側で検証する場合は LF として保存しなおす必要があります。
|
||||||
|
|
||||||
|
*注意2*
|
||||||
|
testSharpID で検証する場合は真の鍵で行う必要があります。
|
||||||
|
そのため testSharpID において
|
||||||
|
|
||||||
|
(1) dummyKey フォルダの dev, prod それぞれに対して
|
||||||
|
eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der を差し替える (他はそのままで OK)
|
||||||
|
|
||||||
|
(2) realKey フォルダの dev, prod それぞれに対して
|
||||||
|
eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der を置く。
|
||||||
|
dummyKey フォルダの dev, prod の NCT2_priv.der, NCT2_priv.pem, NCT2_pub.pem を置く。
|
||||||
|
上記を行った上で Makefile.testSharpID の ifeq ($(USE_DUMMY_KEY),TRUE) endif の間にある
|
||||||
|
DEV_DER_KEY_DIR = ./dummyKey/dev -> ./realKey/dev
|
||||||
|
PROD_DER_KEY_DIR = ./dummyKey/prod -> ./realKey/prod
|
||||||
|
と変更する。
|
||||||
|
|
||||||
|
のいづれかの対応をします。
|
||||||
|
*/
|
||||||
|
|
||||||
#define RAND_MAX 0xffffffff
|
#define RAND_MAX 0xffffffff
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -32,138 +56,152 @@ static struct termios initial_setting, new_setting;
|
|||||||
static int peek_character = -1;
|
static int peek_character = -1;
|
||||||
void keyboard_initialize( void )
|
void keyboard_initialize( void )
|
||||||
{
|
{
|
||||||
tcgetattr( 0, &initial_setting );
|
tcgetattr( 0, &initial_setting );
|
||||||
new_setting = initial_setting;
|
new_setting = initial_setting;
|
||||||
new_setting.c_lflag &= ~ICANON;
|
new_setting.c_lflag &= ~ICANON;
|
||||||
new_setting.c_lflag &= ~ECHO;
|
new_setting.c_lflag &= ~ECHO;
|
||||||
new_setting.c_lflag &= ~ISIG;
|
new_setting.c_lflag &= ~ISIG;
|
||||||
new_setting.c_cc[VMIN] = 0;
|
new_setting.c_cc[VMIN] = 0;
|
||||||
new_setting.c_cc[VTIME] = 0;
|
new_setting.c_cc[VTIME] = 0;
|
||||||
tcsetattr( 0, TCSANOW, &initial_setting );
|
tcsetattr( 0, TCSANOW, &initial_setting );
|
||||||
} // keyboard_initialize
|
} // keyboard_initialize
|
||||||
|
|
||||||
void keyboard_finalize( void )
|
void keyboard_finalize( void )
|
||||||
{
|
{
|
||||||
tcsetattr( 0, TCSANOW, &initial_setting );
|
tcsetattr( 0, TCSANOW, &initial_setting );
|
||||||
} // keyboard_finalize
|
} // keyboard_finalize
|
||||||
|
|
||||||
int kbhit( void )
|
int kbhit( void )
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
int nread;
|
int nread;
|
||||||
|
|
||||||
if ( peek_character != -1 )
|
if ( peek_character != -1 )
|
||||||
return 1;
|
{
|
||||||
new_setting.c_cc[VMIN] = 0;
|
return 1;
|
||||||
tcsetattr( 0, TCSANOW, &new_setting );
|
}
|
||||||
nread = read( 0, &ch, 1 );
|
new_setting.c_cc[VMIN] = 0;
|
||||||
new_setting.c_cc[VMIN] = 1;
|
tcsetattr( 0, TCSANOW, &new_setting );
|
||||||
tcsetattr( 0, TCSANOW, &new_setting );
|
nread = read( 0, &ch, 1 );
|
||||||
|
new_setting.c_cc[VMIN] = 1;
|
||||||
|
tcsetattr( 0, TCSANOW, &new_setting );
|
||||||
|
|
||||||
if ( nread == 1 )
|
if ( nread == 1 )
|
||||||
{
|
{
|
||||||
peek_character = ch;
|
peek_character = ch;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // kbhit
|
} // kbhit
|
||||||
|
|
||||||
int getch( void )
|
int getch( void )
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
if ( peek_character != -1 )
|
if ( peek_character != -1 )
|
||||||
{
|
{
|
||||||
ch = peek_character;
|
ch = peek_character;
|
||||||
peek_character = -1;
|
peek_character = -1;
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
read( 0, &ch, 1 );
|
read( 0, &ch, 1 );
|
||||||
return ch;
|
return ch;
|
||||||
} // readch
|
} // readch
|
||||||
|
|
||||||
#endif // DEV_CYGWIN
|
#endif // DEV_CYGWIN
|
||||||
|
|
||||||
// char *str = "0x11111111";
|
// char *str = "0x11111111";
|
||||||
static int str_to_u32(u32 *num, const char *str)
|
static int str_to_u32(u32 *num, const char *str)
|
||||||
{
|
{
|
||||||
u32 c;
|
u32 c;
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
char *s;
|
char *s;
|
||||||
int hex_mode = 0;
|
int hex_mode = 0;
|
||||||
|
|
||||||
*num = 0;
|
*num = 0;
|
||||||
|
|
||||||
if( *str == '0' && *(str+1) == 'x' ) {
|
if( *str == '0' && *(str+1) == 'x' )
|
||||||
hex_mode = 1;
|
{
|
||||||
s = (char *)(str + 2);
|
hex_mode = 1;
|
||||||
}
|
s = (char *)(str + 2);
|
||||||
else {
|
}
|
||||||
s = (char *)str;
|
else
|
||||||
}
|
{
|
||||||
|
s = (char *)str;
|
||||||
|
}
|
||||||
|
|
||||||
while( *s != '\0' ) {
|
while( *s != '\0' )
|
||||||
|
{
|
||||||
|
|
||||||
if( shift > 8 ) {
|
if( shift > 8 )
|
||||||
return -1; /* error */
|
{
|
||||||
}
|
return -1; /* error */
|
||||||
|
}
|
||||||
|
|
||||||
if( hex_mode ) {
|
if( hex_mode )
|
||||||
if( '0' <= *s && *s <= '9' ) {
|
{
|
||||||
c = (u32)(*s - '0');
|
if( '0' <= *s && *s <= '9' )
|
||||||
}
|
{
|
||||||
else if( 'a' <= *s && *s <= 'f' ) {
|
c = (u32)(*s - '0');
|
||||||
c = (u32)(*s - 'a') + 10;
|
}
|
||||||
}
|
else if( 'a' <= *s && *s <= 'f' )
|
||||||
else if( 'A' <= *s && *s <= 'F' ) {
|
{
|
||||||
c = (u32)(*s - 'A') + 10;
|
c = (u32)(*s - 'a') + 10;
|
||||||
}
|
}
|
||||||
else {
|
else if( 'A' <= *s && *s <= 'F' )
|
||||||
return -1; /* error */
|
{
|
||||||
}
|
c = (u32)(*s - 'A') + 10;
|
||||||
*num <<= 4;
|
}
|
||||||
*num |= c;
|
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)
|
static double gettimeofday_sec(void)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
struct timeval {
|
struct timeval
|
||||||
time_t tv_sec; /* 秒 */
|
{
|
||||||
suseconds_t tv_usec; /* マイクロ秒 */
|
time_t tv_sec; /* 秒 */
|
||||||
};
|
suseconds_t tv_usec; /* マイクロ秒 */
|
||||||
|
};
|
||||||
|
|
||||||
struct timezone {
|
struct timezone
|
||||||
int tz_minuteswest; /* グリニッジ標準時との差 (西方に分単位) */
|
{
|
||||||
int tz_dsttime; /* 夏時間調整の型 */
|
int tz_minuteswest; /* グリニッジ標準時との差 (西方に分単位) */
|
||||||
};
|
int tz_dsttime; /* 夏時間調整の型 */
|
||||||
|
};
|
||||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
|
||||||
|
|
||||||
|
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
gettimeofday(&tv, NULL);
|
return tv.tv_sec + (double)tv.tv_usec*1e-6;
|
||||||
return tv.tv_sec + (double)tv.tv_usec*1e-6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char *argv[])
|
int main(int ac, char *argv[])
|
||||||
@ -218,7 +256,14 @@ int main(int ac, char *argv[])
|
|||||||
}
|
}
|
||||||
else
|
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())
|
if (kbhit())
|
||||||
{
|
{
|
||||||
@ -335,46 +388,11 @@ int main(int ac, char *argv[])
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cr_print_flag = 0;
|
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:
|
end:
|
||||||
// ファイルのクローズ
|
// ファイルのクローズ
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user