X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/Security/libsecurity_cryptkit/lib/CurveParamDocs/giants.h diff --git a/Security/libsecurity_cryptkit/lib/CurveParamDocs/giants.h b/Security/libsecurity_cryptkit/lib/CurveParamDocs/giants.h new file mode 100644 index 00000000..d25ffffb --- /dev/null +++ b/Security/libsecurity_cryptkit/lib/CurveParamDocs/giants.h @@ -0,0 +1,314 @@ +/************************************************************** + * + * giants.h + * + * Header file for large-integer arithmetic library giants.c. + * + * Updates: + * 18 Jul 99 REC Added fer_mod(). + * 30 Apr 98 JF USE_ASSEMBLER_MUL removed + * 29 Apr 98 JF Function prototypes cleaned up + * 20 Apr 97 RDW + * + * c. 1997 Perfectly Scientific, Inc. + * All Rights Reserved. + * + **************************************************************/ + + +/************************************************************** + * + * Error Codes + * + **************************************************************/ + +#define DIVIDEBYZERO 1 +#define OVFLOW 2 +#define SIGN 3 +#define OVERRANGE 4 +#define AUTO_MUL 0 +#define GRAMMAR_MUL 1 +#define FFT_MUL 2 +#define KARAT_MUL 3 + +/************************************************************** + * + * Preprocessor definitions + * + **************************************************************/ + +/* 2^(16*MAX_SHORTS)-1 will fit into a giant, but take care: + * one usually has squares, etc. of giants involved, and + * every intermediate giant in a calculation must fit into + * this many shorts. Thus, if you want systematically to effect + * arithmetic on B-bit operands, you need MAX_SHORTS > B/8, + * perferably a tad larger than this; e.g. MAX_SHORTS > B/7. + */ +#define MAX_SHORTS (1<<19) + +#define INFINITY (-1) +#define FA 0 +#define TR 1 +#define COLUMNWIDTH 64 + +#define TWOPI (double)(2*3.1415926535897932384626433) +#define SQRT2 (double)(1.414213562373095048801688724209) +#define SQRTHALF (double)(0.707106781186547524400844362104) +#define TWO16 (double)(65536.0) +#define TWOM16 (double)(0.0000152587890625) + +/* Decimal digit ceiling in digit-input routines. */ +#define MAX_DIGITS 10000 + +/* Next, mumber of shorts per operand + at which Karatsuba breaks over. */ +#define KARAT_BREAK 40 + +/* Next, mumber of shorts per operand + at which FFT breaks over. */ +#define FFT_BREAK 200 + +#define newmin(a,b) ((a)<(b)? (a) : (b)) +#define newmax(a,b) ((a)>(b)? (a) : (b)) + +/* Maximum number of recursive steps needed to calculate + * gcds of integers. */ +#define STEPS 32 + +/* The limit below which hgcd is too ponderous */ +#define GCDLIMIT 5000 + +/* The limit below which ordinary ints will be used */ +#define INTLIMIT 31 + +/* Size by which to increment the stack used in pushg() and popg(). */ +#define STACK_GROW 16 + +#define gin(x) gread(x,stdin) +#define gout(x) gwriteln(x,stdout) + + +/************************************************************** + * + * Structure definitions + * + **************************************************************/ + +typedef struct +{ + int sign; + unsigned short n[1]; /* number of shorts = abs(sign) */ +} giantstruct; + +typedef giantstruct *giant; + +typedef struct _matrix +{ + giant ul; /* upper left */ + giant ur; /* upper right */ + giant ll; /* lower left */ + giant lr; /* lower right */ +} *gmatrix; + +typedef struct +{ + double re; + double im; +} complex; + + +/************************************************************** + * + * Function Prototypes + * + **************************************************************/ + +/************************************************************** + * + * Initialization and utility functions + * + **************************************************************/ + +/* trig lookups. */ +void init_sinCos(int); +double s_sin(int); +double s_cos(int); + + +/* Creates a new giant, numshorts = INFINITY invokes the + * maximum MAX_SHORTS. */ +giant newgiant(int numshorts); + +/* Creates a new giant matrix, but does not malloc + * the component giants. */ +gmatrix newgmatrix(void); + +/* Returns the bit-length n; e.g. n=7 returns 3. */ +int bitlen(giant n); + +/* Returns the value of the pos bit of n. */ +int bitval(giant n, int pos); + +/* Returns whether g is one. */ +int isone(giant g); + +/* Returns whether g is zero. */ +int isZero(giant g); + +/* Copies one giant to another. */ +void gtog(giant src, giant dest); + +/* Integer <-> giant. */ +void itog(int n, giant g); +signed int gtoi (giant); + +/* Returns the sign of g: -1, 0, 1. */ +int gsign(giant g); + +/* Returns 1, 0, -1 as a>b, a=b, a