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

📄 lib_bgnfp.h

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

#include "lib_type.h"

/**
*   for test only
*
*   to query the status of BGNFP Module
*
**/
void print_bgn_fp_status();

/**
*
* start BGNFP module 
*
**/
BGNFP_MD_ID bgn_fp_start( const BIGINT *p );

/**
*
* end BGNFP module 
*
**/
void bgn_fp_end(BGNFP_MD_ID bgnfp_md_id);


/**
*   clone src to des
*   return des where des = src  
**/
void bgn_fp_clone(BGNFP_MD_ID bgnfp_md_id,const BIGINT * src,BIGINT * des);

/**
*   compare a and b
*   if a > b, then return 1
*   if a = b, then return 0
*   if a < b, then return -1
**/
int bgn_fp_cmp(BGNFP_MD_ID bgnfp_md_id,const BIGINT * a,const BIGINT *b);

/**
*   
*   set a = 0
**/
void bgn_fp_set_zero(BGNFP_MD_ID bgnfp_md_id,BIGINT * a);

/**
*   
*   set a = 1
**/
void bgn_fp_set_one(BGNFP_MD_ID bgnfp_md_id,BIGINT * a);

/**
*   
*   set a = n
**/
void bgn_fp_set_word(BGNFP_MD_ID bgnfp_md_id,BIGINT *a,const UINT32 n);

/**
*   return e = 2 ^ nth mod p
*            = ( 1 << nth ) mod p
*   where nth = 0,1,...,{BIGINTSIZE - 1}
*   
**/
void bgn_fp_set_e(BGNFP_MD_ID bgnfp_md_id,BIGINT *e,const UINT32 nth);

/**
*   
*   set a =  2^ {BIGINTSIZE} - 1 mod p
**/
void bgn_fp_set_max(BGNFP_MD_ID bgnfp_md_id,BIGINT * a);

/**
*
*   if src = 0, then return EC_TRUE
*   if src !=0, then return EC_FALSE
*
**/
EC_BOOL bgn_fp_is_zero(BGNFP_MD_ID bgnfp_md_id,const BIGINT* src);

/**
*
*   if src = 1, then return EC_TRUE
*   if src !=1, then return EC_FALSE
*
**/
EC_BOOL bgn_fp_is_one(BGNFP_MD_ID bgnfp_md_id,const BIGINT* src);

/**
*
*   if src is odd, then return EC_TRUE
*   if src is even, then return EC_FALSE
*
**/
EC_BOOL bgn_fp_is_odd(BGNFP_MD_ID bgnfp_md_id,BIGINT *src);

/**
*   let a belong to [0, p - 1], then 
*       c = ( a >> WORDSIZE ) mod n = (a >> nbits)
*   return c 
*
*   maybe address of c = address of a 
**/
void bgn_fp_shr_onewordsize(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,BIGINT *c);


/** 
*   let a belong to [0, p - 1], then 
*       c = ( a >> nbits ) mod p = (a >> nbits)
*   return c
*
**/
void bgn_fp_shr_lesswordsize(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a, const UINT32 nbits,BIGINT *c);


/** 
*   let a belong to [0, p - 1], then 
*       c = ( a << WORDSIZE ) mod p
*   return c
*
**/
void bgn_fp_shl_onewordsize(BGNFP_MD_ID bgnfp_md_id,const BIGINT * a, BIGINT * c);

/** 
*   let a belong to [0, p - 1], then 
*       c = ( a << nbits ) mod p
*   return c
*
**/
void bgn_fp_shl_lesswordsize(BGNFP_MD_ID bgnfp_md_id,const BIGINT * a, const UINT32 nbits, BIGINT * c);

/**
**   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_fp_naf(BGNFP_MD_ID bgnfp_md_id,const BIGINT *k,int *s);

/**
*
*       c = ( a + b ) mod p
*       where a < p and b < p
*
**/
void bgn_fp_add(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,const BIGINT *b, BIGINT *c );

/**
*       c = ( a - b ) mod p
*       where a < p and b < p
*
**/
void bgn_fp_sub(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,const BIGINT *b,BIGINT *c );

/**
void bgn_fp_neg(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,BIGINT *c );
*       c = ( a * b ) mod p
*       where a < p and b < p
*
**/
void bgn_fp_mul(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,const BIGINT *b,BIGINT *c );

/**
*       c = ( a ^ 2 ) mod p
*       where a < p 
*
**/
void bgn_fp_squ(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,BIGINT *c );

/**
*       c = ( a ^ e ) mod p
*       where 0 < a < p and e < 2 ^ WORDSIZE
*
**/
void bgn_fp_sexp(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,const UINT32 e,BIGINT *c );

/**
*       c = ( a ^ e ) mod p
*       where 0 < a < p and e < 2 ^ BIGINTSIZE
* 
**/
void bgn_fp_exp(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,const BIGINT *e,BIGINT *c );

/**
*
*   if a = 0 , then return EC_FALSE
*   if p > a > 0 and GCD(a,p) > 1, then return EC_FALSE
*   if p > a > 0 and GCD(a,p) = 1, then return EC_TRUE and
*       c = ( 1 / a ) mod p
*   where 0 < a < p 
*
**/
EC_BOOL bgn_fp_inv(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,BIGINT *c );

/**
*
*   assume p is odd prime and a belong to [ 0.. p -1 ]
*
*   return the legendre symbol (a/p)
*   
**/
int bgn_fp_legendre(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a);

/**
*   
*   let p mod 8 = 3 or 5 or 7. 
*   and Legendre symbol (a/p) = 1, then
*   compute one solution of congruence
*           x^2 = a mod p
*
*   Note:
*       not support p mod 8 = 1 at present
*
**/
EC_BOOL bgn_fp_squroot(BGNFP_MD_ID bgnfp_md_id,const BIGINT *a,BIGINT *c);
#endif /* _LIB_BGNFP_H */

⌨️ 快捷键说明

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