⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_bgnf2n.h

📁 用于ECC公钥密码算法的大数运算库
💻 H
字号:
#ifndef _LIB_BGNF2N_H
#define _LIB_BGNF2N_H

#include "lib_type.h"


/**
*   for test only
*
*   to query the status of BGNZ2N Module
*
**/
void print_bgn_f2n_status();

/**
*
* start BGNZ2N module 
*
**/
BGNF2N_MD_ID bgn_f2n_start( const BIGINT *f_x );

/**
*
* end BGNZ2N module 
*
**/
void bgn_f2n_end(BGNF2N_MD_ID bgnf2n_md_id);

/**
*   compare a and b
*   if a > b, then return 1
*   if a = b, then return 0
*   if a < b, then return -1
**/
int bgn_f2n_cmp(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT * a,const BIGINT *b);

/**
*   clone src to des
*   return des where des = src  
**/
void bgn_f2n_clone(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT * src,BIGINT * des);

/**
*
*   if src = 0, then return EC_TRUE
*   if src !=0, then return EC_FALSE
*
**/
EC_BOOL bgn_f2n_is_zero(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* src);

/**
*
*   if src = 1, then return EC_TRUE
*   if src !=1, then return EC_FALSE
*
**/
EC_BOOL bgn_f2n_is_one(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* src);

/**
*
*   if src is odd, then return EC_TRUE
*   if src is even, then return EC_FALSE
*
**/
EC_BOOL bgn_f2n_is_odd(BGNF2N_MD_ID bgnf2n_md_id,BIGINT *src);

/**
*   
*   set a = 0
**/
void bgn_f2n_set_zero(BGNF2N_MD_ID bgnf2n_md_id,BIGINT * a);

/**
*   
*   set a = 1
**/
void bgn_f2n_set_one(BGNF2N_MD_ID bgnf2n_md_id,BIGINT * a);

/**
*   
*   set a = n
**/
void bgn_f2n_set_word(BGNF2N_MD_ID bgnf2n_md_id,BIGINT *a,UINT32 n);

/**
*   if k = 0, then return s[ 0 ] = 0 and 0
*   if k > 0, then
*       let k = SUM( k_i * 2 ^ i, i = 0..n, k_i takes 0 or 1, and k_n = 1 )
*   return s =[ k_0,...,k_n ] and n
*   i.e,
*       s[ 0 ] = k_0,... s[ n ] = k_n
*
**/
UINT32 bgn_f2n_parse_bits(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT *k,UINT32 *s);

/**
**   Let the NAF representative of k be
*       k = SUM ( s_i * 2 ^ i, where s_i belong to {1,0,-1} and i = 0..n )
*   Then return s = [ s_0,...,s_n ] and n
*   i.e,
*       s[ 0 ] = s_0,... s[ n ] = s_n
*
**/
int bgn_f2n_naf(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT *k,int *s);

/** 
*
*   return deg(a)   
*
*   let a = SUM(a_i * x^i, i =0..m)
*   if a  = 0, then return ( 0 )
*   if a != 0, then return ( m )
**/
UINT32 bgn_f2n_deg(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT *a);

/** 
*   let a0 = a mod x ^{WORDSIZE}
*   return c = ( a - a0 ) /( x ^{WORDSIZE} ) ) and the shifted out word is returned.
*   hence a = ( c * x ^{WORDSIZE} ) + shift_out
*   maybe address of c = address of a 
**/
void bgn_f2n_shr_onewordsize(BGNF2N_MD_ID bgnf2n_md_id,BIGINT *a,BIGINT *c);

/** 
*   let a0 = a mod x ^{nbits}
*   return c = ( a - a0 ) /( x ^{nbits} ) ) and the shifted out word is returned.
*   hence a = ( c * x ^{nbits} ) + shift_out
*   maybe address of c = address of a 
**/
void bgn_f2n_shr_lesswordsize(BGNF2N_MD_ID bgnf2n_md_id,BIGINT *a, UINT32 nbits,BIGINT *c);

/** 
*   return c = ( a * x ^{WORDSIZE} ) and the shifted out word is returned.
*   where ( a * x ^{WORDSIZE} ) = shift_out * x ^( BIGINTSIZE ) + c
*   maybe address of c = address of a 
**/
void bgn_f2n_shl_onewordsize(BGNF2N_MD_ID bgnf2n_md_id,BIGINT * a, BIGINT * c);

/** 
*   return c = ( a * x ^{nbits} ) and the shifted out word is returned.
*   where ( a * x ^{nbits} ) = shift_out * x ^( BIGINTSIZE ) + c
*   maybe address of c = address of a 
**/
void bgn_f2n_shl_lesswordsize(BGNF2N_MD_ID bgnf2n_md_id,BIGINT * a, UINT32 nbits, BIGINT * c);

/**
*   deg (a) < n
*   deg (b) < n
*   
*   c = a + b over F_{2^n} = Z_2[x]/f(x)
*   i.e,
*   c = a + b mod f(x) over Z_2[x]
*
**/
void bgn_f2n_add(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* a,const BIGINT * b,BIGINT * c);

/**
*   deg (a) < n
*   deg (b) < n
*   
*   c = a - b over F_{2^n} = Z_2[x]/f(x)
*   i.e,
*   c = a - b mod f(x) over Z_2[x]
*
**/
void bgn_f2n_sub(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* a,const BIGINT * b,BIGINT * c);

/**
*   deg (a) < n
void bgn_f2n_squ(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* a,BIGINT * c);
*   deg (b) < n
*   
*   c = a * b over F_{2^n}, where F_{2^n} = Z_2[ x ]/ f(x)
*   i.e,
*   c = a * b mod f(x) over F2[x]
*
**/
void bgn_f2n_mul(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* a,const BIGINT * b,BIGINT * c);

/**
*   a != 0 and deg (a) < n
*   
*   c = a ^{-1} over F_{2^n} = Z_2[x]/f(x)
*   i.e,
*   c = a ^{-1} mod f(x) over Z_2[x]
*
*/
EC_BOOL bgn_f2n_inv(BGNF2N_MD_ID bgnf2n_md_id,const BIGINT* a,BIGINT * c);

#endif /* _LIB_BGNF2N_H  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -