tree checksum vpatch file split hunks

all signers: diana_coman ben_vulpes peterl spyked asciilifeform

antecedents: ffa_ch7_turbo_egyptians ffa_ch6_simplest_rsa ffa_ch4_ffacalc

press order:

ffa_ch1_genesisasciilifeform ben_vulpes diana_coman peterl spyked
ffa_ch2_logicalsasciilifeform ben_vulpes diana_coman peterl spyked
ffa_ch3_shiftsasciilifeform ben_vulpes diana_coman peterl spyked
ffa_ch4_ffacalcasciilifeform ben_vulpes peterl spyked
ffa_ch5_egyptasciilifeform
ffa_ch6_simplest_rsaasciilifeform
ffa_ch7_turbo_egyptiansasciilifeform
ffa_ch8_randomismasciilifeform

patch:

- 26B51D3E6AFCA55540D015309958F470CEA6B57222B3BA4ACC9E215DE737AD1747C817E417414888DE872839A7531F4E0F4835B706930320AF3CE10DB40F248D
+ 002A7F1B09D1DE08407D2BC98BD142821A83690C56BEE4F841EB810473AD627F71468F4DEEB11CB47D5A57CE8C72A4473FDA368FD6E0AF4119A36A7020EA4E43
ffa/ffacalc/cmdline.ads
(34 . 12)(34 . 12)
5 procedure Get_Argument(Number : in Natural;
6 Result : out String);
7
8 function Len_Arg (Arg_Num : Integer) return Integer;
9 pragma Import(C, Len_Arg, "__gnat_len_arg");
10
11 private
12
13 procedure Fill_Arg (A : System.Address; Arg_Num : Integer);
14 pragma Import(C, Fill_Arg, "__gnat_fill_arg");
15
16 function Len_Arg (Arg_Num : Integer) return Integer;
17 pragma Import(C, Len_Arg, "__gnat_len_arg");
18
19 end CmdLine;
- 3021D0ACD3C417CA8315CB6E2BB10B2F592C1F9C0D01640264B6C52107194622941AE291E955CD18C17BFF0E251CC23166A844A14162C91250B22668EDA11A16
+ 7AA380253BA2297408941A0693B8C37E58AD272B245B418464636647C922C0B75AC70B0B8F22FC1AD6B7CBEA9FBA8368A256862FC301553732CC6A83595B9B29
ffa/ffacalc/ffa_calc.adb
(18 . 8)(18 . 8)
24 ------------------------------------------------------------------------------
25
26 -- Basics
27 with OS; use OS;
28 with CmdLine; use CmdLine;
29 with OS; use OS;
30 with CmdLine; use CmdLine;
31
32 -- FFA
33 with FZ_Lim; use FZ_Lim;
(39 . 14)(39 . 19)
35 -- For Output
36 with FFA_IO; use FFA_IO;
37
38 -- For RNG:
39 with FFA_RNG; use FFA_RNG;
40
41
42 procedure FFA_Calc is
43
44 Width : Positive; -- Desired FFA Width
45 Height : Positive; -- Desired Height of Stack
46 Width : Positive; -- Desired FFA Width
47 Height : Positive; -- Desired Height of Stack
48 RNG : RNG_Device; -- The active RNG device.
49
50 begin
51 if Arg_Count /= 3 then
52 Eggog("Usage: ./ffa_calc WIDTH HEIGHT");
53 if Arg_Count < 3 or Arg_Count > 4 then
54 Eggog("Usage: ./ffa_calc WIDTH HEIGHT [/dev/rng]");
55 end if;
56
57 declare
(57 . 6)(62 . 24)
59 Get_Argument(1, Arg1); -- First arg
60 Get_Argument(2, Arg2); -- Second arg
61
62 if Arg_Count = 4 then
63 -- RNG was specified:
64 declare
65 Arg3 : CmdLineArg;
66 begin
67 Get_Argument(3, Arg3); -- Third arg (optional)
68
69 -- Ada.Sequential_IO chokes on paths with trailing whitespace!
70 -- So we have to give it a trimmed path. But we can't use
71 -- Ada.Strings.Fixed.Trim, because it suffers from
72 -- SecondaryStackism-syphilis. Instead we are stuck doing this:
73 Init_RNG(RNG, Arg3(Arg3'First .. Len_Arg(3)));
74 end;
75 else
76 -- RNG was NOT specified:
77 Init_RNG(RNG); -- Use the machine default then
78 end if;
79
80 -- Parse into Positives:
81 Width := Positive'Value(Arg1);
82 Height := Positive'Value(Arg2);
(422 . 6)(445 . 12)
84 -- Other --
85 -----------
86
87 -- Push a FZ of RNGolade onto the stack
88 when '?' =>
89 Push;
90 FZ_Clear(Stack(SP));
91 FZ_Random(RNG, Stack(SP));
92
93 -- mUx
94 when 'U' =>
95 Want(3);
-
+ EDEF7B1F625864332F9F55DA649B1A795CD9A8112B1052E860ACFE4B4F7E09A72AAE650BB6EDF245D36DAE0DF7AA0DDAAF456C56E91AA59A3642C14F7598C226
ffa/ffacalc/ffa_rng.adb
(0 . 0)(1 . 58)
100 ------------------------------------------------------------------------------
101 ------------------------------------------------------------------------------
102 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
103 -- --
104 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
105 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
106 -- --
107 -- You do not have, nor can you ever acquire the right to use, copy or --
108 -- distribute this software ; Should you use this software for any purpose, --
109 -- or copy and distribute it to anyone or in any manner, you are breaking --
110 -- the laws of whatever soi-disant jurisdiction, and you promise to --
111 -- continue doing so for the indefinite future. In any case, please --
112 -- always : read and understand any software ; verify any PGP signatures --
113 -- that you use - for any purpose. --
114 -- --
115 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
116 ------------------------------------------------------------------------------
117 ------------------------------------------------------------------------------
118
119 with OS; use OS;
120
121 with FZ_Type; use FZ_Type;
122
123
124 package body FFA_RNG is
125
126 -- Prepare an RNG for use; at given path, or will use default
127 procedure Init_RNG(RNG : out RNG_Device;
128 RNG_Unix_Path : in String := Default_RNG_Path) is
129 begin
130 begin
131 -- Open the RNG at the offered path:
132 Word_IO.Open(File => RNG.F,
133 Mode => Word_IO.In_File,
134 Name => RNG_Unix_Path);
135 exception
136 when others =>
137 Eggog("Could not open RNG at : " & RNG_Unix_Path & "!");
138 end;
139 end Init_RNG;
140
141
142 -- Fill a FZ from RNG
143 procedure FZ_Random(RNG : in RNG_Device;
144 N : out FZ) is
145 begin
146 begin
147 -- Fill the destination FZ from this RNG:
148 for i in N'Range loop
149 Word_IO.Read(RNG.F, N(i));
150 end loop;
151 exception
152 when others =>
153 Eggog("Could not read from RNG!");
154 end;
155 end FZ_Random;
156
157 end FFA_RNG;
-
+ 630F1E725D84D93D6462E33BE1D0FE1E85034E456CBC5FB43DB9A3E83D2A7199ADDA24F05EE49DE2A04EF1BA7007E0830D19F552F85115933341B008BEA78D28
ffa/ffacalc/ffa_rng.ads
(0 . 0)(1 . 46)
162 ------------------------------------------------------------------------------
163 ------------------------------------------------------------------------------
164 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
165 -- --
166 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
167 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
168 -- --
169 -- You do not have, nor can you ever acquire the right to use, copy or --
170 -- distribute this software ; Should you use this software for any purpose, --
171 -- or copy and distribute it to anyone or in any manner, you are breaking --
172 -- the laws of whatever soi-disant jurisdiction, and you promise to --
173 -- continue doing so for the indefinite future. In any case, please --
174 -- always : read and understand any software ; verify any PGP signatures --
175 -- that you use - for any purpose. --
176 -- --
177 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
178 ------------------------------------------------------------------------------
179 ------------------------------------------------------------------------------
180
181 with Ada.Sequential_IO;
182
183 with Words; use Words;
184 with FZ_Type; use FZ_Type;
185
186
187 package FFA_RNG is
188
189 Default_RNG_Path : constant String := "/dev/random";
190
191 -- For reading from RNGs:
192 package Word_IO is new Ada.Sequential_IO(Element_Type => Word);
193
194 -- Represents an RNG Device:
195 type RNG_Device is record
196 F : Word_IO.File_Type;
197 end record;
198
199 -- Prepare an RNG for use; at given path, or will use default
200 procedure Init_RNG(RNG : out RNG_Device;
201 RNG_Unix_Path : in String := Default_RNG_Path);
202
203 -- Fill a FZ from RNG
204 procedure FZ_Random(RNG : in RNG_Device;
205 N : out FZ);
206
207 end FFA_RNG;
- C8F9DA805FE81735B86FEA05F9BF7BFEA08B2A6B8374985A3040E35179355D2EA0FFBF2E670023C9375B8DC0C392011CCB1A645505DC462EDA9F3B75B3683DCC
+ F54015524531959B907EF2197E12185A97DD0B7FDD75588E2950ABD3CFA68666F4D5955CBAC44041C27FCB195B17D903CD8F1C7F9DC8897FE6E1B7C423987746
ffa/libffa/fz_modex.adb
(60 . 41)(60 . 44)
212 Modulus : in FZ;
213 Result : out FZ) is
214
215 -- Working register for the squaring
216 -- Working register for the squaring; initially is copy of Base
217 B : FZ(Base'Range) := Base;
218
219 -- Register for cycling through the bits of E
220 -- Copy of Exponent, for cycling through its bits
221 E : FZ(Exponent'Range) := Exponent;
222
223 -- Register for the Mux operation
224 T : FZ(Result'Range);
225
226 -- Buffer register for the Result
227 R : FZ(Result'Range);
228
229 begin
230 -- Result := 1
231 WBool_To_FZ(1, Result);
232 WBool_To_FZ(1, R);
233
234 -- For each bit of Result width:
235 for i in 1 .. FZ_Bitness(Result) loop
236 -- For each bit of R width:
237 for i in 1 .. FZ_Bitness(R) loop
238
239 -- T := Result * B mod Modulus
240 FZ_Mod_Mul(X => Result, Y => B, Modulus => Modulus,
241 Product => T);
242 FZ_Mod_Mul(X => R, Y => B, Modulus => Modulus, Product => T);
243
244 -- Sel is the current low bit of E;
245 -- When Sel=0 -> Result := Result;
246 -- When Sel=1 -> Result := T
247 FZ_Mux(X => Result, Y => T, Result => Result,
248 Sel => FZ_OddP(E));
249 FZ_Mux(X => R, Y => T, Result => R, Sel => FZ_OddP(E));
250
251 -- Advance to the next bit of E
252 FZ_ShiftRight(E, E, 1);
253
254 -- B := B*B mod Modulus
255 FZ_Mod_Mul(X => B, Y => B, Modulus => Modulus,
256 Product => B);
257 FZ_Mod_Mul(X => B, Y => B, Modulus => Modulus, Product => B);
258
259 end loop;
260
261 -- Output the Result:
262 Result := R;
263
264 end FZ_Mod_Exp;
265 pragma Inline_Always(FZ_Mod_Exp);
266