Mercurial > dropbear
comparison tomsfastmath/demo/stest.c @ 643:a362b62d38b2 dropbear-tfm
Add tomsfastmath from git rev bfa4582842bc3bab42e4be4aed5703437049502a
with Makefile.in renamed
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 23 Nov 2011 18:10:20 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
642:33fd2f3499d2 | 643:a362b62d38b2 |
---|---|
1 /* A simple static test program. */ | |
2 #include <tfm.h> | |
3 | |
4 #ifdef GBA_MODE | |
5 #include <gba.h> | |
6 #define DISPLAY(x) modetxt_puts(vfb, x, 1) | |
7 #endif | |
8 | |
9 #ifndef DISPLAY | |
10 #define DISPLAY(x) printf(x) | |
11 #endif | |
12 | |
13 | |
14 #ifdef GBA_MODE | |
15 int c_main(void) | |
16 #else | |
17 int main(void) | |
18 #endif | |
19 { | |
20 fp_int a,b,c,d,e,f; | |
21 fp_digit dp; | |
22 | |
23 fp_init(&a); | |
24 fp_init(&b); | |
25 fp_init(&c); | |
26 fp_init(&d); | |
27 fp_init(&e); | |
28 fp_init(&f); | |
29 | |
30 #ifdef GBA_MODE | |
31 install_common(); | |
32 modetxt_init(); | |
33 modetxt_gotoxy(0,0); | |
34 #endif | |
35 | |
36 /* test multiplication */ | |
37 fp_read_radix(&a, "3453534534535345345341230891273", 10); | |
38 fp_read_radix(&b, "2394873294871238934718923" , 10); | |
39 fp_read_radix(&c, "8270777629674273015508507050766235312931312159028658979", 10); | |
40 fp_mul(&a, &b, &d); | |
41 if (fp_cmp(&c, &d)) { | |
42 DISPLAY("mul failed\n"); | |
43 return 0; | |
44 } else { | |
45 DISPLAY("mul passed\n"); | |
46 } | |
47 | |
48 /* test multiplication */ | |
49 fp_read_radix(&a, "30481290320498235987349712308523652378643912563478232907782361237864278207235782364578264891274789264278634289739", 10); | |
50 fp_read_radix(&b, "48761478126387263782638276327836287632836278362837627838736278362923698724823749238732" , 10); | |
51 fp_read_radix(&c, "1486312771227034563307950634490737985563993459700941115664257275795366623795590136120579100118233580357115074068815507257715906295105536107921754177810976863679300283932188006885811950341132768970948", 10); | |
52 fp_mul(&a, &b, &d); | |
53 if (fp_cmp(&c, &d)) { | |
54 DISPLAY("mul failed\n"); | |
55 return 0; | |
56 } else { | |
57 DISPLAY("mul passed\n"); | |
58 } | |
59 | |
60 /* test multiplication */ | |
61 fp_read_radix(&a, "115792089237316195423570985008687907853269984665640564039457584007913129639935", 10); | |
62 fp_read_radix(&b, "174224571863520493293247799005065324265471" , 10); | |
63 fp_read_radix(&c, "20173827172553973356686868531273530268200710714389071377794102651988800859098544338487575161443744102709980552583184385", 10); | |
64 fp_mul(&a, &b, &d); | |
65 if (fp_cmp(&c, &d)) { | |
66 DISPLAY("mul failed\n"); | |
67 return 0; | |
68 } else { | |
69 DISPLAY("mul passed\n"); | |
70 } | |
71 | |
72 /* test squaring */ | |
73 fp_read_radix(&a, "298723982748923478923473927489237289347238947238947238947238972893", 10); | |
74 fp_read_radix(&b, "89236017869379132235512787068367546521309689412262624434964313994127411682542855190667724226920696163962644836740110835385588789449" , 10); | |
75 fp_sqr(&a, &c); | |
76 if (fp_cmp(&c, &b)) { | |
77 DISPLAY("sqr failed\n"); | |
78 return 0; | |
79 } else { | |
80 DISPLAY("sqr passed\n"); | |
81 } | |
82 | |
83 fp_read_radix(&a, "397823894238973128942895123894327123941724927848927349274897238978927593487012378490184789429812734982738972389", 10); | |
84 fp_read_radix(&b, "158263850827461677491961439999264901067636282938352531932899298293270945997930087353471903166601507321298827087008336951419604640736464667188494668962822678461626245753696845719301945679092882499787869509090904187704367321" , 10); | |
85 fp_sqr(&a, &c); | |
86 if (fp_cmp(&c, &b)) { | |
87 DISPLAY("sqr failed\n"); | |
88 return 0; | |
89 } else { | |
90 DISPLAY("sqr passed\n"); | |
91 } | |
92 | |
93 fp_read_radix(&a, "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095", 10); | |
94 fp_read_radix(&b, "179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474097562152033539671286128252223189553839160721441767298250321715263238814402734379959506792230903356495130620869925267845538430714092411695463462326211969025" , 10); | |
95 fp_sqr(&a, &c); | |
96 if (fp_cmp(&c, &b)) { | |
97 DISPLAY("sqr failed\n"); | |
98 return 0; | |
99 } else { | |
100 DISPLAY("sqr passed\n"); | |
101 } | |
102 | |
103 | |
104 /* montgomery reductions */ | |
105 fp_read_radix(&a, "234892374892374893489123428937892781237863278637826327367637836278362783627836783678363", 10); | |
106 fp_read_radix(&b, "4447823492749823749234123489273987393983289319382762756425425425642727352327452374521", 10); | |
107 fp_read_radix(&c, "2396271882990732698083317035605836523697277786556053771759862552557086442129695099100", 10); | |
108 fp_montgomery_setup(&b, &dp); | |
109 fp_montgomery_reduce(&a, &b, dp); | |
110 if (fp_cmp(&a, &c)) { | |
111 DISPLAY("mont failed\n"); | |
112 return 0; | |
113 } else { | |
114 DISPLAY("mont passed\n"); | |
115 } | |
116 | |
117 fp_read_radix(&a, "2348923748923748934891234456645654645645684576353428937892781237863278637826327367637836278362783627836783678363", 10); | |
118 fp_read_radix(&b, "444782349274982374923412348927398739398328931938276275642542542564272735232745237452123424324324444121111119", 10); | |
119 fp_read_radix(&c, "45642613844554582908652603086180267403823312390990082328515008314514368668691233331246183943400359349283420", 10); | |
120 fp_montgomery_setup(&b, &dp); | |
121 fp_montgomery_reduce(&a, &b, dp); | |
122 if (fp_cmp(&a, &c)) { | |
123 DISPLAY("mont failed\n"); | |
124 return 0; | |
125 } else { | |
126 DISPLAY("mont passed\n"); | |
127 } | |
128 | |
129 fp_read_radix(&a, "234823424242342923748923748934891234456645654645645684576353424972378234762378623891236834132352375235378462378489378927812378632786378263273676378362783627555555555539568389052478124618461834763837685723645827529034853490580134568947341278498542893481762349723907847892983627836783678363", 10); | |
130 fp_read_radix(&b, "44478234927456563455982374923412348927398739398328931938276275642485623481638279025465891276312903262837562349056234783648712314678120389173890128905425242424239784256427", 10); | |
131 fp_read_radix(&c, "33160865265453361650564031464519042126185632333462754084489985719613480783282357410514898819797738034600484519472656152351777186694609218202276509271061460265488348645081", 10); | |
132 fp_montgomery_setup(&b, &dp); | |
133 fp_montgomery_reduce(&a, &b, dp); | |
134 if (fp_cmp(&a, &c)) { | |
135 DISPLAY("mont failed\n"); | |
136 return 0; | |
137 } else { | |
138 DISPLAY("mont passed\n"); | |
139 } | |
140 | |
141 | |
142 return 0; | |
143 } | |
144 | |
145 | |
146 /* $Source$ */ | |
147 /* $Revision$ */ | |
148 /* $Date$ */ |