update SVC.

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@303 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
nakasima 2007-10-22 11:26:01 +00:00
parent 823714f88d
commit 395c3f4d5e
7 changed files with 66 additions and 61 deletions

View File

@ -75,8 +75,6 @@ static void dump(const char *str, const void *ptr, u32 length)
OS_TPrintf("\n"); OS_TPrintf("\n");
} }
typedef int RSA_CTX[3];
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: TwlMain Name: TwlMain
@ -88,7 +86,7 @@ typedef int RSA_CTX[3];
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void TwlMain() void TwlMain()
{ {
RSA_CTX ctx; // heapŠÇ—<C387><E28094>î•ñ SVCSignHeapContext ctx; // heapŠÇ—<C387><E28094>î•ñ
u8 md[20]; // calculated by gs_data u8 md[20]; // calculated by gs_data
u8 data[128]; // decrypted by gs_sign u8 data[128]; // decrypted by gs_sign
u8 hash[20]; // decrypted and extructed by gs_sign u8 hash[20]; // decrypted and extructed by gs_sign
@ -108,7 +106,7 @@ void TwlMain()
{ {
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SVC_InitSignHeap(ctx, gs_heap, sizeof(gs_heap)); SVC_InitSignHeap(&ctx, gs_heap, sizeof(gs_heap));
OS_TPrintf("SVC_InitSignHeap was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("SVC_InitSignHeap was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));
} }
@ -118,8 +116,8 @@ void TwlMain()
{ {
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SVC_DecryptoSign(ctx, data, gs_sign, gs_key); SVC_DecryptSign(&ctx, data, gs_sign, gs_key);
OS_TPrintf("SVC_DecryptoSign was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("SVC_DecryptSign was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));
dump("RSA Result:", data, sizeof(data)); dump("RSA Result:", data, sizeof(data));
} }
@ -129,8 +127,8 @@ void TwlMain()
{ {
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SVC_DecryptoSignDER(ctx, hash, gs_sign, gs_key); SVC_DecryptSignDER(&ctx, hash, gs_sign, gs_key);
OS_TPrintf("SVC_DecryptoSignDER was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("SVC_DecryptSignDER was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));
dump("Extracted hash:", hash, sizeof(hash)); dump("Extracted hash:", hash, sizeof(hash));
} }

View File

@ -75,8 +75,6 @@ static void dump(const char *str, const void *ptr, u32 length)
OS_TPrintf("\n"); OS_TPrintf("\n");
} }
typedef int RSA_CTX[3];
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: TwlMain Name: TwlMain
@ -88,7 +86,7 @@ typedef int RSA_CTX[3];
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void TwlMain() void TwlMain()
{ {
RSA_CTX ctx; // heapŠÇ—<C387><E28094>î•ñ SVCSignHeapContext ctx; // heapŠÇ—<C387><E28094>î•ñ
u8 md[20]; // calculated by gs_data u8 md[20]; // calculated by gs_data
u8 data[128]; // decrypted by gs_sign u8 data[128]; // decrypted by gs_sign
u8 hash[20]; // decrypted and extructed by gs_sign u8 hash[20]; // decrypted and extructed by gs_sign
@ -108,7 +106,7 @@ void TwlMain()
{ {
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SVC_InitSignHeap(ctx, gs_heap, sizeof(gs_heap)); SVC_InitSignHeap(&ctx, gs_heap, sizeof(gs_heap));
OS_TPrintf("SVC_InitSignHeap was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("SVC_InitSignHeap was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));
} }
@ -118,8 +116,8 @@ void TwlMain()
{ {
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SVC_DecryptoSign(ctx, data, gs_sign, gs_key); SVC_DecryptSign(&ctx, data, gs_sign, gs_key);
OS_TPrintf("SVC_DecryptoSign was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("SVC_DecryptSign was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));
dump("RSA Result:", data, sizeof(data)); dump("RSA Result:", data, sizeof(data));
} }
@ -129,8 +127,8 @@ void TwlMain()
{ {
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SVC_DecryptoSignDER(ctx, hash, gs_sign, gs_key); SVC_DecryptSignDER(&ctx, hash, gs_sign, gs_key);
OS_TPrintf("SVC_DecryptoSignDER was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("SVC_DecryptSignDER was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));
dump("Extracted hash:", hash, sizeof(hash)); dump("Extracted hash:", hash, sizeof(hash));
} }

