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

📄 xbn_vsmath.h

📁 IBE是一种非对称密码技术
💻 H
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */

#include "ictk.h"

#ifndef XBN_VSMATH_H
#define XBN_VSMATH_H

#ifdef __cplusplus
extern "C" {
#endif

/* Allocates and inits new multi-precision number. This function does
 * not check on the validity of the mpCtx arg, it is the responsibility
 * of the caller to pass in a valid mpCtx.
 */
int vsm_zNew (
   VoltMpIntCtx *mpCtx,
   vsm_z_t **newZ
   );

/* Clears and deallocates the multi-precision number.
 */
void vsm_zDel (
   vsm_z_t *x
   );

/* Return "TRUE" (non-zero value) if the input arg is zero.
 * Return "FALSE" (zero) if the input arg is not 0.
 */
bool_t vsm_zIsZero (
   vsm_z_t *a
   );

/* Return "TRUE" (non-zero value) if the two are equal.
 * Return "FALSE" (zero) if the two are not equal.
 */
bool_t vsm_zIsEqual (
   vsm_z_t *a,
   vsm_z_t *b,
   bf_context_t *bf
   );

/* The base (the b argument) must be either 2 or 256.
 * If the base is 2, this gives the number of bits that make up the
 * number.
 * If the base is 256, this gives the number of octets that make up the
 * number.
 * This function does not return an error, so bad args result in a
 * return of length 0.
 */
unsigned int vsm_zSizeInBase (
   vsm_z_t *a,
   int b
   );

/* Return "TRUE" (non-zero value) if the number is odd.
 * Return "FALSE" (zero) if it is not.
 */
bool_t vsm_zIsOdd (
   vsm_z_t *a,
   bf_context_t *bf);

/* Return "TRUE" (non-zero value) if the number is even.
 * Return "FALSE" (zero) if it is not.
 */
bool_t vsm_zIsEven (
   vsm_z_t *a,
   bf_context_t *bf);

/* Set x = a
 * Return 0 for success, non-zero error code.
 */
int vsm_zSet (
   vsm_z_t *x,
   vsm_z_t *a
   );

/* Set x = u
 */
int vsm_zSetUI (
   vsm_z_t *x,
   unsigned int u
   );

/* Sets bit b to 0 or 1.
 * If v is zero, this sets the bit to 0 (clears the bit). If v is not
 * zero, this sets the bit to 1.
 */
int vsm_zSetBit (
   vsm_z_t *x,
   unsigned int b,
   unsigned int v
   );

/* Return +1 if a > 0, 0 if a == 0, -1 if a < 0.
 */
int vsm_zSgn (
   vsm_z_t *a
   );

/* compare a to b
 */
int vsm_zCmp (
   vsm_z_t *a,
   vsm_z_t *b
   );

/* compare a to u
 */
int vsm_zCmpUI (
   vsm_z_t *a,
   unsigned int u
   );

/* x = a + b
 */
int vsm_zAdd (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *b
   );

/* x = a + u
 */
int vsm_zAddUI (
   vsm_z_t *x,
   vsm_z_t *a,
   unsigned int u
   );

/* x = a - b
 */
int vsm_zSub (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *b
   );

/* x = a - u
 */
int vsm_zSubUI (
   vsm_z_t *x,
   vsm_z_t *a,
   unsigned int u
   );

/* x = a * b
 */
int vsm_zMul (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *b
   );

/* x = a * u
 */
int vsm_zMulUI (
   vsm_z_t *x,
   vsm_z_t *a,
   unsigned int u
   );

/* x = a / u (integer div)
 * This is simply the quotient portion of a division.
 *    a / u --> x with remainder
 *    a / u --> x*u + r, for some integer n and a remainder < u
 */
int vsm_zDivUI (
   vsm_z_t *x,
   vsm_z_t *a,
   unsigned int u
   );

/* x = a mod b
 */
int vsm_zMod (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *b
   );

/* x = a mod u
 * This function does not check whether x is a valid pointer or not.
 */
int vsm_zModUI (
   vsm_z_t *a,
   unsigned int u,
   unsigned int *x
   );

/* x = a ^ b (mod p)
 */
int vsm_zPowM (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *b,
   vsm_z_t *p
   );

/* x = a * 2 ^ u
 */
int vsm_zMul2exp (
   vsm_z_t *x,
   vsm_z_t *a,
   unsigned int u
   );

/* x = 1/a mod p
 * find x s.t. x * a mod p is 1
 */
int vsm_zInvert (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *p
   );

/* x = a * a
 */
int vsm_zSqr (
   vsm_z_t *x,
   vsm_z_t *a
   );

/* If the nth bit is 0, return 0, if it is 1, return 1.
 */
int vsm_zTestBit (
   vsm_z_t *a,
   unsigned int n
   );

/* Start with bit n, find the index of the next bit (moving from least
 * significant bit to most significant bit) that is 1. If the bit at
 * index n is 1, return n.
 * <p>For example, if the number is 0x000401f8,
 * <code>
 * <pre>
 *     vsm_Scan1 (number, 0) is 3
 *     vsm_Scan1 (number, 5) is 5
 *     vsm_Scan1 (number, 9) is 17
 * </pre>
 * </code>
 * If the start index given (the n argument) is beyond the end of the
 * number, return a value > the total bit length of the number. For
 * example, the number 0x000401f8 is 19 bits long.
 * <code>
 * <pre>
 *     vsm_Scan1 (number, 25) might be 26.
 * </pre>
 * </code>
 * It is the responsibility of the caller to know whether the return
 * value is beyond the end.
 */
int vsm_zScan1 (
   vsm_z_t *a,
   unsigned int n
   );

/* x = floor (a / 2^n)
 * This is simply the quotient portion of a division.
 *    a / 2^n --> x with remainder
 *    a / 2^n --> x*(2^n) + r, for some integer n and a remainder < 2^n
 */
int vsm_zFDiv2exp (
   vsm_z_t *x,
   vsm_z_t *a,
   unsigned int n
   );

/* x = floor (a / b)
 * This is simply the quotient portion of a division.
 *    a / b --> x with remainder
 *    a / b --> x*b + r, for some integer n and a remainder < b
 */
int vsm_zFDiv (
   vsm_z_t *x,
   vsm_z_t *a,
   vsm_z_t *b
   );

/* big-endian encoding of a bignum into a fixed-length raw byte string
 * Return 0 for success, non-zero error code.
 */
int vsm_zRawEncode (
   unsigned char *out,
   unsigned int sz,
   vsm_z_t *x
   );

/* big-endian decoding of a bignum from a fixed-length raw byte string
 */
int vsm_zRawDecode (
   vsm_z_t *x,
   unsigned char *in,
   unsigned int sz
   );

#ifdef __cplusplus
}
#endif

#endif /* XBN_VSMATH_H */

⌨️ 快捷键说明

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