mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
Add first files.
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@1 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
commit
42b718d775
127
LICENSE_en.txt
Normal file
127
LICENSE_en.txt
Normal file
@ -0,0 +1,127 @@
|
||||
|
||||
LICENSE ISSUES
|
||||
==============
|
||||
|
||||
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
|
||||
the OpenSSL License and the original SSLeay license apply to the toolkit.
|
||||
See below for the actual license texts. Actually both licenses are BSD-style
|
||||
Open Source licenses. In case of any license issues related to OpenSSL
|
||||
please contact openssl-core@openssl.org.
|
||||
|
||||
OpenSSL License
|
||||
---------------
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
Original SSLeay License
|
||||
-----------------------
|
||||
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
37
LICENSE_jp.txt
Normal file
37
LICENSE_jp.txt
Normal file
@ -0,0 +1,37 @@
|
||||
OpenSSL ライセンス
|
||||
Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
|
||||
|
||||
ソースおよびバイナリー形式での再配布および使用は、変更の有無に拘らず、次の条件を満たす場合に許可されます。
|
||||
|
||||
ソース・コードを再配布する場合には、上記の著作権表示、この使用条件および以下の免責表示を含める必要があります。
|
||||
バイナリー形式で再配布する場合には、上記の著作権表示、以下の使用条件および免責表示を、配布に際して提供する関連文書および資料に記載する必要があります。
|
||||
このソフトウェアの機能または使用について言及するすべての広告用材料では、次の謝辞を表示する必要があります。「この製品には、OpenSSL Toolkit で使用するために OpenSSL Project によって開発されたソフトウェアが組み込まれています。 (http://www.openssl.org/)」
|
||||
事前の書面による許可がなければ、「OpenSSL Toolkit」と「OpenSSL Project」の名前を、このソフトウェアから派生した製品の承認または促進に使用してはなりません。書面による許可が必要な場合は、openssl-core@openssl.org に連絡してください。
|
||||
OpenSSL Project の事前の書面による許可がなければ、このソフトウェアから派生した製品を「OpenSSL」と呼ぶことはできませんし、また、それらの製品の名前に「OpenSSL」が含まれていてはなりません。
|
||||
いかなる形の再配布にも、次の謝辞を表示する必要があります。「この製品には、OpenSSL Toolkit で使用するために OpenSSL Project によって開発されたソフトウェアが含まれています。(http://www.openssl.org/)」
|
||||
OpenSSL Project は、このソフトウェアを特定物として現存するままの状態で提供し、法律上の瑕疵担保責任、商品性の保証および特定目的適合性の保証を含むすべての明示もしくは黙示の保証責任を負いません。 起こりうる損害について予見の有無を問わず、「ソフトウェア」を使用したために生じる、直接的、間接的、付帯的、特別、懲罰的、または結果的損害 (代替の製品またはサービスの調達、データまたは利益の喪失、事業の中断などを含み、他のいかなる場合も含む) については、それが契約、厳格な責任、不法行為 (過失の場合もそうでない場合も含む) など、いかなる責任の理論においても、OpenSSL Project およびその寄稿者はその責任を負いません。
|
||||
|
||||
この製品には、Eric Young (eay@cryptsoft.com) により作成された暗号化ソフトウェアが含まれています。この製品には、Tim Hudson (tjh@cryptsoft.com) により作成されたソフトウェアが含まれています。
|
||||
|
||||
|
||||
|
||||
SSLeay ライセンス
|
||||
|
||||
Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) All rights reserved.
|
||||
|
||||
このパッケージは、Eric Young (eay@cryptsoft.com) により作成された SSL インプリメンテーションです。このインプリメンテーションは、Netscape SSL に準拠するように作成されています。
|
||||
|
||||
このライブラリーは、以下の条件に従う限り、無料での商業および非商業の使用が許可されます。以下の条件は、単に SSL コードだけでなく、この配布に含まれるすべてのコードに適用されます。この場合、そのコードが RC4、RSA、lhash、DES、などにいずれであっても構いません。この配布に含まれる SSL 資料は、著作権所有者が Tim Hudson (tjh@cryptsoft.com) である点を除き、同一著作権によってカバーされます。
|
||||
|
||||
著作権は Eric Young が所有していますので、コードの著作権表示を除去してはなりません。このパッケージをいずれかの製品に使用する場合は、使用するライブラリー部分の作成者として Eric Young を特定する必要があります。これは、プログラム始動時に、またはこのパッケージと一緒に提供される資料 (オンラインまたはテキスト) にテキスト形式のメッセージとして含めることができます。
|
||||
|
||||
ソースおよびバイナリー形式での再配布および使用は、変更の有無に拘らず、次の条件を満たす場合に許可されます。
|
||||
|
||||
ソース・コードを再配布する場合には、この著作権表示、この使用条件および以下の免責表示を含める必要があります。
|
||||
バイナリー形式で再配布する場合には、上記の著作権表示、以下の使用条件および免責表示を、配布に際して提供する関連文書および資料に記載する必要があります。
|
||||
このソフトウェアの機能と使用に言及するすべての広告用材料では、次のような謝辞を表示する必要があります。「この製品には、Eric Young 氏 (eay@cryptsoft.com) によって作成された暗号ソフトウェアが含まれています」。使用するライブラリーからのルーチンが暗号に関係ない場合は、「暗号」という語を省略することができます。
|
||||
apps ディレクトリー (アプリケーション・コード) からの Windows 固有のコード (またはその派生物) を組み込む場合は、次の謝辞を表示する必要があります。「この製品には、Tim Hudson 氏 (tjh@cryptsoft.com) によって作成されたソフトウェアが含まれています。」
|
||||
Eric Young は、このソフトウェアを特定物として現存するままの状態で提供し、法律上の瑕疵担保責任、商品性の保証および特定目的適合性の保証を含むすべての明示もしくは黙示の保証責任を負いません。 起こりうる損害について予見の有無を問わず、「ソフトウェア」を使用したために生じる、直接的、間接的、付帯的、特別、懲罰的、または結果的損害 (代替の製品またはサービスの調達、データまたは利益の喪失、事業の中断などを含み、他のいかなる場合も含む) については、それが契約、厳格な責任、不法行為 (過失の場合もそうでない場合も含む) など、いかなる責任の理論においても、作成者および寄稿者はその責任を負いません。
|
||||
|
||||
このコードのすべての公開済みバージョンまたは派生物のライセンスおよび配布条件は、変更できません。すなわち、このコードは、単にコピーすることも、他の配布ライセンス (GNU Public Licence も含む) に含めることもできません。
|
||||
|
||||
143
Makefile
Normal file
143
Makefile
Normal file
@ -0,0 +1,143 @@
|
||||
# nm ntd_mem_allocator.o | grep " [T|B|D] "
|
||||
# nm ntd_crypto_ecdsa.o | grep " [T|B|D] "
|
||||
# nm ntd_crypto_rsa.o | grep " [T|B|D] "
|
||||
# nm generate_id.o | grep " [T|B|D] "
|
||||
# nm ../rsa_keysrcgen/rsa1_key.o | grep " [T|B|D] "
|
||||
|
||||
# nFast Path
|
||||
NFAST_PATH = /opt/nfast
|
||||
|
||||
# nFast Developer tools installation
|
||||
NFAST_DEV_PATH = $(NFAST_PATH)/c/ctd/gcc
|
||||
NFAST_EXAMPLES = $(NFAST_PATH)/c/ctd/examples
|
||||
|
||||
# nFast Developer tools library
|
||||
NFAST_LIBPATH = $(NFAST_DEV_PATH)/lib
|
||||
|
||||
# nFast Developer tools include
|
||||
NFAST_INC = $(NFAST_DEV_PATH)/include
|
||||
|
||||
# nFast CPPFLAGS
|
||||
NFAST_CPPFLAGS = \
|
||||
-I$(NFAST_INC)/sworld \
|
||||
-I$(NFAST_INC)/hilibs \
|
||||
-I$(NFAST_INC)/nflog \
|
||||
-I$(NFAST_INC)/cutils \
|
||||
-I$(NFAST_EXAMPLES)/sworld \
|
||||
-I$(NFAST_EXAMPLES)/hilibs \
|
||||
-I$(NFAST_EXAMPLES)/nflog \
|
||||
-I$(NFAST_EXAMPLES)/cutils \
|
||||
|
||||
# nFast LDLIBS
|
||||
NFAST_LDLIBS = \
|
||||
$(NFAST_LIBPATH)/librqcard.a \
|
||||
$(NFAST_LIBPATH)/libnfkm.a \
|
||||
$(NFAST_LIBPATH)/libnfstub.a \
|
||||
$(NFAST_LIBPATH)/libnflog.a \
|
||||
$(NFAST_LIBPATH)/libcutils.a -lm \
|
||||
|
||||
# nFast OBJS
|
||||
NFAST_OBJS_PATH = $(NFAST_EXAMPLES)/nfuser/build-gcc-lib
|
||||
NFAST_OBJS_LIST = \
|
||||
$(NFAST_OBJS_PATH)/simplebignum.o \
|
||||
$(NFAST_OBJS_PATH)/nfutil.o \
|
||||
|
||||
# $(NFAST_OBJS_PATH)/simplebignum.o \
|
||||
|
||||
|
||||
# ダミーのRSA鍵ペアを使用する場合は、USE_DUMMY_KEYをTRUEにしてください。
|
||||
# 正式な RSA鍵ペアを使用する場合は、USE_DUMMY_KEYをコメントアウトして、DER_KEY_DIRにRSA鍵ペアが入ったフォルダを指定してください。
|
||||
|
||||
#USE_DUMMY_KEY = TRUE
|
||||
#ENCRYPT_AES = TRUE
|
||||
|
||||
ifeq ($(USE_DUMMY_KEY),TRUE)
|
||||
DER_KEY_DIR = ./rsakey_dummy
|
||||
else
|
||||
#DER_KEY_DIR = ./rsakey
|
||||
DER_KEY_DIR = ./rsakey_dummy
|
||||
endif
|
||||
|
||||
PACKAGE_DIR = ./package
|
||||
# OPENSSL_DIR = ./openssl-1.0.0-beta2
|
||||
OPENSSL_DIR = ./openssl-0.9.8k
|
||||
|
||||
# SFMT_DIR = ./SFMT-src-1.3.3
|
||||
|
||||
TARGET = gen_id
|
||||
|
||||
KEYS_C = cr_gen_id_rsa_key_priv.c cr_gen_id_rsa_key_pub.c
|
||||
KEYS_H = $(KEYS_C:.c=.h)
|
||||
SRCS = main.c cr_generate_id.c cr_alloc.c $(KEYS_C)
|
||||
|
||||
OBJS = $(notdir $(SRCS:.c=.o))
|
||||
|
||||
|
||||
#DEV_CYGWIN = TRUE
|
||||
ifeq ($(DEV_CYGWIN),TRUE)
|
||||
CC := C:/Cygwin/bin/gcc
|
||||
CFLAGS = -mno-cygwin -Wall -DMEXP=216091 -msse2 -DHAVE_SSE2
|
||||
CPPFLAGS= -I. -I$(OPENSSL_DIR)/include -I$(OPENSSL_DIR)/crypto/ec -I$(SFMT_DIR)
|
||||
else
|
||||
CC := /usr/bin/gcc
|
||||
CFLAGS = -Wall -DMEXP=216091 -msse2 -DHAVE_SSE2
|
||||
CPPFLAGS = -I. -I$(OPENSSL_DIR)/include -I$(OPENSSL_DIR)/crypto/ec $(NFAST_CPPFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(USE_DUMMY_KEY),TRUE)
|
||||
CFLAGS += -DUSE_DUMMY_KEY
|
||||
endif
|
||||
|
||||
ifeq ($(ENCRYPT_AES),TRUE)
|
||||
CFLAGS += -DENCRYPT_AES
|
||||
endif
|
||||
|
||||
ifeq ($(DEV_CYGWIN),TRUE)
|
||||
LD = C:/Cygwin/bin/gcc
|
||||
LDFLAGS = -Wl,--subsystem,console -mwindows -mno-cygwin -L$(OPENSSL_DIR)
|
||||
LDLIBS = -lcrypto -lssl
|
||||
else
|
||||
LD = /usr/bin/gcc
|
||||
LDFLAGS = -Wl -mwindows -L$(OPENSSL_DIR)
|
||||
LDLIBS = -lcrypto -lssl -ldl -lnsl $(NFAST_LDLIBS)
|
||||
endif
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
all: package_build $(KEYS_C) $(TARGET)
|
||||
|
||||
# install: $(TARGET)
|
||||
# install -c -m 777 $(TARGET) ../bin
|
||||
|
||||
package_build :
|
||||
cd $(PACKAGE_DIR);make
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(LD) $(LDFLAGS) $(OBJS) -o $@ $(LDLIBS) $(NFAST_OBJS_LIST)
|
||||
|
||||
$(OBJS): $(HEADS) Makefile
|
||||
|
||||
# %.o:$(SFMT_DIR)/%.c
|
||||
# $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
%.o:%.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
#%.c:$(DER_KEY_DIR)/%.der
|
||||
# perl tools/bin2c.plx $<
|
||||
|
||||
cr_gen_id_rsa_key_priv.c : $(DER_KEY_DIR)/gen_id_rsa_key_priv.der
|
||||
perl tools/bin2c.plx $<
|
||||
|
||||
cr_gen_id_rsa_key_pub.c : $(DER_KEY_DIR)/gen_id_rsa_key_pub.der
|
||||
perl tools/bin2c.plx $<
|
||||
|
||||
|
||||
.PHONY: clean clobber
|
||||
clean:
|
||||
$(RM) $(OBJS) $(TARGET).exe $(KEYS_C) $(KEYS_H)
|
||||
|
||||
clobber:
|
||||
$(RM) $(OBJS) $(TARGET).exe $(KEYS_C) $(KEYS_H)
|
||||
cd $(PACKAGE_DIR);make clobber
|
||||
|
||||
50
Makefile.sharp
Normal file
50
Makefile.sharp
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
# OPENSSL_DIR = ../openssl-1.0.0-beta2
|
||||
OPENSSL_DIR = ../openssl-0.9.8k
|
||||
SFMT_DIR = ../SFMT-src-1.3.3
|
||||
|
||||
USE_SFMT = TRUE
|
||||
|
||||
|
||||
|
||||
TARGET = gen_id
|
||||
|
||||
SRCS = main.c cr_generate_id.c cr_alloc.c cr_gen_id_rsa_key_priv.c cr_gen_id_rsa_key_pub.c $(SFMT_DIR)/SFMT.c
|
||||
|
||||
OBJS = $(notdir $(SRCS:.c=.o))
|
||||
|
||||
CC := C:/Cygwin/bin/gcc
|
||||
|
||||
CFLAGS = -mno-cygwin -Wall
|
||||
|
||||
ifeq ($(USE_SFMT),TRUE)
|
||||
CFLAGS += -DUSE_SFMT -DMEXP=216091 -msse2 -DHAVE_SSE2
|
||||
endif
|
||||
|
||||
CPPFLAGS= -I. -I$(OPENSSL_DIR)/include -I$(OPENSSL_DIR)/crypto/ec -I$(SFMT_DIR)
|
||||
|
||||
LD = C:/Cygwin/bin/gcc
|
||||
LDFLAGS = -Wl,--subsystem,console -mwindows -mno-cygwin -L$(OPENSSL_DIR)
|
||||
LDLIBS = -lcrypto -lssl
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(LD) $(LDFLAGS) $(OBJS) -o $@ $(LDLIBS)
|
||||
|
||||
$(OBJS): $(HEADS) Makefile
|
||||
|
||||
%.o:$(SFMT_DIR)/%.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
%.o:%.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
.PHONY: clean clobber
|
||||
clean clobber:
|
||||
$(RM) $(OBJS) $(TARGET).exe
|
||||
|
||||
|
||||
477
cr_alloc.c
Normal file
477
cr_alloc.c
Normal file
@ -0,0 +1,477 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
typedef int BOOL;
|
||||
typedef signed char s8;
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
#include "cr_alloc.h"
|
||||
|
||||
#define OFFSET(n, a) (((u32) (n)) & ((a) - 1))
|
||||
#define TRUNC(n, a) (((u32) (n)) & ~((a) - 1))
|
||||
#define ROUND(n, a) (((u32) (n) + (a) - 1) & ~((a) - 1))
|
||||
|
||||
#define ALIGNMENT 32 // alignment in bytes
|
||||
#define MINOBJSIZE (HEADERSIZE + ALIGNMENT) // smallest object
|
||||
#define HEADERSIZE ROUND(sizeof(Cell), ALIGNMENT)
|
||||
|
||||
//---- InRange(): True if a <= targ < b
|
||||
#define InRange(targ, a, b) \
|
||||
((u32)(a) <= (u32)(targ) && (u32)(targ) < (u32)(b))
|
||||
|
||||
//---- RangeOverlap(): True if the ranges a and b overlap in any way.
|
||||
#define RangeOverlap(aStart, aEnd, bStart, bEnd) \
|
||||
(((u32)(bStart) <= (u32)(aStart)) && ((u32)(aStart) < (u32)(bEnd)) || \
|
||||
((u32)(bStart) < (u32)(aEnd)) && ((u32)(aEnd) <= (u32)(bEnd)) )
|
||||
|
||||
//---- RangeSubset(): True if range a is a subset of range b
|
||||
// Assume (aStart < aEnd) and (bStart < bEnd)
|
||||
#define RangeSubset(aStart, aEnd, bStart, bEnd) \
|
||||
((u32)(bStart) <= (u32)(aStart) && (u32)(aEnd) <= (u32)(bEnd))
|
||||
|
||||
typedef struct Cell Cell;
|
||||
typedef struct HeapDesc HeapDesc;
|
||||
|
||||
struct Cell {
|
||||
struct Cell *prev;
|
||||
struct Cell *next;
|
||||
long size; // size of object plus HEADERSIZE
|
||||
};
|
||||
|
||||
struct HeapDesc {
|
||||
long size; // if -1 then heap is free. Note OS_AllocFixed()
|
||||
// could make a heap empty.
|
||||
Cell *free; // pointer to the first free cell
|
||||
Cell *allocated; // pointer to the first used cell
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
// volatile because some functions use this as hidden macro parameter
|
||||
void *arenaStart;
|
||||
void *arenaEnd;
|
||||
HeapDesc *heapArray;
|
||||
} OSHeapInfo;
|
||||
|
||||
/*
|
||||
-- heapInfo - arenaStart
|
||||
(OSHeapInfo)
|
||||
-- heapArray --
|
||||
(HeapDesc)
|
||||
-- arenaStart --
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static OSHeapInfo *_sys_heapInfo;
|
||||
|
||||
|
||||
static Cell *DLAddFront(Cell * list, Cell * cell)
|
||||
{
|
||||
cell->next = list;
|
||||
cell->prev = NULL;
|
||||
if (list)
|
||||
{
|
||||
list->prev = cell;
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
static Cell *DLExtract(Cell * list, Cell * cell)
|
||||
{
|
||||
if (cell->next)
|
||||
{
|
||||
cell->next->prev = cell->prev;
|
||||
}
|
||||
|
||||
if (cell->prev == NULL)
|
||||
{
|
||||
return cell->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell->prev->next = cell->next;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
static Cell *DLInsert(Cell * list, Cell * cell)
|
||||
{
|
||||
Cell *prev;
|
||||
Cell *next;
|
||||
|
||||
for (next = list, prev = NULL; next; prev = next, next = next->next)
|
||||
{
|
||||
if (cell <= next)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cell->next = next;
|
||||
cell->prev = prev;
|
||||
if (next)
|
||||
{
|
||||
next->prev = cell;
|
||||
if ((char *)cell + cell->size == (char *)next)
|
||||
{
|
||||
//---- Coalesce forward
|
||||
cell->size += next->size;
|
||||
cell->next = next = next->next;
|
||||
if (next)
|
||||
{
|
||||
next->prev = cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prev)
|
||||
{
|
||||
prev->next = cell;
|
||||
if ((char *)prev + prev->size == (char *)cell)
|
||||
{
|
||||
//---- Coalesce back
|
||||
prev->size += cell->size;
|
||||
prev->next = next;
|
||||
if (next)
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cell; // cell becomes new head of list
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void *cr_alloc_Alloc( u32 size)
|
||||
{
|
||||
OSHeapInfo *heapInfo;
|
||||
HeapDesc *hd;
|
||||
Cell *cell; // candidate block
|
||||
Cell *newCell; // ptr to leftover block
|
||||
long leftoverSize; // size of any leftover
|
||||
|
||||
heapInfo = _sys_heapInfo;
|
||||
|
||||
hd = heapInfo->heapArray;
|
||||
|
||||
// printf("heapArray 2 0x%p\n", hd);
|
||||
|
||||
// Enlarge size to smallest possible cell size
|
||||
size += HEADERSIZE;
|
||||
size = ROUND(size, ALIGNMENT);
|
||||
|
||||
// Search for block large enough
|
||||
for (cell = hd->free; cell != NULL; cell = cell->next)
|
||||
{
|
||||
if ((long)size <= cell->size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cell == NULL)
|
||||
{
|
||||
// miya printf("%s %d\n",__FUNCTION__,__LINE__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
leftoverSize = cell->size - (long)size;
|
||||
if (leftoverSize < MINOBJSIZE)
|
||||
{
|
||||
//---- Just extract this cell out since it's too small to split
|
||||
hd->free = DLExtract(hd->free, cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
//---- cell is large enough to split into two pieces
|
||||
cell->size = (long)size;
|
||||
|
||||
//---- Create a new cell
|
||||
newCell = (Cell *) ((char *)cell + size);
|
||||
newCell->size = leftoverSize;
|
||||
|
||||
//---- Leave newCell in free, and take cell away
|
||||
newCell->prev = cell->prev;
|
||||
newCell->next = cell->next;
|
||||
|
||||
if (newCell->next != NULL)
|
||||
{
|
||||
newCell->next->prev = newCell;
|
||||
}
|
||||
|
||||
if (newCell->prev != NULL)
|
||||
{
|
||||
newCell->prev->next = newCell;
|
||||
}
|
||||
else
|
||||
{
|
||||
// SDK_TASSERTMSG(hd->free == cell, OS_ERR_ALLOCFROMHEAP_BROKENHEAP);
|
||||
hd->free = newCell;
|
||||
}
|
||||
}
|
||||
|
||||
//---- Add to allocated list
|
||||
hd->allocated = DLAddFront(hd->allocated, cell);
|
||||
|
||||
return (void *)((char *)cell + HEADERSIZE);
|
||||
}
|
||||
|
||||
|
||||
static void cr_alloc_Free( void *ptr)
|
||||
{
|
||||
OSHeapInfo *heapInfo;
|
||||
HeapDesc *hd;
|
||||
Cell *cell;
|
||||
|
||||
heapInfo = _sys_heapInfo;
|
||||
|
||||
cell = (Cell *) ((char *)ptr - HEADERSIZE);
|
||||
hd = heapInfo->heapArray;
|
||||
|
||||
hd->allocated = DLExtract(hd->allocated, cell);
|
||||
|
||||
hd->free = DLInsert(hd->free, cell);
|
||||
}
|
||||
|
||||
|
||||
u32 OSi_GetTotalAllocSize(BOOL isHeadInclude)
|
||||
{
|
||||
OSHeapInfo *heapInfo;
|
||||
Cell *cell;
|
||||
u32 sum = 0;
|
||||
|
||||
heapInfo = _sys_heapInfo;
|
||||
|
||||
if (isHeadInclude)
|
||||
{
|
||||
for (cell = heapInfo->heapArray->allocated; cell; cell = cell->next)
|
||||
{
|
||||
sum += (u32)(cell->size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (cell = heapInfo->heapArray->allocated; cell; cell = cell->next)
|
||||
{
|
||||
sum += (u32)(cell->size - HEADERSIZE);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
u32 cr_alloc_GetTotalFreeSize(void)
|
||||
{
|
||||
OSHeapInfo *heapInfo;
|
||||
Cell *cell;
|
||||
u32 sum = 0;
|
||||
|
||||
heapInfo = _sys_heapInfo;
|
||||
|
||||
for (cell = heapInfo->heapArray->free; cell; cell = cell->next)
|
||||
{
|
||||
sum += (u32)(cell->size - HEADERSIZE);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
u32 cr_alloc_GetMaxFreeSize(void)
|
||||
{
|
||||
OSHeapInfo *heapInfo;
|
||||
Cell *cell;
|
||||
u32 candidate = 0;
|
||||
|
||||
heapInfo = _sys_heapInfo;
|
||||
|
||||
for (cell = heapInfo->heapArray->free; cell; cell = cell->next)
|
||||
{
|
||||
u32 size = (u32)(cell->size - HEADERSIZE);
|
||||
if (size > candidate)
|
||||
{
|
||||
candidate = size;
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
|
||||
static void *cr_alloc_InitAlloc(void *arenaStart, void *arenaEnd)
|
||||
{
|
||||
OSHeapInfo *heapInfo;
|
||||
HeapDesc *hd;
|
||||
Cell *cell;
|
||||
|
||||
|
||||
heapInfo = arenaStart;
|
||||
_sys_heapInfo = heapInfo;
|
||||
|
||||
|
||||
heapInfo->heapArray = (void *)((u32)arenaStart + sizeof(OSHeapInfo));
|
||||
|
||||
/*
|
||||
-- heapInfo - arenaStart
|
||||
(OSHeapInfo)
|
||||
-- heapArray --
|
||||
(HeapDesc)
|
||||
-- arenaStart --
|
||||
*/
|
||||
|
||||
hd = heapInfo->heapArray;
|
||||
|
||||
hd->size = -1;
|
||||
hd->free = hd->allocated = NULL;
|
||||
|
||||
//---- Set OSi_CurrentHeap to an invalid value
|
||||
|
||||
//---- Reset arenaStart to the nearest reasonable location
|
||||
arenaStart = (void *)((char *)heapInfo->heapArray + sizeof(HeapDesc) );
|
||||
arenaStart = (void *)ROUND(arenaStart, ALIGNMENT);
|
||||
|
||||
heapInfo->arenaStart = arenaStart;
|
||||
heapInfo->arenaEnd = (void *)TRUNC(arenaEnd, ALIGNMENT);
|
||||
|
||||
|
||||
hd = heapInfo->heapArray;
|
||||
|
||||
if (hd->size < 0) {
|
||||
// hd->size = (char *)end - (char *)start;
|
||||
hd->size = (char *)(heapInfo->arenaEnd)- (char *)(heapInfo->arenaStart);
|
||||
|
||||
// cell = (Cell *) start;
|
||||
cell = (Cell *)(heapInfo->arenaStart);
|
||||
cell->prev = NULL;
|
||||
cell->next = NULL;
|
||||
cell->size = hd->size;
|
||||
hd->free = cell;
|
||||
hd->allocated = 0;
|
||||
}
|
||||
return heapInfo->arenaStart;
|
||||
}
|
||||
|
||||
|
||||
/* */
|
||||
|
||||
static int alloc_counter = 0;
|
||||
static int alloc_counter2 = 0;
|
||||
|
||||
//#define TSIZE_KERNEL_BUFFER 0x30000
|
||||
#define TSIZE_KERNEL_BUFFER 0x20000
|
||||
|
||||
static u32 __kernel_bufmgr_buffer[TSIZE_KERNEL_BUFFER/sizeof(u32)];
|
||||
|
||||
|
||||
int cr_mem_get_counter(void)
|
||||
{
|
||||
return alloc_counter;
|
||||
}
|
||||
|
||||
int cr_mem_get_counter2(void)
|
||||
{
|
||||
return alloc_counter2;
|
||||
}
|
||||
|
||||
|
||||
void cr_mem_bufmgr_initialize(void)
|
||||
{
|
||||
//miya printf("%s %d\n",__FUNCTION__,__LINE__);
|
||||
memset(__kernel_bufmgr_buffer, 0, TSIZE_KERNEL_BUFFER);
|
||||
(void)cr_alloc_InitAlloc((void *)__kernel_bufmgr_buffer,
|
||||
(void *)&(__kernel_bufmgr_buffer[TSIZE_KERNEL_BUFFER/sizeof(u32)]));
|
||||
alloc_counter = 0;
|
||||
alloc_counter2 = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *cr_mem_malloc(size_t size)
|
||||
{
|
||||
void *p_blk;
|
||||
|
||||
alloc_counter++;
|
||||
|
||||
p_blk = cr_alloc_Alloc( size );
|
||||
|
||||
if( NULL == p_blk ) {
|
||||
//miya fprintf(stderr, "Error:%s %d\n",__FUNCTION__,__LINE__);
|
||||
return NULL;
|
||||
}
|
||||
memset( p_blk, 0 , size);
|
||||
return p_blk;
|
||||
}
|
||||
|
||||
void cr_mem_free(void *ptr)
|
||||
{
|
||||
cr_alloc_Free( ptr );
|
||||
alloc_counter--;
|
||||
}
|
||||
|
||||
void *cr_mem_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p_blk;
|
||||
|
||||
alloc_counter++;
|
||||
|
||||
p_blk = cr_alloc_Alloc( size * nmemb );
|
||||
|
||||
if( NULL == p_blk ) {
|
||||
//miya fprintf(stderr, "Error:%s %d\n",__FUNCTION__,__LINE__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return p_blk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *cr_mem_realloc(void *ptr, size_t size)
|
||||
{
|
||||
void *p_blk;
|
||||
|
||||
// OSHeapInfo *heapInfo;
|
||||
// HeapDesc *hd;
|
||||
// heapInfo = _sys_heapInfo;
|
||||
// hd = heapInfo->heapArray;
|
||||
|
||||
// KMEMB *hdr;
|
||||
Cell *cell;
|
||||
|
||||
p_blk = cr_alloc_Alloc( size );
|
||||
|
||||
if( NULL == p_blk ) {
|
||||
//miya fprintf(stderr, "Error:call realloc error %d\n",alloc_counter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// hdr = (KMEMB *)ptr - 1;
|
||||
cell = (Cell *) ((char *)ptr - HEADERSIZE);
|
||||
|
||||
#if 0
|
||||
if( hdr->size > size ) {
|
||||
memcpy(p_blk, ptr, size);
|
||||
}
|
||||
else {
|
||||
memcpy(p_blk, ptr, hdr->size);
|
||||
}
|
||||
#else
|
||||
if( cell->size > size ) {
|
||||
memcpy(p_blk, ptr, size);
|
||||
}
|
||||
else {
|
||||
memcpy(p_blk, ptr, cell->size);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
cr_alloc_Free( ptr );
|
||||
|
||||
return p_blk;
|
||||
}
|
||||
|
||||
30
cr_alloc.h
Normal file
30
cr_alloc.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef _CR_ALLOC_H_
|
||||
#define _CR_ALLOC_H_
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
unsigned long cr_alloc_GetMaxFreeSize(void);
|
||||
unsigned long cr_alloc_GetTotalFreeSize(void);
|
||||
unsigned long cr_alloc_GetTotalAllocSize(int isHeadInclude);
|
||||
|
||||
void cr_mem_bufmgr_initialize(void);
|
||||
int cr_mem_get_counter(void);
|
||||
int cr_mem_get_counter2(void);
|
||||
|
||||
void *cr_mem_realloc(void *ptr, size_t size);
|
||||
void *cr_mem_calloc(size_t nmemb, size_t size);
|
||||
void cr_mem_free(void *ptr);
|
||||
void *cr_mem_malloc(size_t size);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _CR_ALLOC_H_ */
|
||||
1970
cr_generate_id.c
Normal file
1970
cr_generate_id.c
Normal file
File diff suppressed because it is too large
Load Diff
188
cr_generate_id.h
Normal file
188
cr_generate_id.h
Normal file
@ -0,0 +1,188 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef _CR_GENERATE_ID_H_
|
||||
#define _CR_GENERATE_ID_H_
|
||||
|
||||
|
||||
#define CR_GENID_SUCCESS 0
|
||||
#define CR_GENID_ERROR_NON 0
|
||||
#define CR_GENID_ERROR_RSA_ENC ( -1)
|
||||
#define CR_GENID_ERROR_RSA_DEC ( -2)
|
||||
#define CR_GENID_ERROR_RSA_VERIFY ( -3)
|
||||
#define CR_GENID_ERROR_ECDSA_SIGN ( -4)
|
||||
#define CR_GENID_ERROR_ECDSA_VERIFY ( -5)
|
||||
#define CR_GENID_ERROR_SET_MEM_FUNCTIONS ( -6)
|
||||
#define CR_GENID_ERROR_RSA_LOAD_PARAM ( -7)
|
||||
#define CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY ( -8)
|
||||
#define CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY ( -9)
|
||||
#define CR_GENID_ERROR_RSA_READ_PRIVATE_KEY (-10)
|
||||
#define CR_GENID_ERROR_RSA_READ_PUBLIC_KEY (-11)
|
||||
#define CR_GENID_ERROR_BN_NEW_0 (-12)
|
||||
#define CR_GENID_ERROR_BN_NEW_1 (-13)
|
||||
#define CR_GENID_ERROR_BN_NEW_2 (-14)
|
||||
#define CR_GENID_ERROR_BN_CTX_NEW (-15)
|
||||
#define CR_GENID_ERROR_EC_POINT_NEW (-16)
|
||||
#define CR_GENID_ERROR_EC_KEY_NEW_0 (-17)
|
||||
#define CR_GENID_ERROR_EC_KEY_NEW_1 (-18)
|
||||
#define CR_GENID_ERROR_ID_BUF_SIZE (-19)
|
||||
#define CR_GENID_ERROR_ERR_BUF_SIZE (-20)
|
||||
#define CR_GENID_ERROR_PRIVKEY_SCRAMBLE (-21)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef signed char s8;
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef signed long s32;
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
//#define DEBUG_PRINT 1
|
||||
|
||||
#ifdef USE_SFMT
|
||||
#include "SFMT.h"
|
||||
#endif /* USE_SFMT */
|
||||
|
||||
#define CR_ID_BUF_SIZE (2048/8)
|
||||
#define CR_NUM_OF_SERIAL 5
|
||||
|
||||
/*
|
||||
serial と 実際のID との関係は、下記のようになっています。
|
||||
ID0 = serial[ 0 ]
|
||||
ID1 = serial[ 1 ] | ( serial[ 2 ] << 32 )
|
||||
ID2 = serial[ 3 ] | ( serial[ 4 ] << 32 )
|
||||
*/
|
||||
|
||||
// Nintendo ID 仕様
|
||||
#define CR_ID0_BIT_NUM 32
|
||||
#define CR_ID1_BIT_NUM 34
|
||||
#define CR_ID2_BIT_NUM 64
|
||||
#define CR_ID0_MASK 0xFFFFFFFF // 32bit
|
||||
#define CR_ID1_MASK 0x00000003FFFFFFFFll // 34bit
|
||||
#define CR_ID2_MASK 0xFFFFFFFFFFFFFFFFll // 64bit
|
||||
|
||||
int cr_generate_id_initialize( void );
|
||||
int cr_generate_id_finalize( void );
|
||||
|
||||
int cr_generate_id( u32 serial[CR_NUM_OF_SERIAL], u8 id[CR_ID_BUF_SIZE], u8 bondingOption );
|
||||
|
||||
extern int cr_print_flag;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _CR_GENERATE_ID_H_ */
|
||||
|
||||
83
dummyCA/NintendoCA-G2_dummy.crt
Normal file
83
dummyCA/NintendoCA-G2_dummy.crt
Normal file
@ -0,0 +1,83 @@
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 0 (0x0)
|
||||
Signature Algorithm: sha1WithRSAEncryption
|
||||
Issuer: C=US, ST=WA, O=NINTENDO_OF_AMERICA, OU=SYSTEM, CN=ALL-PLATFORM/emailAddress=admin@nintendo.co.jp
|
||||
Validity
|
||||
Not Before: Nov 19 08:58:03 2009 GMT
|
||||
Not After : Nov 17 08:58:03 2019 GMT
|
||||
Subject: C=US, ST=WA, O=NINTENDO_OF_AMERICA, OU=SYSTEM, CN=ALL-PLATFORM/emailAddress=admin@nintendo.co.jp
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: rsaEncryption
|
||||
Public-Key: (2048 bit)
|
||||
Modulus:
|
||||
00:b7:b9:5f:4b:d5:c8:d6:9c:04:05:0c:d3:64:b9:
|
||||
94:75:1e:08:6e:71:ee:86:9b:95:05:09:57:d4:2a:
|
||||
40:41:1c:ce:b3:5d:f9:2f:29:ef:13:1e:a2:d0:11:
|
||||
67:18:cc:a2:69:dd:eb:ce:90:d7:48:8b:60:0a:b9:
|
||||
eb:32:ae:03:38:de:dc:4a:a6:83:1d:54:0c:73:50:
|
||||
32:97:cb:72:1d:7d:07:a8:a4:3d:ed:a7:6e:91:01:
|
||||
bc:f4:97:d9:ae:22:33:30:2b:05:d7:f4:a7:11:0c:
|
||||
be:f5:e5:fb:81:b3:7c:d3:87:22:cd:85:2b:0e:fb:
|
||||
7f:1e:7a:c4:65:0c:1e:6a:27:c5:24:e4:2a:da:c7:
|
||||
64:b0:b7:1d:72:0d:1c:cd:d7:85:f2:74:3a:c1:ba:
|
||||
03:49:06:43:95:f8:c9:48:e8:0f:7c:ca:1a:c5:d7:
|
||||
a3:22:75:ff:7f:29:91:b8:aa:65:30:d1:19:18:7e:
|
||||
08:e1:a0:4a:54:f0:bc:42:89:f6:7a:81:c5:83:c5:
|
||||
78:28:b1:d7:9c:7e:69:78:09:14:12:75:13:62:ef:
|
||||
4b:d9:76:e3:29:9a:6b:35:e4:53:b8:14:4f:8b:93:
|
||||
9c:7b:21:8e:f0:5a:04:b3:04:3f:6a:f0:96:1a:e2:
|
||||
99:42:51:e0:e5:6f:13:d0:f9:86:5e:80:c6:31:21:
|
||||
47:6f
|
||||
Exponent: 65537 (0x10001)
|
||||
X509v3 extensions:
|
||||
X509v3 Basic Constraints:
|
||||
CA:FALSE
|
||||
Netscape Comment:
|
||||
OpenSSL Generated Certificate
|
||||
X509v3 Subject Key Identifier:
|
||||
C7:3D:11:8F:6F:EB:10:5C:CE:C4:CE:04:79:BF:61:E9:70:E0:58:B2
|
||||
X509v3 Authority Key Identifier:
|
||||
keyid:C7:3D:11:8F:6F:EB:10:5C:CE:C4:CE:04:79:BF:61:E9:70:E0:58:B2
|
||||
|
||||
Signature Algorithm: sha1WithRSAEncryption
|
||||
02:56:8e:4c:e2:bb:c7:2c:3a:16:ef:26:c7:11:fa:1c:a5:fc:
|
||||
a8:a3:be:7a:0b:d7:e1:32:77:b9:c5:0a:1a:d8:74:6e:f6:42:
|
||||
3e:c2:ae:60:94:57:6a:d6:4d:56:cd:3e:82:21:4f:e1:53:95:
|
||||
a0:83:e1:24:10:57:ac:89:53:6f:45:9e:85:04:a2:47:1f:e9:
|
||||
85:01:3b:8e:f5:77:ae:66:93:49:90:53:5f:12:10:c3:14:b9:
|
||||
9b:f3:b9:02:54:60:c6:da:48:db:a1:23:9b:ae:9d:42:30:96:
|
||||
af:b5:b2:23:5a:e0:33:89:51:db:f1:6b:a8:10:57:d6:f9:5d:
|
||||
fb:d9:ec:29:92:8a:3b:e8:6d:e2:ae:a6:8d:3c:a1:bd:09:92:
|
||||
3e:d2:05:e4:c0:54:b7:49:92:03:c8:4b:9b:d5:66:91:04:41:
|
||||
dd:65:dd:32:b9:00:f7:54:0e:a0:71:74:33:30:76:4b:59:34:
|
||||
7d:58:59:c7:65:69:3b:72:91:8f:ba:1b:a2:8b:2e:d5:fe:b0:
|
||||
64:2d:f3:ae:ae:76:76:21:a1:c0:a3:53:a6:93:62:99:e2:22:
|
||||
fc:80:aa:d2:a6:2f:6f:03:28:6d:01:66:40:7d:36:0e:05:ca:
|
||||
06:09:4b:6d:7a:42:a9:57:85:80:50:f1:21:cd:df:47:e2:49:
|
||||
73:9d:12:ca
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEAjCCAuqgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMCVVMx
|
||||
CzAJBgNVBAgMAldBMRwwGgYDVQQKDBNOSU5URU5ET19PRl9BTUVSSUNBMQ8wDQYD
|
||||
VQQLDAZTWVNURU0xFTATBgNVBAMMDEFMTC1QTEFURk9STTEjMCEGCSqGSIb3DQEJ
|
||||
ARYUYWRtaW5AbmludGVuZG8uY28uanAwHhcNMDkxMTE5MDg1ODAzWhcNMTkxMTE3
|
||||
MDg1ODAzWjCBhTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAldBMRwwGgYDVQQKDBNO
|
||||
SU5URU5ET19PRl9BTUVSSUNBMQ8wDQYDVQQLDAZTWVNURU0xFTATBgNVBAMMDEFM
|
||||
TC1QTEFURk9STTEjMCEGCSqGSIb3DQEJARYUYWRtaW5AbmludGVuZG8uY28uanAw
|
||||
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3uV9L1cjWnAQFDNNkuZR1
|
||||
Hghuce6Gm5UFCVfUKkBBHM6zXfkvKe8THqLQEWcYzKJp3evOkNdIi2AKuesyrgM4
|
||||
3txKpoMdVAxzUDKXy3IdfQeopD3tp26RAbz0l9muIjMwKwXX9KcRDL715fuBs3zT
|
||||
hyLNhSsO+38eesRlDB5qJ8Uk5Crax2Swtx1yDRzN14XydDrBugNJBkOV+MlI6A98
|
||||
yhrF16Midf9/KZG4qmUw0RkYfgjhoEpU8LxCifZ6gcWDxXgosdecfml4CRQSdRNi
|
||||
70vZduMpmms15FO4FE+Lk5x7IY7wWgSzBD9q8JYa4plCUeDlbxPQ+YZegMYxIUdv
|
||||
AgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2Vu
|
||||
ZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBTHPRGPb+sQXM7EzgR5v2HpcOBY
|
||||
sjAfBgNVHSMEGDAWgBTHPRGPb+sQXM7EzgR5v2HpcOBYsjANBgkqhkiG9w0BAQUF
|
||||
AAOCAQEAAlaOTOK7xyw6Fu8mxxH6HKX8qKO+egvX4TJ3ucUKGth0bvZCPsKuYJRX
|
||||
atZNVs0+giFP4VOVoIPhJBBXrIlTb0WehQSiRx/phQE7jvV3rmaTSZBTXxIQwxS5
|
||||
m/O5AlRgxtpI26Ejm66dQjCWr7WyI1rgM4lR2/FrqBBX1vld+9nsKZKKO+ht4q6m
|
||||
jTyhvQmSPtIF5MBUt0mSA8hLm9VmkQRB3WXdMrkA91QOoHF0MzB2S1k0fVhZx2Vp
|
||||
O3KRj7oboosu1f6wZC3zrq52diGhwKNTppNimeIi/ICq0qYvbwMobQFmQH02DgXK
|
||||
BglLbXpCqVeFgFDxIc3fR+JJc50Syg==
|
||||
-----END CERTIFICATE-----
|
||||
18
dummyCA/NintendoCA-G2_dummy.csr
Normal file
18
dummyCA/NintendoCA-G2_dummy.csr
Normal file
@ -0,0 +1,18 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIC3TCCAcUCAQAwgZcxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJXQTEQMA4GA1UE
|
||||
BwwHUkVETU9ORDEcMBoGA1UECgwTTklOVEVORE9fT0ZfQU1FUklDQTEPMA0GA1UE
|
||||
CwwGU1lTVEVNMRUwEwYDVQQDDAxBTEwtUExBVEZPUk0xIzAhBgkqhkiG9w0BCQEW
|
||||
FGFkbWluQG5pbnRlbmRvLmNvLmpwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEAt7lfS9XI1pwEBQzTZLmUdR4IbnHuhpuVBQlX1CpAQRzOs135LynvEx6i
|
||||
0BFnGMyiad3rzpDXSItgCrnrMq4DON7cSqaDHVQMc1Ayl8tyHX0HqKQ97adukQG8
|
||||
9JfZriIzMCsF1/SnEQy+9eX7gbN804cizYUrDvt/HnrEZQweaifFJOQq2sdksLcd
|
||||
cg0czdeF8nQ6wboDSQZDlfjJSOgPfMoaxdejInX/fymRuKplMNEZGH4I4aBKVPC8
|
||||
Qon2eoHFg8V4KLHXnH5peAkUEnUTYu9L2XbjKZprNeRTuBRPi5OceyGO8FoEswQ/
|
||||
avCWGuKZQlHg5W8T0PmGXoDGMSFHbwIDAQABoAAwDQYJKoZIhvcNAQEFBQADggEB
|
||||
ACz+sEe0XyW4NkDJvTEJbtPaIyL8PYcz7Iz6sAdwyoj67sZh/H1evyKPDDF6AHtp
|
||||
Q+TMzGFUWxrv3Rwp2xHNi35T8jpCpvZNNtAQ7+v0/IHn1TPyIjxWcSh8qShR6OqE
|
||||
LhBhs+5jumbJVw0D7R1CGc9n/hhjJyfVt1l4PSIYbMWkdPcl/3rXJtc/PQUzcLoH
|
||||
jQZC8OlvZKH77SiJ5avdfq5co7By0Pw4ANNuw8hZnG8BuRed1/xo7ZsR4F63P0g3
|
||||
Hi2G9bNWR1eeORo1ouGQDg8RhCgKk39BDLIQWEqto6GwHYpolydzUKtWkHV7zEU1
|
||||
Gt3UGMqCqltOj8RIZKsIIF8=
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
BIN
dummyCA/NintendoCA-G2_priv_dummy.der
Normal file
BIN
dummyCA/NintendoCA-G2_priv_dummy.der
Normal file
Binary file not shown.
27
dummyCA/NintendoCA-G2_priv_dummy.pem
Normal file
27
dummyCA/NintendoCA-G2_priv_dummy.pem
Normal file
@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAt7lfS9XI1pwEBQzTZLmUdR4IbnHuhpuVBQlX1CpAQRzOs135
|
||||
LynvEx6i0BFnGMyiad3rzpDXSItgCrnrMq4DON7cSqaDHVQMc1Ayl8tyHX0HqKQ9
|
||||
7adukQG89JfZriIzMCsF1/SnEQy+9eX7gbN804cizYUrDvt/HnrEZQweaifFJOQq
|
||||
2sdksLcdcg0czdeF8nQ6wboDSQZDlfjJSOgPfMoaxdejInX/fymRuKplMNEZGH4I
|
||||
4aBKVPC8Qon2eoHFg8V4KLHXnH5peAkUEnUTYu9L2XbjKZprNeRTuBRPi5OceyGO
|
||||
8FoEswQ/avCWGuKZQlHg5W8T0PmGXoDGMSFHbwIDAQABAoIBAGgTLYWjDEtuQ+Ss
|
||||
eE+1xQB3S+Vsyucb2VXqDgPVD2MTM5BuKotqINFe6HIfeZyVx2dbXIo+iIXC1lwd
|
||||
J7wk0RR1QqtTGjER/J+SDabpi7JismT47U/kKgEgz+5q2tgG7aJarMvB/qXs53wa
|
||||
lNfLWmnlQnTT/ClXlJIqj3iCXfRZrmzlwvO8U0kil0oe1jFAlgYAj/ktnsvQmK/t
|
||||
Mli7zQdg2GYLouRSk1HexLkf9Hmf3pKJjmNL4Xx2WblaGGX+sGTOZP4d1Mwx1q3z
|
||||
kEscTjxWiTh1YRjxY8gdf1W63w1H0+9eBxp7DfzwmEt6wBu/dsLaBwDDAmqdgyqY
|
||||
nEc8yFkCgYEA7N8GJ1on2dYtDkVXrTHA9lOoj6es10F59FRydaRMm2FMY9m6lEg3
|
||||
jstSKf8AZTV+6KOlEf4K7ym1BIkdVD0FlkUp0d8tLtmF36y9qV8L0zUwaZAaR/Pi
|
||||
xRZ6cP+Fr6KNYqB5O9iPb+z4cDQtwS9SYFLjP6ZU2Q0lUDoQZPyfnk0CgYEAxo+b
|
||||
lRDLhADN0A+df8W/AWFWdrCexC9vwhzcinMr55nXJv2gzmR78BiXv2IVwPHg6dz2
|
||||
sSQKttgEnQwVW4nqY0E8mEPNja6sMpt4xkblwXQRm1u09MERUk2M4Lg5hvtFXiM2
|
||||
qSkcryD0OYs9MMQ0wyKbJGHLVB9si1D6trK1sqsCgYBTh8Z8xB8/g3a6DJwBmIUK
|
||||
mK/dkOyzsARYtBr0/26AcMxmfdZ9CgaFlY+w/ZrfFgFd+q9wa9zhQBz0r4GnPiml
|
||||
N1irCP+/ALhkC1+Kxdi+r4gWAdoyu3+hru6YwJMdP76KJDr8br8OYkuuDciA0rZC
|
||||
/5fhzz8ml6sr4n37jtafFQKBgQCW7JUfivKGVW4a1aOreQ0j6W6lLL6g9EWIUBO6
|
||||
EKywj5igBGx0NKCX8Ll3OQC79Z41ZEUGhBS4wh1Pmd2qBHxqES4TtoXJSZmNper5
|
||||
Gu6MSsMPSXeUCiQ2YMfSD3V6igdB9JYZoiwxWWUJUDKknJ5WLDmsP8EjIfeJNXY7
|
||||
5D6DnQKBgDdiPyGUHRLQy7+hm5EYWVhc8L//ejtF73XHxeBao6V7QZvM6dLalqie
|
||||
eY8bNy9nDUbk9dnL193VPbmH3ZcYkcKtkGuBRQsFcImCVkxcxtG110LMHbOcuVax
|
||||
Bsh6Ia0hswVFY4mzKf6mpzo2oNHT7s8vaDtVCJkjGN3d8Suf/2ng
|
||||
-----END RSA PRIVATE KEY-----
|
||||
BIN
dummyCA/NintendoCA-G2_pub_dummy.der
Normal file
BIN
dummyCA/NintendoCA-G2_pub_dummy.der
Normal file
Binary file not shown.
9
dummyCA/NintendoCA-G2_pub_dummy.pem
Normal file
9
dummyCA/NintendoCA-G2_pub_dummy.pem
Normal file
@ -0,0 +1,9 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt7lfS9XI1pwEBQzTZLmU
|
||||
dR4IbnHuhpuVBQlX1CpAQRzOs135LynvEx6i0BFnGMyiad3rzpDXSItgCrnrMq4D
|
||||
ON7cSqaDHVQMc1Ayl8tyHX0HqKQ97adukQG89JfZriIzMCsF1/SnEQy+9eX7gbN8
|
||||
04cizYUrDvt/HnrEZQweaifFJOQq2sdksLcdcg0czdeF8nQ6wboDSQZDlfjJSOgP
|
||||
fMoaxdejInX/fymRuKplMNEZGH4I4aBKVPC8Qon2eoHFg8V4KLHXnH5peAkUEnUT
|
||||
Yu9L2XbjKZprNeRTuBRPi5OceyGO8FoEswQ/avCWGuKZQlHg5W8T0PmGXoDGMSFH
|
||||
bwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
66
dummyCA/NintendoCTR2_dummy.crt
Normal file
66
dummyCA/NintendoCTR2_dummy.crt
Normal file
@ -0,0 +1,66 @@
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 1 (0x1)
|
||||
Signature Algorithm: sha1WithRSAEncryption
|
||||
Issuer: C=US, ST=WA, O=NINTENDO_OF_AMERICA, OU=SYSTEM, CN=ALL-PLATFORM/emailAddress=admin@nintendo.co.jp
|
||||
Validity
|
||||
Not Before: Nov 19 09:02:31 2009 GMT
|
||||
Not After : Nov 17 09:02:31 2019 GMT
|
||||
Subject: C=JP, ST=KYOTO, L=KYOTO, O=NINTENDO, OU=RED, CN=CTR/emailAddress=ctr_admin@nintendo.co.jp
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: id-ecPublicKey
|
||||
Public-Key: (233 bit)
|
||||
pub:
|
||||
04:00:d9:01:fd:e5:55:60:d9:32:33:25:93:53:0a:
|
||||
ba:63:a3:14:50:96:2d:4c:72:f2:9a:e6:a0:fb:6b:
|
||||
bf:01:be:d6:c3:8c:64:11:a2:6c:d3:ac:aa:31:9a:
|
||||
f5:67:a4:85:67:d6:93:67:04:8b:f0:a0:9e:2d:25:
|
||||
35
|
||||
ASN1 OID: sect233r1
|
||||
X509v3 extensions:
|
||||
X509v3 Basic Constraints:
|
||||
CA:FALSE
|
||||
Netscape Comment:
|
||||
OpenSSL Generated Certificate
|
||||
X509v3 Subject Key Identifier:
|
||||
71:C3:EC:E7:2A:49:31:38:31:5B:7B:76:9D:2E:10:03:FE:19:78:4C
|
||||
X509v3 Authority Key Identifier:
|
||||
keyid:C7:3D:11:8F:6F:EB:10:5C:CE:C4:CE:04:79:BF:61:E9:70:E0:58:B2
|
||||
|
||||
Signature Algorithm: sha1WithRSAEncryption
|
||||
78:77:94:27:9d:db:1e:4b:4a:f0:58:de:a3:09:b2:d3:be:08:
|
||||
ce:ff:12:14:8c:f5:3f:fd:c8:bb:f1:51:5e:7a:6f:38:dc:c8:
|
||||
cd:c9:af:52:d1:a7:c3:b7:60:e0:37:95:7d:72:89:94:40:fb:
|
||||
c5:ce:ff:ed:9f:a8:ff:93:ee:61:f1:36:01:a9:2f:df:bc:3d:
|
||||
8b:e8:ee:60:98:75:93:3b:96:92:0b:a1:41:33:d8:01:b9:13:
|
||||
42:5f:04:56:c9:84:3e:41:06:6d:4c:82:bd:9f:dd:77:45:df:
|
||||
76:0e:27:c5:ae:69:3a:61:5d:a2:85:b9:fe:64:96:a5:ef:1d:
|
||||
d5:93:05:c3:24:9e:ce:fc:b6:c3:0e:fa:8f:40:31:f8:ed:f9:
|
||||
66:52:75:9d:2a:66:a6:ce:52:46:1c:90:39:5a:53:ea:eb:8c:
|
||||
25:9e:16:70:6b:9b:3f:2a:22:23:55:67:a6:fa:50:2b:4a:e4:
|
||||
e5:a6:db:2d:df:ae:76:4a:04:be:b9:1c:45:74:82:0a:91:70:
|
||||
d6:31:5f:ed:c9:bf:14:db:5a:8b:d0:e6:8a:20:4b:db:2e:c4:
|
||||
1f:13:08:22:72:bb:79:9b:7a:19:b1:9e:a5:2e:e6:15:b8:66:
|
||||
6e:62:39:77:70:e4:63:9b:fc:03:5c:4b:ad:64:55:6e:11:f1:
|
||||
b9:e0:b8:24
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDMDCCAhigAwIBAgIBATANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMCVVMx
|
||||
CzAJBgNVBAgMAldBMRwwGgYDVQQKDBNOSU5URU5ET19PRl9BTUVSSUNBMQ8wDQYD
|
||||
VQQLDAZTWVNURU0xFTATBgNVBAMMDEFMTC1QTEFURk9STTEjMCEGCSqGSIb3DQEJ
|
||||
ARYUYWRtaW5AbmludGVuZG8uY28uanAwHhcNMDkxMTE5MDkwMjMxWhcNMTkxMTE3
|
||||
MDkwMjMxWjCBhTELMAkGA1UEBhMCSlAxDjAMBgNVBAgMBUtZT1RPMQ4wDAYDVQQH
|
||||
DAVLWU9UTzERMA8GA1UECgwITklOVEVORE8xDDAKBgNVBAsMA1JFRDEMMAoGA1UE
|
||||
AwwDQ1RSMScwJQYJKoZIhvcNAQkBFhhjdHJfYWRtaW5AbmludGVuZG8uY28uanAw
|
||||
UjAQBgcqhkjOPQIBBgUrgQQAGwM+AAQA2QH95VVg2TIzJZNTCrpjoxRQli1McvKa
|
||||
5qD7a78BvtbDjGQRomzTrKoxmvVnpIVn1pNnBIvwoJ4tJTWjezB5MAkGA1UdEwQC
|
||||
MAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRl
|
||||
MB0GA1UdDgQWBBRxw+znKkkxODFbe3adLhAD/hl4TDAfBgNVHSMEGDAWgBTHPRGP
|
||||
b+sQXM7EzgR5v2HpcOBYsjANBgkqhkiG9w0BAQUFAAOCAQEAeHeUJ53bHktK8Fje
|
||||
owmy074Izv8SFIz1P/3Iu/FRXnpvONzIzcmvUtGnw7dg4DeVfXKJlED7xc7/7Z+o
|
||||
/5PuYfE2Aakv37w9i+juYJh1kzuWkguhQTPYAbkTQl8EVsmEPkEGbUyCvZ/dd0Xf
|
||||
dg4nxa5pOmFdooW5/mSWpe8d1ZMFwySezvy2ww76j0Ax+O35ZlJ1nSpmps5SRhyQ
|
||||
OVpT6uuMJZ4WcGubPyoiI1VnpvpQK0rk5abbLd+udkoEvrkcRXSCCpFw1jFf7cm/
|
||||
FNtai9DmiiBL2y7EHxMIInK7eZt6GbGepS7mFbhmbmI5d3DkY5v8A1xLrWRVbhHx
|
||||
ueC4JA==
|
||||
-----END CERTIFICATE-----
|
||||
9
dummyCA/NintendoCTR2_dummy.csr
Normal file
9
dummyCA/NintendoCTR2_dummy.csr
Normal file
@ -0,0 +1,9 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIBMzCB4QIBADCBhTELMAkGA1UEBhMCSlAxDjAMBgNVBAgMBUtZT1RPMQ4wDAYD
|
||||
VQQHDAVLWU9UTzERMA8GA1UECgwITklOVEVORE8xDDAKBgNVBAsMA1JFRDEMMAoG
|
||||
A1UEAwwDQ1RSMScwJQYJKoZIhvcNAQkBFhhjdHJfYWRtaW5AbmludGVuZG8uY28u
|
||||
anAwUjAQBgcqhkjOPQIBBgUrgQQAGwM+AAQA2QH95VVg2TIzJZNTCrpjoxRQli1M
|
||||
cvKa5qD7a78BvtbDjGQRomzTrKoxmvVnpIVn1pNnBIvwoJ4tJTWgADAJBgcqhkjO
|
||||
PQQBA0IAMD8CHgDRzF0qVB7z6NG9nNEWq6w+gzxzFV95+tfWCYkCsgIdUT2iMI7Z
|
||||
UZiE0I/lrOIHqetBIsJFpYVGA83D1gc=
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
BIN
dummyCA/NintendoCTR2_priv_dummy.der
Normal file
BIN
dummyCA/NintendoCTR2_priv_dummy.der
Normal file
Binary file not shown.
8
dummyCA/NintendoCTR2_priv_dummy.pem
Normal file
8
dummyCA/NintendoCTR2_priv_dummy.pem
Normal file
@ -0,0 +1,8 @@
|
||||
-----BEGIN EC PARAMETERS-----
|
||||
BgUrgQQAGw==
|
||||
-----END EC PARAMETERS-----
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MG0CAQEEHSPpFxKbsybBnzhicMZAWpTsdlB1u/Ca7PlXn9SZoAcGBSuBBAAboUAD
|
||||
PgAEANkB/eVVYNkyMyWTUwq6Y6MUUJYtTHLymuag+2u/Ab7Ww4xkEaJs06yqMZr1
|
||||
Z6SFZ9aTZwSL8KCeLSU1
|
||||
-----END EC PRIVATE KEY-----
|
||||
BIN
dummyCA/NintendoCTR2_pub_dummy.der
Normal file
BIN
dummyCA/NintendoCTR2_pub_dummy.der
Normal file
Binary file not shown.
4
dummyCA/NintendoCTR2_pub_dummy.pem
Normal file
4
dummyCA/NintendoCTR2_pub_dummy.pem
Normal file
@ -0,0 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFIwEAYHKoZIzj0CAQYFK4EEABsDPgAEANkB/eVVYNkyMyWTUwq6Y6MUUJYtTHLy
|
||||
muag+2u/Ab7Ww4xkEaJs06yqMZr1Z6SFZ9aTZwSL8KCeLSU1
|
||||
-----END PUBLIC KEY-----
|
||||
50
dummyCA/Test_CTR-Device_dummy.crt
Normal file
50
dummyCA/Test_CTR-Device_dummy.crt
Normal file
@ -0,0 +1,50 @@
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 2 (0x2)
|
||||
Signature Algorithm: ecdsa-with-SHA1
|
||||
Issuer: C=JP, ST=KYOTO, L=KYOTO, O=NINTENDO, OU=RED, CN=CTR/emailAddress=ctr_admin@nintendo.co.jp
|
||||
Validity
|
||||
Not Before: Nov 19 09:19:06 2009 GMT
|
||||
Not After : Nov 17 09:19:06 2019 GMT
|
||||
Subject: C=JP, ST=OKAYAMA, L=ODA, O=SHARP, OU=TAKAYA, CN=HSM/emailAddress=admin@sharp.co.jp
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: id-ecPublicKey
|
||||
Public-Key: (233 bit)
|
||||
pub:
|
||||
04:01:b3:a1:96:8b:60:29:fe:b9:18:86:89:82:4c:
|
||||
92:d8:98:0d:d8:f3:8f:6a:68:8e:f5:93:f2:4f:5a:
|
||||
d4:01:5a:02:86:1f:cd:e1:37:7b:1b:5e:47:b2:f9:
|
||||
8f:f5:85:a3:ae:e2:4a:51:28:22:2d:1a:82:6e:91:
|
||||
96
|
||||
ASN1 OID: sect233r1
|
||||
X509v3 extensions:
|
||||
X509v3 Basic Constraints:
|
||||
CA:FALSE
|
||||
Netscape Comment:
|
||||
OpenSSL Generated Certificate
|
||||
X509v3 Subject Key Identifier:
|
||||
6F:90:5B:FE:66:6D:4D:4B:B1:6D:3F:CC:64:1A:26:BF:8F:5D:1D:1B
|
||||
X509v3 Authority Key Identifier:
|
||||
keyid:71:C3:EC:E7:2A:49:31:38:31:5B:7B:76:9D:2E:10:03:FE:19:78:4C
|
||||
|
||||
Signature Algorithm: ecdsa-with-SHA1
|
||||
30:3f:02:1d:2d:13:94:04:c0:cc:57:48:fe:73:b8:c0:25:88:
|
||||
92:9b:27:ec:ba:fc:cb:bd:e6:40:87:91:4d:7b:1f:02:1e:00:
|
||||
94:a0:7b:72:a0:72:e3:87:fd:3d:d1:9b:db:18:87:5b:54:24:
|
||||
3a:f5:48:7e:9c:86:ad:89:69:bf:fa
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICXzCCAgygAwIBAgIBAjAJBgcqhkjOPQQBMIGFMQswCQYDVQQGEwJKUDEOMAwG
|
||||
A1UECAwFS1lPVE8xDjAMBgNVBAcMBUtZT1RPMREwDwYDVQQKDAhOSU5URU5ETzEM
|
||||
MAoGA1UECwwDUkVEMQwwCgYDVQQDDANDVFIxJzAlBgkqhkiG9w0BCQEWGGN0cl9h
|
||||
ZG1pbkBuaW50ZW5kby5jby5qcDAeFw0wOTExMTkwOTE5MDZaFw0xOTExMTcwOTE5
|
||||
MDZaMH4xCzAJBgNVBAYTAkpQMRAwDgYDVQQIDAdPS0FZQU1BMQwwCgYDVQQHDANP
|
||||
REExDjAMBgNVBAoMBVNIQVJQMQ8wDQYDVQQLDAZUQUtBWUExDDAKBgNVBAMMA0hT
|
||||
TTEgMB4GCSqGSIb3DQEJARYRYWRtaW5Ac2hhcnAuY28uanAwUjAQBgcqhkjOPQIB
|
||||
BgUrgQQAGwM+AAQBs6GWi2Ap/rkYhomCTJLYmA3Y849qaI71k/JPWtQBWgKGH83h
|
||||
N3sbXkey+Y/1haOu4kpRKCItGoJukZajezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4
|
||||
QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBRv
|
||||
kFv+Zm1NS7FtP8xkGia/j10dGzAfBgNVHSMEGDAWgBRxw+znKkkxODFbe3adLhAD
|
||||
/hl4TDAJBgcqhkjOPQQBA0IAMD8CHS0TlATAzFdI/nO4wCWIkpsn7Lr8y73mQIeR
|
||||
TXsfAh4AlKB7cqBy44f9PdGb2xiHW1QkOvVIfpyGrYlpv/o=
|
||||
-----END CERTIFICATE-----
|
||||
9
dummyCA/Test_CTR-Device_dummy.csr
Normal file
9
dummyCA/Test_CTR-Device_dummy.csr
Normal file
@ -0,0 +1,9 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIBKjCB2QIBADB+MQswCQYDVQQGEwJKUDEQMA4GA1UECAwHT0tBWUFNQTEMMAoG
|
||||
A1UEBwwDT0RBMQ4wDAYDVQQKDAVTSEFSUDEPMA0GA1UECwwGVEFLQVlBMQwwCgYD
|
||||
VQQDDANIU00xIDAeBgkqhkiG9w0BCQEWEWFkbWluQHNoYXJwLmNvLmpwMFIwEAYH
|
||||
KoZIzj0CAQYFK4EEABsDPgAEAbOhlotgKf65GIaJgkyS2JgN2POPamiO9ZPyT1rU
|
||||
AVoChh/N4Td7G15HsvmP9YWjruJKUSgiLRqCbpGWoAAwCQYHKoZIzj0EAQNBADA+
|
||||
Ah1hHULgGMJQ9thR6xIXnKnf7MRoL+8MM+7IiytapwIdE4cmzuPZRQ1TohuAI4zZ
|
||||
seqaK/9grU1rWEcDZT0=
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
BIN
dummyCA/Test_CTR-Device_priv_dummy.der
Normal file
BIN
dummyCA/Test_CTR-Device_priv_dummy.der
Normal file
Binary file not shown.
8
dummyCA/Test_CTR-Device_priv_dummy.pem
Normal file
8
dummyCA/Test_CTR-Device_priv_dummy.pem
Normal file
@ -0,0 +1,8 @@
|
||||
-----BEGIN EC PARAMETERS-----
|
||||
BgUrgQQAGw==
|
||||
-----END EC PARAMETERS-----
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MG0CAQEEHeionsNFKvOye5ZdTN7DgNma1Hecm5/085LBPsdVoAcGBSuBBAAboUAD
|
||||
PgAEAbOhlotgKf65GIaJgkyS2JgN2POPamiO9ZPyT1rUAVoChh/N4Td7G15HsvmP
|
||||
9YWjruJKUSgiLRqCbpGW
|
||||
-----END EC PRIVATE KEY-----
|
||||
BIN
dummyCA/Test_CTR-Device_pub_dummy.der
Normal file
BIN
dummyCA/Test_CTR-Device_pub_dummy.der
Normal file
Binary file not shown.
4
dummyCA/Test_CTR-Device_pub_dummy.pem
Normal file
4
dummyCA/Test_CTR-Device_pub_dummy.pem
Normal file
@ -0,0 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFIwEAYHKoZIzj0CAQYFK4EEABsDPgAEAbOhlotgKf65GIaJgkyS2JgN2POPamiO
|
||||
9ZPyT1rUAVoChh/N4Td7G15HsvmP9YWjruJKUSgiLRqCbpGW
|
||||
-----END PUBLIC KEY-----
|
||||
455
main.c
Normal file
455
main.c
Normal file
@ -0,0 +1,455 @@
|
||||
|
||||
#define RAND_MAX 0xffffffff
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DEV_CYGWIN
|
||||
#include <conio.h>
|
||||
#else // Cygwin
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#endif // Linux
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "cr_generate_id.h"
|
||||
|
||||
#define T_BONDING_OPTION 0 // TORIAEZU bondingOption = 0
|
||||
|
||||
// extern const int isDummyPrivateKey;
|
||||
|
||||
/*
|
||||
gen_id.exe 0x01 0x02
|
||||
gen_id.exe 0x01 0x02 ctrid090716.dat
|
||||
gen_id.exe 0x01 0x03 ctrid090728.dat
|
||||
*/
|
||||
|
||||
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 );
|
||||
} // keyboard_initialize
|
||||
|
||||
void keyboard_finalize( void )
|
||||
{
|
||||
tcsetattr( 0, TCSANOW, &initial_setting );
|
||||
} // keyboard_finalize
|
||||
|
||||
int kbhit( void )
|
||||
{
|
||||
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 );
|
||||
|
||||
if ( nread == 1 )
|
||||
{
|
||||
peek_character = ch;
|
||||
return 1;
|
||||
}
|
||||
|
||||
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 *str = "0x11111111";
|
||||
static int str_to_u32(u32 *num, const char *str)
|
||||
{
|
||||
u32 c;
|
||||
int shift = 0;
|
||||
char *s;
|
||||
int hex_mode = 0;
|
||||
|
||||
*num = 0;
|
||||
|
||||
if( *str == '0' && *(str+1) == 'x' ) {
|
||||
hex_mode = 1;
|
||||
s = (char *)(str + 2);
|
||||
}
|
||||
else {
|
||||
s = (char *)str;
|
||||
}
|
||||
|
||||
while( *s != '\0' ) {
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
if( '0' <= *s && *s <= '9' ) {
|
||||
c = (u32)(*s - '0');
|
||||
}
|
||||
else {
|
||||
return -1; /* error */
|
||||
}
|
||||
*num *= 10;
|
||||
*num += c;
|
||||
}
|
||||
shift++;
|
||||
s++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double gettimeofday_sec(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
#if 0
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec + (double)tv.tv_usec*1e-6;
|
||||
}
|
||||
|
||||
int main(int ac, char *argv[])
|
||||
{
|
||||
u32 serial[CR_NUM_OF_SERIAL];
|
||||
u8 id[CR_ID_BUF_SIZE]; /* 256byte(2048bit) */
|
||||
int ret_code;
|
||||
int c;
|
||||
FILE *fp;
|
||||
double time_start,time_end;
|
||||
long double time_total = 0;
|
||||
int time_count = 0;
|
||||
int myseed;
|
||||
time_t tloc;
|
||||
u32 counter0, counter0_bak;
|
||||
u64 counter1, counter1_bak;
|
||||
u64 counter2, counter2_bak;
|
||||
u32 i;
|
||||
|
||||
#ifndef DEV_CYGWIN
|
||||
keyboard_initialize();
|
||||
#endif
|
||||
|
||||
#ifdef USE_DUMMY_KEY
|
||||
fprintf(stderr,"RSA private key is dummy!\n");
|
||||
return -1; /* error */
|
||||
#endif
|
||||
|
||||
time(&tloc);
|
||||
myseed = tloc;
|
||||
srand(myseed);
|
||||
|
||||
#ifdef USE_SFMT
|
||||
init_gen_rand((u32)myseed);
|
||||
/* いくらか乱数を読み捨てした方が良い? */
|
||||
#endif
|
||||
|
||||
// ID生成前にカウンタ加算をするなら、初期値は 0 で OK
|
||||
counter0 = 0x00000000;
|
||||
counter1 = 0x0000000000000000ll;
|
||||
counter2 = 0x0000000000000000ll;
|
||||
|
||||
// cr_generate_id を使用する前に呼び出す
|
||||
if ( !cr_generate_id_initialize() )
|
||||
{
|
||||
printf( "error : cr_generate_id_initialize()\n" );
|
||||
return 0; // error
|
||||
}
|
||||
|
||||
|
||||
if( ac == 1 ) {
|
||||
for( i = 1 ; i < 0xffffffff; i++ ) {
|
||||
u64 unit;
|
||||
|
||||
counter0_bak = counter0;
|
||||
counter1_bak = counter1;
|
||||
counter2_bak = counter2;
|
||||
|
||||
// counter0 は、1 ずつ加算
|
||||
counter0 = i;
|
||||
if( counter0 == 0 ) {
|
||||
counter0 = 1;
|
||||
}
|
||||
|
||||
// counter1 は、"1~4 の乱数値" を加算
|
||||
unit = (u64)( ( rand() & 0x03 ) + 1 );
|
||||
counter1 += unit;
|
||||
|
||||
// counter2 は、"0 以外の 32bit 乱数値" を加算
|
||||
do {
|
||||
#ifdef USE_SFMT
|
||||
unit = (u64)gen_rand32();
|
||||
#else
|
||||
unit = (u64)rand() | ( (u64)rand() << 16 );
|
||||
#endif
|
||||
}while( unit == 0 );
|
||||
counter2 += unit;
|
||||
|
||||
// カウンタオーバーフローチェック
|
||||
if( counter0 < counter0_bak ) {
|
||||
fprintf(stderr,"counter0 overflow : %08x\n", (unsigned int)counter0 );
|
||||
}
|
||||
if( counter1 < counter1_bak ) {
|
||||
fprintf(stderr,"counter1 overflow : %08x%08x\n", (unsigned int)( counter1 >> 32 ), (unsigned int)counter2 );
|
||||
}
|
||||
if( counter2 < counter2_bak ) {
|
||||
fprintf(stderr,"counter2 overflow : %08x%08x\n", (unsigned int)( counter2 >> 32 ), (unsigned int)counter2 );
|
||||
}
|
||||
|
||||
serial[0] = counter0;
|
||||
serial[1] = (u32)(counter1 & 0xffffffff);
|
||||
serial[2] = (u32)((counter1 >> 32) & 0xffffffff);
|
||||
serial[3] = (u32)(counter2 & 0xffffffff);
|
||||
serial[4] = (u32)((counter2 >> 32) & 0xffffffff);
|
||||
|
||||
|
||||
time_start = gettimeofday_sec();
|
||||
ret_code = cr_generate_id( serial, id, T_BONDING_OPTION );
|
||||
if( ret_code != 0 ) {
|
||||
fprintf(stderr,"generate_id failed\n");
|
||||
switch( ret_code ) {
|
||||
case CR_GENID_ERROR_ID_BUF_SIZE:
|
||||
fprintf(stderr,"failed to CR_ID_BUFFER structure size\n");
|
||||
break;
|
||||
case CR_GENID_ERROR_ERR_BUF_SIZE:
|
||||
fprintf(stderr,"failed to CR_ERR_BUFFER structure size\n");
|
||||
break;
|
||||
case CR_GENID_ERROR_RSA_ENC:
|
||||
fprintf(stderr,"failed to RSA_public_encrypt\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_RSA_DEC:
|
||||
fprintf(stderr,"failed to RSA_private_decrypt\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_RSA_VERIFY:
|
||||
fprintf(stderr,"RSA verify failed\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_ECDSA_SIGN:
|
||||
fprintf(stderr,"ECDSA sign failure. No ECDSA sign will be done.\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_ECDSA_VERIFY:
|
||||
fprintf(stderr,"ECDSA_verify NG.\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_SET_MEM_FUNCTIONS:
|
||||
fprintf(stderr,"CRYPTO_set_mem_functions error \n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_RSA_LOAD_PARAM:
|
||||
fprintf(stderr,"load rsa param failed\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_EC_GENERATE_PRIVATE_KEY:
|
||||
fprintf(stderr,"error EC generate_private_key\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_EC_GENERATE_PUBLIC_KEY:
|
||||
fprintf(stderr,"error EC generate_public_key\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_RSA_READ_PRIVATE_KEY:
|
||||
fprintf(stderr,"error RSA read private key\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_RSA_READ_PUBLIC_KEY:
|
||||
fprintf(stderr,"error RSA read public key\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_BN_NEW_0:
|
||||
fprintf(stderr,"error bn_new 0\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_BN_NEW_1:
|
||||
fprintf(stderr,"error bn_new 1\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_BN_NEW_2:
|
||||
fprintf(stderr,"error bn_new 2\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_BN_CTX_NEW:
|
||||
fprintf(stderr,"error bn_ctx_new\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_EC_POINT_NEW:
|
||||
fprintf(stderr,"error ec_point_new\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_EC_KEY_NEW_0:
|
||||
fprintf(stderr,"error EC_KEY_new_by_curve_name 0\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_EC_KEY_NEW_1:
|
||||
fprintf(stderr,"error EC_KEY_new_by_curve_name 1\n");
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
case CR_GENID_ERROR_PRIVKEY_SCRAMBLE:
|
||||
fprintf(stderr,"failed to decode privkey scramble.\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"error unknown error ret_code=%d\n", ret_code);
|
||||
fprintf(stderr," internal errcode=0x%02x%02x%02x%02x\n", id[11],id[10],id[9],id[8]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
time_end = gettimeofday_sec();
|
||||
time_total += (long double)(time_end - time_start);
|
||||
time_count++;
|
||||
/* printf("generate_id success\n"); */
|
||||
}
|
||||
|
||||
if (kbhit())
|
||||
{
|
||||
c = getch();
|
||||
if( 'p' == c ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)serial[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[3] );
|
||||
printf("time av. = %8.8f sec\n", (double)(time_total/(long double)time_count));
|
||||
cr_print_flag = 1;
|
||||
}
|
||||
else if( c == 'q' ) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cr_print_flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( ac == 3 ) {
|
||||
if( 0 == str_to_u32(&serial[0], argv[1]) && 0 == str_to_u32(&serial[1], argv[2]) ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)serial[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[3] );
|
||||
|
||||
time_start = gettimeofday_sec();
|
||||
cr_print_flag = 1;
|
||||
if( 0 != cr_generate_id( serial, id, T_BONDING_OPTION ) )
|
||||
{
|
||||
fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n",
|
||||
(int)serial[0], (int)serial[1], (int)serial[2]);
|
||||
}
|
||||
else {
|
||||
time_end = gettimeofday_sec();
|
||||
time_total += (long double)(time_end - time_start);
|
||||
time_count++;
|
||||
printf("time av. = %8.8f sec\n", (double)(time_total/(long double)time_count));
|
||||
}
|
||||
cr_print_flag = 0;
|
||||
}
|
||||
else {
|
||||
goto err_print;
|
||||
}
|
||||
|
||||
}
|
||||
else if( ac == 4 ) {
|
||||
if( 0 == str_to_u32(&serial[0], argv[1]) && 0 == str_to_u32(&serial[1], argv[2]) ) {
|
||||
printf("ID[0] = 0x%08x\n", (unsigned int)serial[0]);
|
||||
printf("ID[1] = 0x%08x%08x\n", (unsigned int)serial[2], (unsigned int)serial[1] );
|
||||
printf("ID[2] = 0x%08x%08x\n", (unsigned int)serial[4], (unsigned int)serial[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( serial, id, T_BONDING_OPTION ) )
|
||||
{
|
||||
fprintf(stderr,"cr_generate_id failed s1=0x%08x s2_lo=0x%08x s2_hi=0x%08x\n",
|
||||
(int)serial[0], (int)serial[1], (int)serial[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 SerialNo.(32bit) filename.dat\n", argv[0]);
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
// cr_generate_id を使用した後に呼び出す
|
||||
if ( !cr_generate_id_finalize() )
|
||||
{
|
||||
printf( "error : cr_generate_id_finalize()\n" );
|
||||
return 0; // error
|
||||
}
|
||||
|
||||
#ifndef DEV_CYGWIN
|
||||
keyboard_finalize();
|
||||
#endif
|
||||
|
||||
printf("end of main\n");
|
||||
return 0;
|
||||
}
|
||||
29
package.csh
Normal file
29
package.csh
Normal file
@ -0,0 +1,29 @@
|
||||
#!c:/tcsh/tcsh.exe
|
||||
|
||||
set mydir="cr_generate_id"
|
||||
|
||||
#../rsa_keysrcgen/gen_id_rsa_key.c
|
||||
|
||||
set myfiles="main.c cr_generate_id.c cr_generate_id.h cr_alloc.c cr_alloc.h cr_gen_id_rsa_key_priv.c cr_gen_id_rsa_key_pub.c cr_gen_id_rsa_key_priv.h cr_gen_id_rsa_key_pub.h Makefile.sharp readme_openssl.txt LICENSE_en.txt LICENSE_jp.txt readme.txt"
|
||||
|
||||
|
||||
if(-e $mydir.zip) then
|
||||
rm -f $mydir.zip
|
||||
endif
|
||||
|
||||
if(-d $mydir ) then
|
||||
rm -rf $mydir
|
||||
endif
|
||||
|
||||
mkdir $mydir
|
||||
|
||||
foreach myfile ($myfiles)
|
||||
if(-e $mydir/$myfile) then
|
||||
rm -f $mydir/$myfile
|
||||
endif
|
||||
cp $myfile $mydir/$myfile
|
||||
end
|
||||
|
||||
mv $mydir/Makefile.sharp $mydir/Makefile
|
||||
|
||||
zip $mydir.zip $mydir/*
|
||||
34
package.sh
Normal file
34
package.sh
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
mydir="generate_id"
|
||||
echo $mydir
|
||||
|
||||
#../rsa_keysrcgen/gen_id_rsa_key.c
|
||||
|
||||
myfiles="main.c cr_generate_id.c cr_generate_id.h cr_alloc.c cr_alloc.h cr_gen_id_rsa_key_priv.c cr_gen_id_rsa_key_pub.c cr_gen_id_rsa_key_priv.h cr_gen_id_rsa_key_pub.h Makefile.sharp readme_openssl.txt LICENSE_en.txt LICENSE_jp.txt readme.txt"
|
||||
|
||||
|
||||
if [ -e mydir.zip ]
|
||||
then
|
||||
rm -f $mydir.zip
|
||||
fi
|
||||
|
||||
if [ -e $mydir ]
|
||||
then
|
||||
rm -rf $mydir
|
||||
fi
|
||||
|
||||
mkdir $mydir
|
||||
|
||||
for myfile in $myfiles
|
||||
do
|
||||
if [ -e $mydir/$myfile ]
|
||||
then
|
||||
rm -f $mydir/$myfile
|
||||
fi
|
||||
cp $myfile $mydir/$myfile
|
||||
done
|
||||
|
||||
mv $mydir/Makefile.sharp $mydir/Makefile
|
||||
|
||||
zip $mydir.zip $mydir/*
|
||||
71
readme.txt
Normal file
71
readme.txt
Normal file
@ -0,0 +1,71 @@
|
||||
CTR - ID生成関数について 2009/09/30
|
||||
|
||||
----------------------------
|
||||
要、opensslライブラリ(バージョン0.9.8以上)
|
||||
現在、openssl-1.0.0-beta2とopenssl-0.9.8kでテスト中。
|
||||
|
||||
-----------------------------
|
||||
ファイル構成:
|
||||
readme.txt
|
||||
readme_openssl.txt
|
||||
LICENSE_en.txt
|
||||
LICENSE_jp.txt
|
||||
cr_generate_id.h
|
||||
cr_generate_id.c
|
||||
cr_alloc.h
|
||||
cr_alloc.c
|
||||
cr_gen_id_rsa_key_priv.c
|
||||
cr_gen_id_rsa_key_priv.h
|
||||
cr_gen_id_rsa_key_pub.c
|
||||
cr_gen_id_rsa_key_pub.h
|
||||
maim.c(使用サンプル)
|
||||
Makefile(Windows cygwin環境用)
|
||||
|
||||
----------------------------
|
||||
関数仕様:
|
||||
|
||||
#define CR_ID_BUF_SIZE (2048/8)
|
||||
#define CR_NUM_OF_SERIAL 5
|
||||
|
||||
typedef signed char s8;
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
int cr_generate_id(u32 counter[CR_NUM_OF_SERIAL], u8 id[ID_BUF_SIZE]);
|
||||
/*
|
||||
Core2 Duo 2.66GHz 2GB で約0.016sec
|
||||
*/
|
||||
----------------------------
|
||||
使用サンプル:
|
||||
|
||||
main()
|
||||
{
|
||||
u8 id_buf[CR_ID_BUF_SIZE]; /* 256byte(2048bit) */
|
||||
u32 counter_array[CR_NUM_OF_SERIAL];
|
||||
|
||||
u32 counter0 = 1;
|
||||
u64 counter1 = 2;
|
||||
u64 counter2 = 3;
|
||||
|
||||
|
||||
while( 1 ) {
|
||||
counter_array[0] = counter0;
|
||||
counter_array[1] = (u32)(counter1 & 0xffffffff );
|
||||
counter_array[2] = (u32)( (counter1 >> 32) & 0xffffffff );
|
||||
counter_array[3] = (u32)(counter2 & 0xffffffff );
|
||||
counter_array[4] = (u32)( (counter2 >> 32) & 0xffffffff );
|
||||
|
||||
if( 0 != cr_generate_id(counter_array, id_buf) ) {
|
||||
fprintf(stderr,"cr_generate_id failed c=0x%08x\n",counter0);
|
||||
}
|
||||
else {
|
||||
fwrite(id, CR_ID_BUF_SIZE, 1, fp);
|
||||
}
|
||||
counter0++;
|
||||
counter1 += (u64)rand();
|
||||
counter2 += (u64)rand();
|
||||
}
|
||||
}
|
||||
|
||||
15
readme_openssl.txt
Normal file
15
readme_openssl.txt
Normal file
@ -0,0 +1,15 @@
|
||||
This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit.
|
||||
(http://www.openssl.org/)
|
||||
|
||||
This product includes cryptographic software written by Eric Young (eay@cryptsoft.com)
|
||||
|
||||
-------------------------------------------------------------------------------------------
|
||||
この製品には、OpenSSL Toolkit で使用するために OpenSSL Project によって開発されたソフトウェアが組み込まれています。
|
||||
(http://www.openssl.org/)
|
||||
|
||||
|
||||
このパッケージは、Eric Young (eay@cryptsoft.com) により作成された SSL インプリメンテーションです。このインプリメンテーションは、Netscape SSL に準拠するように作成されています。
|
||||
|
||||
このライブラリーは、以下の条件に従う限り、無料での商業および非商業の使用が許可されます。以下の条件は、単に SSL コードだけでなく、この配布に含まれるすべてのコードに適用されます。この場合、そのコードが RC4、RSA、lhash、DES、などにいずれであっても構いません。この配布に含まれる SSL 資料は、著作権所有者が Tim Hudson (tjh@cryptsoft.com) である点を除き、同一著作権によってカバーされます。
|
||||
|
||||
著作権は Eric Young が所有していますので、コードの著作権表示を除去してはなりません。このパッケージをいずれかの製品に使用する場合は、使用するライブラリー部分の作成者として Eric Young を特定する必要があります。これは、プログラム始動時に、またはこのパッケージと一緒に提供される資料 (オンラインまたはテキスト) にテキスト形式のメッセージとして含めることができます。
|
||||
94
tools/bin2c.plx
Normal file
94
tools/bin2c.plx
Normal file
@ -0,0 +1,94 @@
|
||||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
|
||||
use File::Basename;
|
||||
|
||||
|
||||
# バイナリファイルをCソースに変換
|
||||
|
||||
my $KEY_VER = 1;
|
||||
my $srcfname = $ARGV[0];
|
||||
my $dstfname_c;
|
||||
my $dstfname_h;
|
||||
my $arrayname;
|
||||
my $size;
|
||||
|
||||
if( !$ARGV[0] ) {
|
||||
die "parameter error.\n";
|
||||
}
|
||||
|
||||
$_ = "cr_" . basename($srcfname, "");
|
||||
s/(\..*)/\.c/;
|
||||
$dstfname_c = $_;
|
||||
s/(\..*)/\.h/;
|
||||
$dstfname_h = $_;
|
||||
s/(\..*)/_DER/;
|
||||
$arrayname = $_;
|
||||
|
||||
$size = -s $srcfname;
|
||||
|
||||
open SRC, "< $srcfname"
|
||||
or die "Cannot open file $srcfname : $!";
|
||||
|
||||
open DST, "> $dstfname_c"
|
||||
or die "Cannot open file temp : $!";
|
||||
|
||||
open DST2, "> $dstfname_h"
|
||||
or die "Cannot open file temp : $!";
|
||||
|
||||
binmode( SRC );
|
||||
|
||||
# 配列サイズを + magic_code(8) + keyLen(2) + padding(6) し、16bytesでROUNDUP
|
||||
my $array_size = ( $size + 16 + 15) & 0xfffffff0;
|
||||
|
||||
# .c ファイルに変換して出力
|
||||
|
||||
printf DST "#include <stdio.h>\n\n";
|
||||
printf DST "\/\/下記配列は、DERフォーマットのKEYデータの前に magic_code[8] + keyLen[2] + keyVer[1] + padding[5] のデータが挿入されています。\n\n";
|
||||
printf DST "const unsigned char %s[ 0x%x ] = {\n\t", $arrayname, $array_size;
|
||||
|
||||
# magic code
|
||||
my $magic_priv = "REDCODER";
|
||||
my $magic_pub = "REDCODEU";
|
||||
my @magic_list;
|
||||
if( $srcfname =~ m/priv/ ) {
|
||||
@magic_list = unpack( "H2H2H2H2H2H2H2H2", $magic_priv );
|
||||
}else {
|
||||
@magic_list = unpack( "H2H2H2H2H2H2H2H2", $magic_pub );
|
||||
}
|
||||
foreach my $elem ( @magic_list ) {
|
||||
printf DST "0x%s, ", $elem;
|
||||
}
|
||||
|
||||
# サイズ
|
||||
printf DST "0x%02x, ", $size % 256;
|
||||
printf DST "0x%02x, ", $size / 256;
|
||||
|
||||
# KEYバージョン
|
||||
printf DST "0x%02x, ", $KEY_VER;
|
||||
|
||||
# パディング
|
||||
my $i;
|
||||
for ( $i = 0; $i < 5; $i++) {
|
||||
printf DST "0x%02x, ", rand(255);
|
||||
}
|
||||
|
||||
# KEY実体
|
||||
my $buff;
|
||||
my $count = 0;
|
||||
while( sysread( SRC, $buff, 1 ) ) {
|
||||
my $src = unpack( "C", $buff );
|
||||
print DST "\n\t" if( ( $count & 0x0f ) == 0 );
|
||||
printf DST "0x%02x, ", $src;
|
||||
$count++;
|
||||
}
|
||||
|
||||
print DST "\n};\n";
|
||||
|
||||
close SRC;
|
||||
close DST;
|
||||
|
||||
# .h ファイルも出力
|
||||
printf DST2 "extern const unsigned char %s[ 0x%x ];\n", $arrayname, $array_size;
|
||||
close DST2;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user