📄 lib_bgnz.h
字号:
#ifndef _LIB_BIGINTZ_H
#define _LIB_BIGINTZ_H
#include "lib_type.h"
/**
*
* start bgn_z module
*
**/
void bgn_z_start();
/**
*
* end bgn_z module
*
**/
void bgn_z_end();
/**
* compare a and b
* if a > b, then return 1
* if a = b, then return 0
* if a < b, then return -1
**/
int bgn_z_cmp(const BIGINT * a,const BIGINT *b);
/**
* clone src to des
* return des where des = src
**/
void bgn_z_clone(const BIGINT * src,BIGINT * des);
/**
*
* if src = 0, then return EC_TRUE
* if src !=0, then return EC_FALSE
*
**/
EC_BOOL bgn_z_is_zero(const BIGINT* src);
/**
*
* if src = 1, then return EC_TRUE
* if src !=1, then return EC_FALSE
*
**/
EC_BOOL bgn_z_is_one(const BIGINT* src);
/**
*
* if src is odd, then return EC_TRUE
* if src is even, then return EC_FALSE
*
**/
EC_BOOL bgn_z_is_odd(const BIGINT *src);
/**
* if a = 0, then return 0
* if a > 0, then
* let M = 2 ^ BIGINTSIZE
* let a = SUM(a_i * M ^ i, i = 0..n, where a_n > 0 )
* return ( n + 1 )
*
**/
UINT32 bgn_z_get_len(const BIGINT *a);
/**
*
* set a = n
**/
void bgn_z_set_word(BIGINT *a, UINT32 n);
/**
*
* set a = 0
**/
void bgn_z_set_zero(BIGINT * a);
/**
*
* set a = 1
**/
void bgn_z_set_one(BIGINT * a);
/**
*
* set a = 2^ BIGINTSIZE - 1
**/
void bgn_z_set_max(BIGINT * a);
/**
* 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_z_parse_bits(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_z_naf(const BIGINT *k,int *s);
/**
* if a = 0, then nbits = 0
* else
* let a = SUM( a_i * 2 ^i, where i = 0..m where a_m > 0,i.e, a_m = 1 )
* then nbits = m + 1
* return nbits
**/
UINT32 bgn_z_get_nbits(const BIGINT *a);
/**
*
* let a = SUM(a_i * 2^i, where i = 0..N, N is enough large,a_i = 0 or 1)
* return a_{nthbit}
*
**/
UINT32 bgn_z_get_bit(const BIGINT *a, UINT32 nthbit);
/**
* let a = SUM(a_i * 2^i, where i = 0..BIGINTSIZE - 1,a_i = 0 or 1)
* then set a_{nthbit} = 1
* note:
* this function is able to deal with a = 0.
**/
void bgn_z_set_bit(BIGINT *a, UINT32 nthbit);
/**
* let a = SUM(a_i * 2^i, where i = 0..N, N is enough large,a_i = 0 or 1)
* then set a_{nthbit} = 0
* note:
* this function is able to deal with a = 0.
**/
void bgn_z_clear_bit(BIGINT *a, UINT32 nthbit);
/**
* return e = 2 ^ nth mod 2 ^ BIGINTSIZE
* = ( 1 << nth ) mod 2 ^ BIGINTSIZE
* where nth = 0,1,...
*
**/
void bgn_z_set_e(BIGINT *e,const UINT32 nth);
/**
* binary operation:
* c = a AND b (i.e, a & b )
**/
void bgn_z_bit_and(const BIGINT *a,const BIGINT *b, BIGINT *c );
/**
* binary operation:
* c = a OR b (i.e, a | b )
**/
void bgn_z_bit_or(const BIGINT *a,const BIGINT *b, BIGINT *c );
/**
* binary operation:
* c = a XOR b (i.e, a ^ b )
**/
void bgn_z_bit_xor(const BIGINT *a,const BIGINT *b, BIGINT *c );
/**
* return c = ( a >> WORDSIZE ) and the shifted out word is returned.
* where a = ( c << WORDSIZE ) + shift_out
* maybe address of c = address of a
**/
UINT32 bgn_z_shr_onewordsize(const BIGINT *a,BIGINT *c);
/**
* return c = ( a >> nbits ) and the shifted out word is returned.
* where 0 <= nbits < WORDSIZE
* where a = ( c << nbits ) + shift_out
* maybe address of c = address of a
**/
UINT32 bgn_z_shr_lesswordsize(const BIGINT *a, UINT32 nbits,BIGINT *c);
/**
* return c = ( a >> nbits ) and no shifted out word is returned.
* where 0 <= nbits
* maybe address of c = address of a
**/
void bgn_z_shr_no_shift_out(const BIGINT *a, UINT32 nbits,BIGINT *c);
/**
* let a = (a1,a0) = a1 * 2 ^BIGINTSIZE + a0
* let c = (c1,c0) = c1 * 2 ^BIGINTSIZE + c0
* return c = ( a >> nbits ) and no shifted out word is returned.
* where 0 <= nbits
* maybe address of c = address of a
**/
void bgn_z_dshr_no_shift_out(const BIGINT *a0,const BIGINT *a1,UINT32 nbits,BIGINT *c0,BIGINT *c1);
/**
* return c = ( a << WORDSIZE ) and the shifted out word is returned.
* where ( a << WORDSIZE ) = shift_out * 2 ^( BIGINTSIZE ) + c
* maybe address of c = address of a
**/
UINT32 bgn_z_shl_onewordsize(const BIGINT *a, BIGINT *c);
/**
* return c = ( a << nbits ) and the shifted out word is returned.
* where ( a << bnits ) = shift_out * 2 ^( BIGINTSIZE ) + c
* maybe address of c = address of a
**/
UINT32 bgn_z_shl_lesswordsize(const BIGINT *a, UINT32 nbits,BIGINT *c);
/**
* return c = ( a << nbits ) mod 2 ^ BIGINTSIZE
* and no shifted out word is returned.
* where 0 <= nbits
* maybe address of c = address of a
**/
void bgn_z_shl_no_shift_out(const BIGINT *a, UINT32 nbits,BIGINT *c);
/**
* let a = (a1,a0) = a1 * 2 ^BIGINTSIZE + a0
* let c = (c1,c0) = c1 * 2 ^BIGINTSIZE + c0
*
* return c = ( a << nbits ) mod 2 ^ {2 *BIGINTSIZE}
* and no shifted out word is returned.
* where 0 <= nbits
* maybe address of c = address of a
**/
void bgn_z_dshl_no_shift_out(const BIGINT *a0,const BIGINT *a1,UINT32 nbits,BIGINT *c0,BIGINT *c1);
/**
* c = ( carry, a + b )
**/
UINT32 bgn_z_add(const BIGINT *a,const BIGINT *b, BIGINT *c );
/**
* c = ( carry, a + b )
* where b < 2 ^ WORDSIZE
**/
UINT32 bgn_z_sadd(const BIGINT *a,const UINT32 b, BIGINT *c );
/**
* let a = (a1, a0) = a1 * 2^ BIGINTSIZE + a0
* c = (c1, c0) = c1 * 2^ BIGINTSIZE + c0
*
* return c = ( carry, a + b )
*
**/
UINT32 bgn_z_dadd(const BIGINT *a0,const BIGINT *a1,const BIGINT *b, BIGINT *c0, BIGINT *c1 );
/**
* c = ( borrow, a - b )
**/
UINT32 bgn_z_sub(const BIGINT *a,const BIGINT *b, BIGINT *c );
/**
* c = ( borrow, a - b )
* where b < 2 ^ WORDSIZE
**/
UINT32 bgn_z_ssub(const BIGINT *a,const UINT32 b, BIGINT *c );
/**
* let a = (a1, a0) = a1 * 2^ BIGINTSIZE + a0
* c = (c1, c0) = c1 * 2^ BIGINTSIZE + c0
*
* return c = ( borrow, a - b )
*
**/
UINT32 bgn_z_dsub(const BIGINT *a0,const BIGINT *a1,const BIGINT *b, BIGINT *c0, BIGINT *c1 );
/**
* return c1 * 2^BIGINTSIZE+ c0 = a * b
*
**/
void bgn_z_mul(const BIGINT *a,const BIGINT *b, BIGINT *c0,BIGINT *c1 );
/**
* return c1 * 2^BIGINTSIZE + c0 = a ^ 2
*
**/
void bgn_z_squ(const BIGINT *a,BIGINT *c0,BIGINT *c1 );
/**
* return (q, r) where a = b * q + r
*
**/
void bgn_z_div(const BIGINT *a,const BIGINT *b, BIGINT *q,BIGINT *r );
/**
* let a = (a1, a0) = a1 * 2^ BIGINTSIZE + a0
* q = (q1, q0) = q1 * 2^ BIGINTSIZE + q0
*
* return (q, r) where a = b * q + r
*
**/
void bgn_z_ddiv(const BIGINT *a0,const BIGINT *a1,const BIGINT *b,BIGINT *q0,BIGINT *q1,BIGINT *r );
/**
*
* return c = GCD(a,b)
*
**/
void bgn_z_gcd(const BIGINT *a,const BIGINT *b,BIGINT *c);
#endif/* _LIB_BIGINTZ_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -