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

📄 flint.h

📁 用扩展欧拉法求逆元 rsa算法的必须组成函数模块 带对话框
💻 H
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************//*                                                                            *//*  Functions for arithmetic and number theory with large integers in C       *//*  Software supplement to the book "Cryptography in C and C++"               *//*  by Michael Welschenbach, published by Apress Berkeley CA, 2001            *//*                                                                            *//*  Module flint.h          Revision: 13.01.2002                              *//*                                                                            *//*  Copyright (C) 1998-2003 by Michael Welschenbach                           *//*  Copyright (C) 1998-2003 by Springer-Verlag Berlin, Heidelberg             *//*  Copyright (C) 2001-2003 by Apress L.P., Berkeley, CA                      *//*  Copyright (C) 2002-2003 by Wydawnictwa MIKOM, Poland                      *//*  Copyright (C) 2002-2003 by PHEI, P.R.China                                *//*  Copyright (C) 2002-2003 by InfoBook, Korea                                *//*  Copyright (C) 2002-2003 by Triumph Publishing, Russia                     *//*                                                                            *//*  All Rights Reserved                                                       *//*                                                                            *//*  The software may be used for noncommercial purposes and may be altered,   *//*  as long as the following conditions are accepted without any              *//*  qualification:                                                            *//*                                                                            *//*  (1) All changes to the sources must be identified in such a way that the  *//*      changed software cannot be misinterpreted as the original software.   *//*                                                                            *//*  (2) The statements of copyright may not removed or altered.               *//*                                                                            *//*  (3) The following DISCLAIMER is accepted:                                 *//*                                                                            *//*  DISCLAIMER:                                                               *//*                                                                            *//*  There is no warranty for the software contained on this CD-ROM, to the    *//*  extent permitted by applicable law. The copyright holders provide the     *//*  software `as is' without warranty of any kind, either expressed or        *//*  implied, including, but not limited to, the implied warranty of fitness   *//*  for a particular purpose. The entire risk as to the quality and           *//*  performance of the program is with you.                                   *//*                                                                            *//*  In no event unless required by applicable law or agreed to in writing     *//*  will the copyright holders, or any of the individual authors named in     *//*  the source files, be liable to you for damages, including any general,    *//*  special, incidental or consequential damages arising out of any use of    *//*  the software or out of inability to use the software (including but not   *//*  limited to any financial losses, loss of data or data being rendered      *//*  inaccurate or losses sustained by you or by third parties as a result of  *//*  a failure of the software to operate with any other programs), even if    *//*  such holder or other party has been advised of the possibility of such    *//*  damages.                                                                  *//*                                                                            *//******************************************************************************//* Read flint.h only once */#ifndef __FLINTH__#define __FLINTH__/* Turn FLINT secure mode on */#if !(defined FLINT_SECURE || defined FLINT_UNSECURE)#define FLINT_SECURE#endif#ifdef  __cplusplusextern "C" {#endif#include <time.h>/******************************************************************************//* Macros                                                                     *//******************************************************************************//* Simple makros *//* Errorcodes    */#define E_CLINT_OK     0        /* Everything O.K.                            */#define E_CLINT_DBZ   -1        /* Division by zero                           */#define E_CLINT_OFL   -2        /* Overflow                                   */#define E_CLINT_UFL   -3        /* Underflow                                  */#define E_CLINT_MAL   -4        /* Error in memory allocation                 */#define E_CLINT_NOR   -5        /* Register not present                       */#define E_CLINT_BOR   -6        /* Base in str2clint_l() not valid            */#define E_CLINT_MOD   -7        /* Modulus even in ?mexp?m_l()                */#define E_CLINT_NPT   -8        /* Null-Pointer received                      */#define E_VCHECK_OK    0        /* CLINT-format O.K.                          */#define E_VCHECK_LDZ   1        /* vcheck_l-Warning: Leading zeros            */#define E_VCHECK_MEM  -1        /* vcheck_l-Error: Null-Pointer               */#define E_VCHECK_OFL  -2        /* vcheck_l-Error: Overflow                   *//**************************************************************//* Constants referring to the internal CLINT-representation   *//**************************************************************/#define BASE            0x10000UL#define BASEMINONE      0xffffU#define BASEMINONEL     0xffffUL#define DBASEMINONE     0xffffffffUL#define BASEDIV2        0x8000U#define DBASEDIV2       0x80000000U#define BITPERDGT       16UL#define LDBITPERDGT     4U/*******************************************************//* Number of digits of CLINT-ojects to base 0x10000    */#define CLINTMAXDIGIT   256U/*******************************************************/#define CLINTMAXSHORT   (CLINTMAXDIGIT + 1)#define CLINTMAXLONG    ((CLINTMAXDIGIT >> 1) + 1)#define CLINTMAXBYTE    (CLINTMAXSHORT << 1)#define CLINTMAXBIT     (CLINTMAXDIGIT << 4)/* Number of small prime numbers stored in smallprimes[] */#define NOOFSMALLPRIMES 6542/* Default number of registers in register bank */#define NOOFREGS        16U/* FLINT/C-Version */#define FLINT_VERMAJ        2       /* Major-Version */#define FLINT_VERMIN        3       /* Minor-Version *//* FLINT/C-Version as USHORT-value 0xhhll, hh=FLINT_VERMAJ, ll=FLINT_VERMIN */#define FLINT_VERSION   ((FLINT_VERMAJ << 8) + FLINT_VERMIN)#ifdef FLINT_COMPATIBILITY/* Macros for Compatibility with version 1.xx */#define E_OK     0              /* Everything O.K.                            */#define E_DBZ   -1              /* Division by zero                           */#define E_OFL   -2              /* Overflow                                   */#define E_UFL   -3              /* Underflow                                  */#define E_MAL   -4              /* Error in memory allocation                 */#define E_NOR   -5              /* Register not present                       */#define E_BOR   -6              /* Base in str2clint_l() not valid            */#define E_MOD   -7              /* Modulus even in ?mexp?m_l()                */#define E_NPT   -8              /* Null-Pointer received                      */#endif /* FLINT_COMPATIBILITY *//* Internationalization */#define ggT_l            gcd_l#define xggT_l           xgcd_l#define kgV_l            lcm_l#define zweiantei_l      twofact_l#define chinrest_l       chinrem_l#define primwurz_l       primroot_l/* LINT_ASM -> FLINT_ASM, LINT_ANSI -> FLINT_ANSI */#ifdef LINT_ASM#ifndef FLINT_ASM#define FLINT_ASM#endif /* !FLINT_ASM */#endif /* LINT_ASM */#ifdef LINT_ANSI#ifndef FLINT_ANSI#define FLINT_ANSI#endif /* !LINT_ANSI */#endif /* LINT_ANSI */#ifdef FLINT_ASM#define _FLINT_ASM       0x61       /* ASCII 'a': Symbol for     */#else                               /*  Assembler-support        */#define _FLINT_ASM          0#endif#ifdef FLINT_SECURE#define _FLINT_SECMOD    0x73       /* ASCII 's': Symbol for     */#else                               /*  security-mode, in which  */#define _FLINT_SECMOD       0       /*  all CLINT-Variables will */#endif                              /*  be purged after use      *//* Makros with parameters *//* Definition of standard-CLINT-Registers */#define r0_l  get_reg_l(0)#define r1_l  get_reg_l(1)#define r2_l  get_reg_l(2)#define r3_l  get_reg_l(3)#define r4_l  get_reg_l(4)#define r5_l  get_reg_l(5)#define r6_l  get_reg_l(6)#define r7_l  get_reg_l(7)#define r8_l  get_reg_l(8)#define r9_l  get_reg_l(9)#define r10_l get_reg_l(10)#define r11_l get_reg_l(11)#define r12_l get_reg_l(12)#define r13_l get_reg_l(13)#define r14_l get_reg_l(14)#define r15_l get_reg_l(15)/* MIN, MAX etc. */#ifndef MIN#define MIN(a,b) ((a)<(b)?(a):(b))#endif#ifndef MAX#define MAX(a,b) ((a)>(b)?(a):(b))#endif#define MIN_L(a,b) (lt_l ((a), (b)) ? (a) : (b))#define min_l(a,b) (lt_l ((a), (b)) ? (a) : (b))#define MAX_L(a,b) (gt_l ((a), (b)) ? (a) : (b))#define max_l(a,b) (gt_l ((a), (b)) ? (a) : (b))#ifndef SWAP#define SWAP(a,b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))#endif#ifndef swap#define swap(a,b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))#endif#define SWAP_L(a,b) (xor_l((a),(b),(a)),xor_l((b),(a),(b)),xor_l((a),(b),(a)))#define swap_l(a,b) (xor_l((a),(b),(a)),xor_l((b),(a),(b)),xor_l((a),(b),(a)))/* ReMoveLeaDingZeRoS from CLINT-variables */#define RMLDZRS_L(n_l) \    while ((DIGITS_L (n_l) > 0) && (*MSDPTR_L (n_l) == 0)) {DECDIGITS_L (n_l);}#define rmldzrs_l(n_l) \    while ((DIGITS_L (n_l) > 0) && (*MSDPTR_L (n_l) == 0)) {DECDIGITS_L (n_l);}/* Copy CLINT types with removal of leading zeros */#define ZCPY_L(dest_l,src_l)\    cpy_l ((dest_l), (src_l));\    RMLDZRS_L ((dest_l))#define zcpy_l(dest_l,src_l)\    cpy_l ((dest_l), (src_l));\    RMLDZRS_L ((dest_l))/* Reduction modulo Nmax + 1 */#define ANDMAX_L(a_l)\    SETDIGITS_L ((a_l), MIN (DIGITS_L (a_l), (USHORT)CLINTMAXDIGIT));\    RMLDZRS_L ((a_l))#define andmax_l(a_l)\    SETDIGITS_L ((a_l), MIN (DIGITS_L (a_l), (USHORT)CLINTMAXDIGIT));\    RMLDZRS_L ((a_l))/* Set CLINT-variables to values 0, 1, 2 resp. */#define SETZERO_L(n_l)\    (*(n_l) = 0)#define setzero_l(n_l)\    (*(n_l) = 0)#define SETONE_L(n_l)\    (u2clint_l ((n_l), 1U))#define setone_l(n_l)\    (u2clint_l ((n_l), 1U))#define SETTWO_L(n_l)\    (u2clint_l ((n_l), 2U))#define settwo_l(n_l)\    (u2clint_l ((n_l), 2U))/* Read the number of digits of a CLINT-variable */#define DIGITS_L(n_l)\    ((unsigned short)*(n_l))#define digits_l(n_l)\    ((unsigned short)*(n_l))/* Set the number of digits of a CLINT-variable */#define SETDIGITS_L(n_l, l)\    (*(n_l) = (unsigned short)(l))#define setdigits_l(n_l, l)\    (*(n_l) = (unsigned short)(l))/* Increment the number of digits of a CLINT-variable */#define INCDIGITS_L(n_l)\    (++*(n_l))#define incdigits_l(n_l)\    (++*(n_l))/* Decrement the number of digits of a CLINT-variable */#define DECDIGITS_L(n_l)\    Assert (DIGITS_L (n_l) > 0);\    (--*(n_l))#define decdigits_l(n_l)\    Assert (DIGITS_L (n_l) > 0);\    (--*(n_l))/* Pointer to the most significant digit of a CLINT variable */#define MSDPTR_L(n_l)\    ((n_l) + DIGITS_L (n_l))#define msdptr_l(n_l)\    ((n_l) + DIGITS_L (n_l))/* Pointer to the least significant digit of a CLINT variable */#define LSDPTR_L(n_l)\    ((n_l) + 1)#define lsdptr_l(n_l)\    ((n_l) + 1)/* Comparisons, setting, testing for evenness and oddness */#define LT_L(a_l,b_l) \    (cmp_l ((a_l), (b_l)) == -1)        /* a_l < b_l        */#define lt_l(a_l,b_l) \    (cmp_l ((a_l), (b_l)) == -1)        /* a_l < b_l        */#define LE_L(a_l,b_l) \    (cmp_l ((a_l), (b_l)) < 1)          /* a_l <= b_l       */#define le_l(a_l,b_l) \    (cmp_l ((a_l), (b_l)) < 1)          /* a_l <= b_l       */#define GT_L(a_l,b_l) \    (cmp_l ((a_l), (b_l)) == 1)         /* a_l > b_l        */#define gt_l(a_l,b_l) \    (cmp_l ((a_l), (b_l)) == 1)         /* a_l > b_l        */#define GE_L(a_l,b_l) \    (cmp_l ((a_l), (b_l)) > -1)         /* a_l >= b_l       */#define ge_l(a_l,b_l) \    (cmp_l ((a_l), (b_l)) > -1)         /* a_l >= b_l       */#define GTZ_L(a_l) \

⌨️ 快捷键说明

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