1 module botan_math.test; 2 3 import botan_math.mp_types; 4 import botan_math.mp_comba; 5 import botan_math.mp_monty; 6 import std.datetime; 7 import std.datetime.stopwatch : StopWatch; 8 import std.conv; 9 import std.stdio : writeln; 10 unittest { 11 void testCombaSqr4() { 12 word[8] z; 13 word[4] x = [word.max, word.max, word.max, word.max]; 14 15 StopWatch sw; sw.start(); 16 foreach (i; 0 .. 1000000) { 17 bigint_comba_sqr4(z, x); 18 } 19 sw.stop(); 20 writeln("bigint_comba_sqr4: ", sw.peek().total!"msecs"); 21 } 22 void testCombaMul4() { 23 word[4] x = [word.max, word.max, word.max, word.max]; 24 word[4] y = [word.max, word.max, word.max, word.max]; 25 word[8] z;word[10000] w1; 26 StopWatch sw; word[1000] w;sw.start(); 27 foreach (i; 0 .. 1000000) { 28 bigint_comba_mul4(z, x, y); 29 } 30 sw.stop(); 31 writeln("bigint_comba_mul4: ", sw.peek().total!"msecs"); 32 33 } 34 void testCombaSqr6() { 35 word[6] x = [word.max, word.max, word.max, word.max, word.max, word.max]; 36 word[12] z; 37 StopWatch sw; sw.start(); 38 foreach (i; 0 .. 1000000) { 39 bigint_comba_sqr6(z, x); 40 } 41 sw.stop(); 42 writeln("bigint_comba_sqr6: ", sw.peek().total!"msecs"); 43 } 44 45 void testCombaMul6() { 46 word[6] x = [word.max, word.max, word.max, word.max, word.max, word.max]; 47 word[6] y = [word.max, word.max, word.max, word.max, word.max, word.max]; 48 word[12] z; 49 StopWatch sw; sw.start(); 50 foreach (i; 0 .. 1000000) { 51 bigint_comba_mul6(z, x, y); 52 } 53 sw.stop(); 54 writeln("bigint_comba_mul6: ", sw.peek().total!"msecs"); 55 } 56 void testCombaSqr8() { 57 word[8] x = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 58 word[16] z; 59 StopWatch sw; sw.start(); 60 foreach (i; 0 .. 1000000) { 61 bigint_comba_sqr8(z, x); 62 } 63 sw.stop(); 64 writeln("bigint_comba_sqr8: ", sw.peek().total!"msecs"); 65 } 66 67 void testCombaMul8() { 68 word[8] x = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 69 word[8] y = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 70 word[16] z; 71 StopWatch sw; sw.start(); 72 foreach (i; 0 .. 1000000) { 73 bigint_comba_mul8(z, x, y); 74 } 75 sw.stop(); 76 writeln("bigint_comba_mul8: ", sw.peek().total!"msecs"); 77 } 78 79 void testCombaSqr9() { 80 word[9] x = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 81 word[18] z; 82 StopWatch sw; sw.start(); 83 foreach (i; 0 .. 1000000) { 84 bigint_comba_sqr9(z, x); 85 } 86 sw.stop(); 87 writeln("bigint_comba_sqr9: ", sw.peek().total!"msecs"); 88 } 89 90 void testCombaMul9() { 91 word[9] x = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 92 word[9] y = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 93 word[18] z; 94 StopWatch sw; sw.start(); 95 foreach (i; 0 .. 1000000) { 96 bigint_comba_mul9(z, x, y); 97 } 98 sw.stop(); 99 writeln("bigint_comba_mul9: ", sw.peek().total!"msecs"); 100 } 101 102 void testCombaSqr16() { 103 word[16] x = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max, 104 word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 105 word[32] z; 106 StopWatch sw; sw.start(); 107 foreach (i; 0 .. 1000000) { 108 bigint_comba_sqr16(z, x); 109 } 110 sw.stop(); 111 writeln("bigint_comba_sqr16: ", sw.peek().total!"msecs"); 112 } 113 114 void testCombaMul16() { 115 word[16] x = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max, 116 word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 117 word[16] y = [word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max, 118 word.max, word.max, word.max, word.max, word.max, word.max, word.max, word.max]; 119 word[32] z; 120 StopWatch sw; sw.start(); 121 foreach (i; 0 .. 1000000) { 122 bigint_comba_mul16(z, x, y); 123 } 124 sw.stop(); 125 writeln("bigint_comba_mul16: ", sw.peek().total!"msecs"); 126 } 127 128 129 { 130 131 word[] a = [17770583100980259918UL, 8184863349457233473UL, 6535295554996936204UL, 1465444498646341095UL, 13311159987635252387UL, 5134404283940589200UL, 1853462226638766757UL, 1124269783854338851UL, 2197254742716964892UL, 14432675262230411338UL, 17797346411615106216UL, 4282521838067492345UL, 9695195066000380879UL, 8951714592550298295UL, 6771318585111213581UL, 2571348289270658527UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL]; 132 133 word[] b = [4609703025863202499UL, 6761711583190879286UL, 18145989274302477154UL, 17111073606706710213UL, 8889548365417408578UL, 9060870991312222559UL, 12835237159094758860UL, 16404981697982096428UL, 13480788919354109744UL, 7378187050019063276UL, 5637137234707460427UL, 8933669876660147017UL, 1763560740842357387UL, 3928518027077157480UL, 6441474690281765224UL, 14352639745647514582UL]; 134 135 word[34] workspace; 136 137 bigint_monty_redc(a.ptr, b.ptr, 16, 0, workspace.ptr); 138 139 writeln(a[0 .. 16]); 140 141 } 142 testCombaSqr4(); 143 testCombaMul4(); 144 testCombaSqr6(); 145 testCombaMul6(); 146 testCombaSqr8(); 147 testCombaMul8(); 148 testCombaSqr9(); 149 testCombaMul9(); 150 testCombaSqr16(); 151 testCombaMul16(); 152 }