View File

@ -53,26 +53,17 @@ static void dump(const char *str, const void *ptr, u32 length)
/* /*
SHA1 API SHA1 API
*/ */
typedef struct SHA1_CTX // 実際には、サイズが同じなら中身は何でも良い static inline void SHA1_Init(SVCSHA1Context *ctx)
{
u32 h0,h1,h2,h3,h4;
u32 Nl,Nh;
u32 data[16];
int num;
void (*sha_block)(struct SHA1_CTX *c, const u8 *W, int num);
}
SHA1_CTX;
static inline void SHA1_Init(SHA1_CTX *ctx)
{ {
if (ctx == NULL) if (ctx == NULL)
return; return;
MI_CpuClear8(ctx, sizeof(SHA1_CTX)); // ctx->sha_block = NULL;
// MI_CpuClear8(ctx, sizeof(SVCSHA1Context));
SVC_SHA1Init(ctx); SVC_SHA1Init(ctx);
} }
static inline void SHA1_Update(SHA1_CTX *ctx, const void* data, u32 len) static inline void SHA1_Update(SVCSHA1Context *ctx, const void* data, u32 len)
{ {
if (ctx == NULL) if (ctx == NULL)
return; return;
@ -81,13 +72,13 @@ static inline void SHA1_Update(SHA1_CTX *ctx, const void* data, u32 len)
SVC_SHA1Update(ctx, data, len); SVC_SHA1Update(ctx, data, len);
} }
static inline void SHA1_GetHash(SHA1_CTX *ctx, u8* md) static inline void SHA1_GetHash(SVCSHA1Context *ctx, u8* md)
{ {
if (ctx == NULL) if (ctx == NULL)
return; return;
if (md == NULL) if (md == NULL)
return; return;
SVC_SHA1GetHash(md, ctx); SVC_SHA1GetHash(ctx, md);
} }
static inline void SHA1_Calc(u8* md, const void* data, u32 len) static inline void SHA1_Calc(u8* md, const void* data, u32 len)
@ -133,7 +124,7 @@ void TwlMain()
{ {
u8 md[20]; u8 md[20];
SHA1_CTX ctx; SVCSHA1Context ctx;
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SHA1_Init(&ctx); SHA1_Init(&ctx);
OS_TPrintf("\nSHA1_Init was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("\nSHA1_Init was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));

View File

@ -53,26 +53,17 @@ static void dump(const char *str, const void *ptr, u32 length)
/* /*
SHA1 API SHA1 API
*/ */
typedef struct SHA1_CTX // 実際には、サイズが同じなら中身は何でも良い static inline void SHA1_Init(SVCSHA1Context *ctx)
{
u32 h0,h1,h2,h3,h4;
u32 Nl,Nh;
u32 data[16];
int num;
void (*sha_block)(struct SHA1_CTX *c, const u8 *W, int num);
}
SHA1_CTX;
static inline void SHA1_Init(SHA1_CTX *ctx)
{ {
if (ctx == NULL) if (ctx == NULL)
return; return;
MI_CpuClear8(ctx, sizeof(SHA1_CTX)); // ctx->sha_block = NULL;
// MI_CpuClear8(ctx, sizeof(SVCSHA1Context));
SVC_SHA1Init(ctx); SVC_SHA1Init(ctx);
} }
static inline void SHA1_Update(SHA1_CTX *ctx, const void* data, u32 len) static inline void SHA1_Update(SVCSHA1Context *ctx, const void* data, u32 len)
{ {
if (ctx == NULL) if (ctx == NULL)
return; return;
@ -81,13 +72,13 @@ static inline void SHA1_Update(SHA1_CTX *ctx, const void* data, u32 len)
SVC_SHA1Update(ctx, data, len); SVC_SHA1Update(ctx, data, len);
} }
static inline void SHA1_GetHash(SHA1_CTX *ctx, u8* md) static inline void SHA1_GetHash(SVCSHA1Context *ctx, u8* md)
{ {
if (ctx == NULL) if (ctx == NULL)
return; return;
if (md == NULL) if (md == NULL)
return; return;
SVC_SHA1GetHash(md, ctx); SVC_SHA1GetHash(ctx, md);
} }
static inline void SHA1_Calc(u8* md, const void* data, u32 len) static inline void SHA1_Calc(u8* md, const void* data, u32 len)
@ -133,7 +124,7 @@ void TwlMain()
DC_FlushAll(); // <20>ðŒ<C3B0>ð»ë¦é DC_FlushAll(); // <20>ðŒ<C3B0>ð»ë¦é
{ {
u8 md[20]; u8 md[20];
SHA1_CTX ctx; SVCSHA1Context ctx;
OSTick begin = OS_GetTick(); OSTick begin = OS_GetTick();
SHA1_Init(&ctx); SHA1_Init(&ctx);
OS_TPrintf("\nSHA1_Init was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); OS_TPrintf("\nSHA1_Init was consumed %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin));

View File

@ -22,37 +22,64 @@
extern "C" { extern "C" {
#endif #endif
int SVC_InitSignHeap( typedef struct
int acmemory_pool[3], {
u32* head;
u32* tail;
u32 size;
}
SVCSignHeapContext;
typedef struct SVCSHA1Context
{
u32 h0,h1,h2,h3,h4;
u32 Nl,Nh;
u32 data[16];
int num;
void (*sha_block)(struct SVCSHA1Context *c, const u8 *W, int num);
}
SVCSHA1Context;
typedef struct
{
void* output;
const void* input;
const void* key;
}
SVCSignBuffers;
void SVC_InitSignHeap(
SVCSignHeapContext* acmemory_pool,
void* heap, void* heap,
unsigned int length unsigned int length
); );
int SVC_DecryptoRSA( int SVC_DecryptRSA(
const void* acmemory_pool, const SVCSignHeapContext* acmemory_pool,
const void* pData, const SVCSignBuffers* pData,
unsigned int* len // 出力サイズ unsigned int* len // 出力サイズ
); );
int SVC_DecryptoSign( int SVC_DecryptSign(
const void* acmemory_pool, const SVCSignHeapContext* acmemory_pool,
void* buffer, // 出力領域 void* buffer, // 出力領域
const void* sgn_ptr, // データへのポインタ const void* sgn_ptr, // データへのポインタ
const void* key_ptr // キーへのポインタ const void* key_ptr // キーへのポインタ
); );
int SVC_DecryptoSignDER( int SVC_DecryptSignDER(
const void* acmemory_pool, const SVCSignHeapContext* acmemory_pool,
void* buffer, // 出力領域 void* buffer, // 出力領域
const void* sgn_ptr, // データへのポインタ const void* sgn_ptr, // データへのポインタ
const void* key_ptr // キーへのポインタ const void* key_ptr // キーへのポインタ
); );
void SVC_SHA1Init( void *c ); void SVC_SHA1Init( SVCSHA1Context *ctx );
void SVC_SHA1Update( void *c, const unsigned char *data, unsigned long len ); void SVC_SHA1Update( SVCSHA1Context *ctx, const unsigned char *data, unsigned long len );
void SVC_SHA1GetHash( unsigned char *md, void *c ); void SVC_SHA1GetHash( SVCSHA1Context *ctx, unsigned char *md );
int SVC_CalcSHA1( void SVC_CalcSHA1(
void* buffer, // 出力領域 void* buffer, // 出力領域
const void* buf, // データへのポインタ const void* buf, // データへのポインタ
unsigned int len // データの長さ unsigned int len // データの長さ

Binary file not shown.

Binary file not shown.