ctr_eFuse/cr_hsm_bignum.h
kubodera_yuichi 86b4ddc293 NFastApp_Malloc,NFastApp_Freeは登録した関数が呼び出されることが判明したのでカウンタはcr_hsm_allocにて統合
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@153 ff987cc8-cf2f-4642-8568-d52cce064691
2010-01-07 08:11:07 +00:00

178 lines
5.5 KiB
C

/** \file simplebignum.h Simple bignum support
*
* Illustrates simple easy-to-use bignumber format. This provides a
* definition of the \ref NFast_Bignum structure which can be used
* in applications which do not already have an equivalent structure
* defined.
*
* See also:
* - \ref nfastapp.h
* - \ref gsbignum
*/
/* Copyright 1999-2002 nCipher Corporation Limited.
*
* This example source code is provided for your information and
* assistance. See the file LICENCE.TXT for details and the
* terms and conditions of the licence which governs the use of the
* source code. By using such source code you will be accepting these
* terms and conditions. If you do not wish to accept these terms and
* conditions, DO NOT OPEN THE FILE OR USE THE SOURCE CODE.
*
* Note that there is NO WARRANTY.
*
*/
#ifndef CR_HSM_BIGNUM_H
#define CR_HSM_BIGNUM_H
#include "nfastapp.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MAXBIGNUMBITS
/** Maximum size of a bignum in bits */
#define MAXBIGNUMBITS 16384
#endif
/** Structure of a bignum
*
* \ref M_Bignum will be a pointer to this structure. */
struct NFast_Bignum {
/** Byte order
*
* If this is set then each 32-bit word in the bignum is big-endian
* (most-significant byte first); otherwise it is little-endian
* (least-significant byte first). */
int msb_first;
/** Word order
*
* If this is set then 32-bit words in the bignum are in big-endian order
* (most-significant word first); otherwise they are in little-endian
* order (least-significant words first).
*/
int msw_first;
/** Number of bytes */
int nbytes;
/** Bignum data
*
* Only the first \a nbytes are used. */
unsigned char bytes[MAXBIGNUMBITS/8];
};
/* Bignum send & receive upcalls -------------------------- */
/* As well as being used directly as upcalls,
these can be used to create bignums from data blocks and
extract data from bignums.
*/
/** Bignum receive upcall
*
* See \ref NFast_BignumReceiveUpcall_t */
extern int my_bignumreceiveupcall(struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx,
M_Bignum *bignum, int nbytes,
const void *source,
int msbitfirst, int mswordfirst);
/** Bignum send-length upcall
*
* See \ref NFast_BignumSendLenUpcall_t */
extern int my_bignumsendlenupcall(struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx,
const M_Bignum *bignum, int *nbytes_r);
/** Bignum send upcall
*
* See \ref NFast_BignumSendUpcall_t */
extern int my_bignumsendupcall(struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx,
const M_Bignum *bignum, int nbytes,
void *dest, int msbitfirst, int mswordfirst);
/** Free bignum upcall
*
* See \ref NFast_BignumFreeUpcall_t */
extern void my_bignumfreeupcall(struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx,
M_Bignum *bignum);
/** Bignum format upcall
*
* See \ref NFast_BignumFormatUpcall_t */
extern int my_bignumformatupcall(struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx,
int *msbitfirst_io, int *mswordfirst_io);
/** Structure containing bignum upcalls
*
* See \ref NFastAppInitArgs and \ref NFAPP_IF_BIGNUM */
extern NFast_BignumUpcalls my_upcalls;
/* Bignum utility functions ----------------------------- */
/** Convert a hex string to a bignum
*
* \return Status code
*/
extern int my_char2bignum ( struct NFast_Bignum **ppBN_out,
const char *text,
struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx );
// convert binary to NFast_Bignum
extern int my_bin2bignum ( struct NFast_Bignum **ppBN_out,
struct NFast_Application *app,
const unsigned char *bin, const int size );
/** Convert a bignum to a hex string
*
* \return Status code
*/
extern int my_bignum2char ( char *buf, int buflen,
const struct NFast_Bignum *pBN,
struct NFast_Application *app,
struct NFast_Call_Context *cctx,
struct NFast_Transaction_Context *tctx );
// convert NFast_Bignum to binary
int my_bignum2bin ( unsigned char *buf, int buflen,
struct NFast_Application *app,
const struct NFast_Bignum *pBN );
// NFast_Bignum copy
int my_bignumCopy( struct NFast_Bignum **dst,
const struct NFast_Bignum *src,
struct NFast_Application *app );
/** Print a bignum in hex to a file
*
* Call ferror() to test for output errors.
*/
extern void my_printbignum ( FILE *f,
const char *prefix, const struct NFast_Bignum *pBN );
/** Compare two bignums
*
* \return -1, 0 or 1 if A\<B, A=B or A\>B
*/
extern int my_compare ( const struct NFast_Bignum *pA,
const struct NFast_Bignum *pB );
#ifdef __cplusplus
}
#endif
#endif // CR_HSM_BIGNUM_H