Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /********************************************************************* |
2 | * |
||
3 | * Big Integer Class Headers |
||
4 | * |
||
5 | ********************************************************************* |
||
6 | * FileName: BigInt.h |
||
7 | * Dependencies: Compiler.h, GenericTypeDefs.h |
||
8 | * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32 |
||
9 | * Compiler: Microchip C32 v1.05 or higher |
||
10 | * Microchip C30 v3.12 or higher |
||
11 | * Microchip C18 v3.30 or higher |
||
12 | * HI-TECH PICC-18 PRO 9.63PL2 or higher |
||
13 | * Company: Microchip Technology, Inc. |
||
14 | * |
||
15 | * Software License Agreement |
||
16 | * |
||
17 | * Copyright (C) 2002-2009 Microchip Technology Inc. All rights |
||
18 | * reserved. |
||
19 | * |
||
20 | * Microchip licenses to you the right to use, modify, copy, and |
||
21 | * distribute: |
||
22 | * (i) the Software when embedded on a Microchip microcontroller or |
||
23 | * digital signal controller product ("Device") which is |
||
24 | * integrated into Licensee's product; or |
||
25 | * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, |
||
26 | * ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device |
||
27 | * used in conjunction with a Microchip ethernet controller for |
||
28 | * the sole purpose of interfacing with the ethernet controller. |
||
29 | * |
||
30 | * You should refer to the license agreement accompanying this |
||
31 | * Software for additional information regarding your rights and |
||
32 | * obligations. |
||
33 | * |
||
34 | * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT |
||
35 | * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT |
||
36 | * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
||
37 | * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
38 | * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR |
||
39 | * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF |
||
40 | * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS |
||
41 | * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE |
||
42 | * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER |
||
43 | * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT |
||
44 | * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. |
||
45 | * |
||
46 | * |
||
47 | * Author Date Comment |
||
48 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
49 | * Elliott Wood 2/15/07 Original |
||
50 | ********************************************************************/ |
||
51 | |||
52 | #ifndef __BIGINT_H |
||
53 | #define __BIGINT_H |
||
54 | |||
55 | #define BIGINT_DEBUG 0 |
||
56 | #define BIGINT_DEBUG_COMPARE 0 |
||
57 | #define RSAEXP_DEBUG 0 |
||
58 | |||
59 | #if defined(__18CXX) |
||
60 | #define BIGINT_DATA_SIZE 8ul //bits |
||
61 | #define BIGINT_DATA_TYPE BYTE |
||
62 | #define BIGINT_DATA_MAX 0xFFu |
||
63 | #define BIGINT_DATA_TYPE_2 WORD |
||
64 | #elif defined(__C30__) |
||
65 | #define BIGINT_DATA_SIZE 16ul //bits |
||
66 | #define BIGINT_DATA_TYPE WORD |
||
67 | #define BIGINT_DATA_MAX 0xFFFFu |
||
68 | #define BIGINT_DATA_TYPE_2 DWORD |
||
69 | #elif defined(__C32__) |
||
70 | #define BIGINT_DATA_SIZE 32ul //bits |
||
71 | #define BIGINT_DATA_TYPE DWORD |
||
72 | #define BIGINT_DATA_MAX 0xFFFFFFFFu |
||
73 | #define BIGINT_DATA_TYPE_2 QWORD |
||
74 | #endif |
||
75 | |||
76 | typedef struct |
||
77 | { |
||
78 | BIGINT_DATA_TYPE *ptrLSB; // Pointer to the least significant byte/word (lowest memory address) |
||
79 | BIGINT_DATA_TYPE *ptrMSB; // Pointer to the first non-zero most significant byte/word (higher memory address) if bMSBValid set |
||
80 | BIGINT_DATA_TYPE *ptrMSBMax; // Pointer to the maximum memory address that ptrMSB could ever be (highest memory address) |
||
81 | BOOL bMSBValid; |
||
82 | } BIGINT; |
||
83 | |||
84 | #if defined(__18CXX) |
||
85 | typedef struct _BIGINT_ROM |
||
86 | { |
||
87 | ROM BIGINT_DATA_TYPE *ptrLSB; |
||
88 | ROM BIGINT_DATA_TYPE *ptrMSB; |
||
89 | } BIGINT_ROM; |
||
90 | #else |
||
91 | #define BIGINT_ROM BIGINT |
||
92 | #endif |
||
93 | |||
94 | |||
95 | void BigInt(BIGINT *theInt, BIGINT_DATA_TYPE *data, WORD wWordLength); |
||
96 | void BigIntMod(BIGINT*, BIGINT*); |
||
97 | void BigIntMultiply(BIGINT*, BIGINT*, BIGINT*); |
||
98 | |||
99 | void BigIntAdd(BIGINT*, BIGINT*); |
||
100 | void BigIntSubtract(BIGINT*, BIGINT*); |
||
101 | void BigIntSubtractROM(BIGINT*, BIGINT_ROM*); |
||
102 | void BigIntCopy(BIGINT*, BIGINT*); |
||
103 | void BigIntSquare(BIGINT *a, BIGINT *res); |
||
104 | void BigIntZero(BIGINT *theInt); |
||
105 | |||
106 | int BigIntMagnitudeDifference(BIGINT *a, BIGINT *b); |
||
107 | int BigIntMagnitudeDifferenceROM(BIGINT *a, BIGINT_ROM *b); |
||
108 | CHAR BigIntCompare(BIGINT*, BIGINT*); |
||
109 | WORD BigIntMagnitude(BIGINT *n); |
||
110 | |||
111 | void BigIntSwapEndianness(BIGINT *a); |
||
112 | |||
113 | void BigIntPrint(const BIGINT *a); |
||
114 | |||
115 | |||
116 | #if defined(__18CXX) |
||
117 | void BigIntROM(BIGINT_ROM *theInt, ROM BIGINT_DATA_TYPE *data, WORD wWordLength); |
||
118 | void BigIntModROM(BIGINT*, BIGINT_ROM*); |
||
119 | void BigIntMultiplyROM(BIGINT*, BIGINT_ROM*, BIGINT*); |
||
120 | void BigIntAddROM(BIGINT*, BIGINT_ROM*); |
||
121 | void BigIntCopyROM(BIGINT*, BIGINT_ROM*); |
||
122 | CHAR BigIntCompareROM(BIGINT*, BIGINT_ROM*); |
||
123 | WORD BigIntMagnitudeROM(BIGINT_ROM *n); |
||
124 | |||
125 | extern ROM BIGINT_DATA_TYPE *_iBr, *_xBr; |
||
126 | |||
127 | void BigIntPrintROM(BIGINT_ROM*); |
||
128 | #else |
||
129 | #define BigIntROM(a,b,c) BigInt(a,((BIGINT_DATA_TYPE*)(b)),c) |
||
130 | #define BigIntModROM(a,b) BigIntMod(a,b) |
||
131 | #define BigIntMultiplyROM(a,b,c) BigIntMultiply(a,b,c) |
||
132 | #define BigIntAddROM(a,b) BigIntAdd(a,b) |
||
133 | #define BigIntCopyROM(a,b) BigIntCopy(a,b) |
||
134 | #define BigIntCompareROM(a,b) BigIntCompare(a,b) |
||
135 | #define BigIntMagnitudeROM(a) BigIntMagnitude(a) |
||
136 | #endif |
||
137 | |||
138 | |||
139 | #endif |
Powered by WebSVN v2.8.3