ctr_eFuse/trunk/cr_generate_id_private.h
kubodera_yuichi 161d102c76 RootCAの名称変更によるバージョンアップ,ver4
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@196 ff987cc8-cf2f-4642-8568-d52cce064691
2010-02-01 11:01:47 +00:00

235 lines
11 KiB
C
Raw Blame History

/* ====================================================================
* 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_PRIVATE_H_
#define _CR_GENERATE_ID_PRIVATE_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef USE_HSM
// nShield
#include "nfastapp.h"
#include "nfkm.h"
#include "rqcard-applic.h"
#include "rqcard-fips.h"
#endif // USE_HSM
#include <openssl/err.h>
#include <openssl/sha.h>
#include <openssl/ec.h>
#include "ec_lcl.h" // EC_KEY (=ec_key_st) <20>\<5C><><EFBFBD>̂̎Q<CC8E>ƂɕK<C995>v
#ifdef DEBUG_PRINT
#define DEBUG_PRINT_ARRAY DebugPrintArray
#else // !DEBUG_PRINT
#define DEBUG_PRINT_ARRAY( ... ) ((void)0)
#endif // DEBUG_PRINT
#define ENCRYPT_AES 1 // <20><><EFBFBD>`<60><><EFBFBD>L<EFBFBD><4C><EFBFBD><EFBFBD>FIX.<2E>i<EFBFBD><69><EFBFBD><EFBFBD><EA82AA><EFBFBD><EFBFBD><EFBFBD>`<60>̏ꍇ<CC8F>AID<49>̈Í<CC88><C38D><EFBFBD><EFBFBD><EFBFBD>RSA<53>ɂȂ<C982><C882>B<EFBFBD>j
#define CR_GEN_ID_VERSION 4 // <20>V<EFBFBD><56><EFBFBD>[<5B>v<EFBFBD>ւ̃<D682><CC83><EFBFBD><EFBFBD>[<5B>X<EFBFBD><58><EFBFBD>Ƃ<EFBFBD>UP<55><50><EFBFBD><EFBFBD><EFBFBD>B
// 2010/02/01 Release ver.4
#ifdef USE_HSM
#define CR_GEN_ID_MAGICCODE 0xdeadb00f; /* <20>ŏI<C58F>I<EFBFBD>ɂ͂<C982><CD82><EFBFBD><EFBFBD><EFBFBD><EFBFBD>œ<EFBFBD><C593><EFBFBD><EFBFBD>B0xdeadbeef<65>ɂ<EFBFBD><C982><EFBFBD><EFBFBD><EFBFBD>RSA<53>ŃR<C583>P<EFBFBD><50><EFBFBD>B */
#else // !USE_HSM
#define CR_GEN_ID_MAGICCODE 0xabadf00d;
#endif // USE_HSM
#define CR_RANDOM_LENGTH 0x50
#define EC_PRIVATE_KEY_LENGTH 0x20
#define ECDSA_SIGN_LENGTH 0x3C
#define CR_RSV_LENGTH 0x10
#define EC_CURVE_NAME NID_sect233r1
//---------------------------------------------------
// OpenSSL<53>̏<EFBFBD><CC8F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʂɂ<CA82><C982><EFBFBD><EFBFBD>G<EFBFBD><47><EFBFBD>[<5B>R<EFBFBD>[<5B>h
//---------------------------------------------------
#define CR_GENID_ERROR_BN_NEW ( -1)
#define CR_GENID_ERROR_ECC_KEY_NEW ( -2)
#define CR_GENID_ERROR_ECC_GENERATE_PRIVATE_KEY ( -3)
#define CR_GENID_ERROR_ECC_GENERATE_PUBLIC_KEY ( -4)
#define CR_GENID_ERROR_ECC_READ_PRIVATE_KEY ( -5)
#define CR_GENID_ERROR_ECC_READ_PUBLIC_KEY ( -6)
#define CR_GENID_ERROR_ECDSA_SIGN ( -7)
#define CR_GENID_ERROR_ECDSA_DEC ( -8)
#define CR_GENID_ERROR_ECDSA_VERIFY ( -9)
#define CR_GENID_ERROR_AES_ENC (-10)
#define CR_GENID_ERROR_AES_DEC (-11)
#define CR_GENID_ERROR_AES_VERIFY (-12)
#define CR_GENID_ERROR_RSA_READ_PRIVATE_KEY (-13)
#define CR_GENID_ERROR_RSA_READ_PUBLIC_KEY (-14)
#define CR_GENID_ERROR_RSA_ENC (-15)
#define CR_GENID_ERROR_RSA_DEC (-16)
#define CR_GENID_ERROR_RSA_VERIFY (-17)
#define CR_GENID_ERROR_SET_MEM_FUNCTIONS (-18)
typedef struct {
u32 magic_number; /* 0x00 - 0x03 = 0xdeadb00f <20>m<EFBFBD><6D><EFBFBD>I*/
u32 device_id[CR_NUM_OF_DEVICEID]; /* 0x04 - 0x07 32bit device ID
(32bit<69>B1<42>Œ<EFBFBD><C592>J<EFBFBD>E<EFBFBD><45><EFBFBD>g<EFBFBD>A<EFBFBD>b<EFBFBD>v<EFBFBD>B<EFBFBD>j
(<28>{ID<49>{random<6F>̐擪0x1C bytes<65><73><EFBFBD>g<EFBFBD>ݍ<EFBFBD><DD8D><EFBFBD>āA<C481>f<EFBFBD>o<EFBFBD>C<EFBFBD>X<EFBFBD><EFBFBD><E996A7><EFBFBD>Ƃ<EFBFBD><C682><EFBFBD><EFBFBD>B)
0x08 - 0x0F 64bit CTR<54>ԍ<EFBFBD> seed
(34bit<69>̂ݎg<DD8E>p<EFBFBD>B1<42>`4<>̗<EFBFBD><CC97><EFBFBD><EFBFBD>J<EFBFBD>E<EFBFBD><45><EFBFBD>g<EFBFBD>A<EFBFBD>b<EFBFBD>v)
0x10 - 0x17 64bit <20>\<5C><>ID
(64bit<69>t<EFBFBD><74><EFBFBD>Ɏg<C98E>p<EFBFBD>B1<42>`0x100000000<30>̗<EFBFBD><CC97><EFBFBD><EFBFBD>J<EFBFBD>E<EFBFBD><45><EFBFBD>g<EFBFBD>A<EFBFBD>b<EFBFBD>v)
*/
u8 version; /* 0x18 = CR_GEN_ID_VERSION */
u8 bonding_option; /* 0x19 <20>{<7B><><EFBFBD>f<EFBFBD>B<EFBFBD><42><EFBFBD>O<EFBFBD>I<EFBFBD>v<EFBFBD>V<EFBFBD><56><EFBFBD><EFBFBD> */
u8 year; /* 0x1A <20>f<EFBFBD>o<EFBFBD>C<EFBFBD>X<EFBFBD>ؖ<EFBFBD><D896><EFBFBD><EFBFBD><EFBFBD><EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD> <20>iHSM<53><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>j */
u8 month; /* 0x1B */
u8 mday; /* 0x1C */
u8 hour; /* 0x1D */
u8 min; /* 0x1E */
u8 sec; /* 0x1F */
u32 expiryDate; /* 0x20 - 0x23 <20>f<EFBFBD>o<EFBFBD>C<EFBFBD>X<EFBFBD>ؖ<EFBFBD><D896><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> seconds from the Epoch (Jan 1, 1970 00:00) as a 32 bit */
u8 devicePrivKey[ EC_PRIVATE_KEY_LENGTH ];
/* 0x24 - 0x43 ECC233 private key (big endian) <20><><EFBFBD>j<EFBFBD>[<5B>N<EFBFBD><4E><EFBFBD>ۏ؂Ȃ<D882> */
u8 deviceCertSign[ ECDSA_SIGN_LENGTH ];
/* 0x44 - 0x7F ECC233 ECDSA signature (big endian) */
u8 reserved[ CR_RSV_LENGTH ]; /* 0x80 - 0x8F <20>\<5C><> */
u8 random[ CR_RANDOM_LENGTH ]; /* 0x90 - 0xDF <20><><EFBFBD><EFBFBD> */
u8 hash[ SHA256_DIGEST_LENGTH ]; /* 0xE0 - 0xFF "0x00-0xDF"<22>̈<EFBFBD><CC88><EFBFBD>SHA256<35>n<EFBFBD>b<EFBFBD>V<EFBFBD><56> */
} CR_ID_BUFFER; /* <20><><EFBFBD>v256bytes = 2048bit */
#define CALL_STACK_SIZE (234)
typedef struct {
u64 totalCount; /* 0x00 - 0x07 */
u32 magic_number; /* 0x08 - 0x0b 0x01234567 <20>m<EFBFBD><6D><EFBFBD>I*/
u32 device_id0; /* 0x0c - 0x0f */
s32 errorCode; /* 0x10 - 0x13 */
u8 bonding_option;
u8 recordSize; // <20>R<EFBFBD>[<5B><><EFBFBD>X<EFBFBD>^<5E>b<EFBFBD>N<EFBFBD>̋L<CC8B>^<5E>T<EFBFBD>C<EFBFBD>Y
u8 callStack[ CALL_STACK_SIZE ];
} CR_ERR_BUFFER;
extern int GetTimestamp( u8 *pYear, u8 *pMonth, u8 *pMday, u8 *pHour, u8 *pMin, u8 *pSec, time_t *pTime);
extern int GenerateRandom( u8 *pDst, int length );
extern int GenarateECCKeyPair( EC_KEY **ppECkey, u8 *pECPrivkey );
extern void InitErrorInfo( void );
extern void SetErrorInfo( const char *funcName, u32 line );
extern void GetErrorInfo( char *stack, u8 *size );
extern int TestECDSA( EC_KEY *pECkey );
extern int GenerateCTRDeviceCert( EC_KEY *pECkey, u32 device_id, u8 bonding_option, u8 *pDevCertSign, u32 *pExpiryDate );
extern int EncryptID( unsigned char *dst_buf, unsigned char *org_buf, u8 bonding_option );
extern void DebugPrintArray( char *pStr, const u8 *pData, int length );
extern void DebugFileOutput( u32 device_id, char *pSuffix, const u8 *pSrc, int length );
#ifdef __cplusplus
}
#endif
#endif /* _CR_GENERATE_ID_PRIVATE_H_ */