tree checksum vpatch file split hunks
all signers: ave1 diana_coman
antecedents: eucrypt_fix_256 eucrypt_ch12_wrapper_rsa_oaep_c_ada
press order:
patch:
(0 . 0)(1 . 160)
5 ------------------------------------------------------------------------------
6 ------------------------------------------------------------------------------
7 -- This file is part of 'CRC32' --
8 -- --
9 -- You do not have, nor can you ever acquire the right to use, copy or --
10 -- distribute this software ; Should you use this software for any purpose, --
11 -- or copy and distribute it to anyone or in any manner, you are breaking --
12 -- the laws of whatever soi-disant jurisdiction, and you promise to --
13 -- continue doing so for the indefinite future. In any case, please --
14 -- always : read and understand any software ; verify any PGP signatures --
15 -- that you use - for any purpose. --
16 -- --
17 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
18 ------------------------------------------------------------------------------
19 ------------------------------------------------------------------------------
20
21 -- CRC32 implementation
22 -- S.MG, 2018
23
24 -- This implementation is based on bitwise operations (no table).
25 -- CRC32 is defined as a modulo 2 long division, these divisions can be
26 -- implemented as "long" divisions based on xor operations
27 -- (in the same way normal long divisions are based on subtractions).
28
29 -- The bits in a register (with bits R31 .. R0), are xored with the
30 -- bits of the divisor.
31 -- The message is shifted into the register bit by bit at position r0
32 -- The register is shifted to make room for each message bit.
33 -- The bit that is shifted off the register (that was at r31) is used
34 -- to determine if the xor operation is needed (if set then the xor
35 -- operation is performed).
36 -- To be able to operate on each bit of the message, 32 zero bits are
37 -- appended.
38
39 -- The current implementation is an adapted version of the above algoritm
40 -- and the adaptations may not always be obvious, below a short list of
41 -- the adaptations;
42 -- (a) CRC32 has a reversed notion of the bit order in a byte (and integer)
43 -- the bits in each byte of the message are therefor shifted from
44 -- the right (and not left as expected from the algorithm)
45 -- (b) At the end of the algorithm the bit order needs to be reversed.
46 -- This step can be avoided by also shifting the register in a
47 -- different direction and using a reversed divisor.
48 -- (not implemented yet)
49 -- (c) Each message bit is shifted on the right side of the register and
50 -- step by step goes through to the right side of the register. Depending
51 -- on the bits before and the divisor it is xor-ed with a 1 or 0.
52 -- Per bit we have then this function;
53 -- end-bit = message-bit xor d0 xor d1 xor .. xor d31
54 -- (where d0 .. d31 denote the bits of the divisor).
55 -- As an xor with 0 can always be added we can make this:
56 -- end-bit = message-bit xor d0 xor d1 xor .. xor d31 xor 0
57 -- Next, the xor operation is commutative,
58 -- so the function can be rewritten as:
59 -- end_bit = 0 xor d0 xor d1 xor .. xor d31 xor message-bit
60 -- I.E. the message bit can be xor-ed with the register at the end
61 -- and then used to decide the next xor operation on the register.
62 -- (and shift the bit just used off the register)
63 -- Now, no appending of zero's is necessary and the initial value of
64 -- the register becomes a factor.
65 -- (CRC32 uses all ones, 16#ff_ff_ff_ff#)
66 -- (d) The implementation is constant time, no branching on the bits is
67 -- used
68 -- (i.e. no if statements that depend on the value of the bits)
69
70 package body CRC32 is
71 -- Implementation of CRC that uses mod 2 division
72 function CRC ( S : in String ) return CRC32 is
73
74 R : CRC32 := 16#FF_FF_FF_FF#;
75
76 begin
77
78 for I in Integer range S'First .. S'Last loop
79 declare
80 C : CRC32 := Character'Pos (S (I));
81 begin
82 CRC_Step(C, R);
83 end;
84 end loop;
85
86 R := Bits_Reverse(R);
87
88 -- Xor the result as per spec
89 R := R xor 16#FF_FF_FF_FF#;
90 return R;
91
92 end CRC;
93
94 function CRC ( Data: in Octet_Array ) return CRC32 is
95
96 R : CRC32 := 16#FF_FF_FF_FF#;
97
98 begin
99
100 for I in Integer range Data'First .. Data'Last loop
101 declare
102 C : CRC32 := CRC32'Val( Data (I) );
103 begin
104 CRC_Step(C, R);
105 end;
106 end loop;
107
108 R := Bits_Reverse(R);
109
110 -- Xor the result as per spec
111 R := R xor 16#FF_FF_FF_FF#;
112 return R;
113
114 end CRC;
115
116
117 --function CRC( Data: in Octet_Array ) return CRC32;
118 --end CRC;
119
120 procedure CRC_Step(C : in out CRC32; R : in out CRC32) is
121 D : constant CRC32 := 16#04_C1_1D_B7#;
122 begin
123 for J in Integer range 1 .. 8 loop
124 declare
125 Bit31Set : CRC32 := 0;
126 Bit1 : constant CRC32 := Rotate_Right(1 and C, 1);
127 begin
128 R := R xor Bit1;
129 Bit31Set := Rotate_Left(Bit31 and R, 1);
130 R := Shift_Left (R, 1);
131 -- if the bit was set then bit31set == 1, else it is 0
132 -- bit31set - 1 will do 1 -> 0 and 0 -> 16#ff_ff_ff_ff#
133 -- not will then make the
134 -- 0 -> 16#ff_ff_ff_ff#
135 -- and the 16#ff_ff_ff_ff# -> 0.
136 -- ie: (not (Bit31Set - 1)) does:
137 -- 1 --> 16#ff_ff_ff_ff#
138 -- 0 --> 0
139 R := R xor ((not (Bit31Set - 1)) and D);
140
141 -- Shift right as the bit order is reversed in CRC 32
142 C := Shift_Right (C, 1);
143
144 end;
145 end loop;
146 end CRC_Step;
147
148 function Bits_Reverse(A : in CRC32) return CRC32 is
149 R : CRC32 := 16#00_00_00_00#;
150 B : CRC32 := A;
151 begin
152 for I in Integer range 1 .. 32 loop
153 declare
154 Bit : constant CRC32 := (1 and B);
155 begin
156 B := Shift_Right (B, 1);
157 R := Shift_Left (R, 1);
158 R := R or Bit;
159 end;
160 end loop;
161 return R;
162 end Bits_Reverse;
163 end CRC32;
164
-(0 . 0)(1 . 85)
169 ------------------------------------------------------------------------------
170 ------------------------------------------------------------------------------
171 -- This file is part of 'CRC32' --
172 -- --
173 -- You do not have, nor can you ever acquire the right to use, copy or --
174 -- distribute this software ; Should you use this software for any purpose, --
175 -- or copy and distribute it to anyone or in any manner, you are breaking --
176 -- the laws of whatever soi-disant jurisdiction, and you promise to --
177 -- continue doing so for the indefinite future. In any case, please --
178 -- always : read and understand any software ; verify any PGP signatures --
179 -- that you use - for any purpose. --
180 -- --
181 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
182 ------------------------------------------------------------------------------
183 ------------------------------------------------------------------------------
184
185 -- CRC32, modulo 2 based implementation
186 -- S.MG, 2018
187 --
188 -- The CRC32 is a checksum calculated as the remainder of dividing
189 -- the input data by the 0x04C11DB7 polynomial. Specifications:
190 -- Name : "CRC-32"
191 -- Width : 32 (number of bits)
192 -- Poly : 04C11DB7 (generator polynomial)
193 -- Init : FFFFFFFF
194 -- RefIn : True (input is reflected)
195 -- RefOut : True (output is reflected)
196 -- XorOut : FFFFFFFF
197 -- Check : CBF43926 (expected value for input "123456789")
198 --
199 -- This implementation is based on the CRC32 example in:
200 -- Ross N. Williams, A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS
201 -- version 3, 1993
202 -- http://ross.net/crc/download/crc_v3.txt
203
204 with Interfaces; use Interfaces;
205
206 package CRC32 is
207 -- local, shorthand version of Interfaces. types
208 subtype CRC32 is Interfaces.Unsigned_32;
209 subtype Octet is Interfaces.Unsigned_8;
210
211 type Octet_Array is array( Integer range <> ) of Octet;
212
213 -- interface for external callers
214 -- calculate CRC32 for the given string
215 function CRC( S: in String ) return CRC32;
216
217 -- calculate CRC32 for the given array of octets
218 function CRC( Data: in Octet_Array ) return CRC32;
219
220 -- internal constants and helper methods
221 private
222 -- These functions need to be imported to get to the shift operators.
223 -- (Specific for GNAT)
224 function Shift_Left ( Value : CRC32;
225 Amount : Natural )
226 return CRC32;
227 function Shift_Right ( Value : CRC32;
228 Amount : Natural )
229 return CRC32;
230 function Rotate_Left ( Value : CRC32;
231 Amount : Natural )
232 return CRC32;
233 function Rotate_Right ( Value : CRC32;
234 Amount : Natural )
235 return CRC32;
236
237 pragma Import ( Intrinsic, Rotate_Left );
238 pragma Import ( Intrinsic, Rotate_Right );
239 pragma Import ( Intrinsic, Shift_Left );
240 pragma Import ( Intrinsic, Shift_Right );
241
242
243 -- The Shift_Left instruction does not return the bit that was shifted
244 -- We need a mask for this last bit
245 -- Bits are counted from right to left, starting at 0
246 Bit31 : constant CRC32 := 16#80_00_00_00#;
247
248 procedure CRC_Step(C : in out CRC32; R : in out CRC32);
249 pragma Inline_Always(CRC_Step);
250
251 function Bits_Reverse(A : in CRC32) return CRC32;
252
253 end CRC32;
-(0 . 0)(1 . 61)
258 ------------------------------------------------------------------------------
259 ------------------------------------------------------------------------------
260 -- CRC32 checksum lib --
261 -- S.MG, 2018 --
262 -- --
263 -- You do not have, nor can you ever acquire the right to use, copy or --
264 -- distribute this software ; Should you use this software for any purpose, --
265 -- or copy and distribute it to anyone or in any manner, you are breaking --
266 -- the laws of whatever soi-disant jurisdiction, and you promise to --
267 -- continue doing so for the indefinite future. In any case, please --
268 -- always : read and understand any software ; verify any PGP signatures --
269 -- that you use - for any purpose. --
270 -- --
271 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
272 ------------------------------------------------------------------------------
273 ------------------------------------------------------------------------------
274
275 project CRC32 is
276
277 for Object_Dir use "obj";
278
279 type Mode_Type is ("debug", "release");
280 Mode : Mode_Type := external ("mode", "release");
281
282 for Languages use ("Ada");
283 for Source_Dirs use (".");
284 for Library_Dir use "lib";
285 for Library_Name use "CRC32";
286 for Library_Kind use "static";
287
288 package Compiler is
289 case Mode is
290 when "debug" =>
291 for Switches ("Ada")
292 use ("-g");
293 when "release" =>
294 for Switches ("Ada")
295 use ("-O2", "-fdump-scos", "-gnata", "-fstack-check",
296 "-gnatyd", "-gnatym",
297 "-fdata-sections", "-ffunction-sections", "-gnatwr", "-gnatw.d",
298 "-gnatec=" & CRC32'Project_Dir & "restrict.adc");
299 end case;
300 end Compiler;
301
302 package Builder is
303 for Switches ("Ada")
304 use ("-nostdlib");
305 end Builder;
306
307 package Binder is
308 case Mode is
309 when "debug" =>
310 for Switches ("Ada")
311 use ();
312 when "release" =>
313 for Switches ("Ada")
314 use ("-static");
315 end case;
316 end Binder;
317
318 end CRC32;
-(0 . 0)(1 . 1)
323 placeholder
-(0 . 0)(1 . 1)
328 placeholder
-(0 . 0)(1 . 80)
333 ------------------------------------------------------------------------------
334 ------------------------------------------------------------------------------
335 -- This file is part of 'CRC32' --
336 -- --
337 -- You do not have, nor can you ever acquire the right to use, copy or --
338 -- distribute this software ; Should you use this software for any purpose, --
339 -- or copy and distribute it to anyone or in any manner, you are breaking --
340 -- the laws of whatever soi-disant jurisdiction, and you promise to --
341 -- continue doing so for the indefinite future. In any case, please --
342 -- always : read and understand any software ; verify any PGP signatures --
343 -- that you use - for any purpose. --
344 -- --
345 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
346 ------------------------------------------------------------------------------
347 ------------------------------------------------------------------------------
348
349 pragma Restrictions(Immediate_Reclamation);
350 pragma Restrictions(Max_Asynchronous_Select_Nesting => 0);
351 pragma Restrictions(Max_Protected_Entries => 0);
352 pragma Restrictions(Max_Select_Alternatives => 0);
353 pragma Restrictions(Max_Task_Entries => 0);
354 pragma Restrictions(Max_Tasks => 0);
355 pragma Restrictions(No_Abort_Statements);
356 pragma Restrictions(No_Access_Parameter_Allocators);
357 pragma Restrictions(No_Allocators);
358 pragma Restrictions(No_Asynchronous_Control);
359 pragma Restrictions(No_Calendar);
360 pragma Restrictions(No_Coextensions);
361 pragma Restrictions(No_Default_Stream_Attributes);
362 pragma Restrictions(No_Delay);
363 pragma Restrictions(No_Dispatch);
364 pragma Restrictions(No_Dispatching_Calls);
365 pragma Restrictions(No_Dynamic_Attachment);
366 pragma Restrictions(No_Dynamic_Priorities);
367 pragma Restrictions(No_Entry_Calls_In_Elaboration_Code);
368 pragma Restrictions(No_Entry_Queue);
369 pragma Restrictions(No_Enumeration_Maps);
370 pragma Restrictions(No_Exception_Propagation);
371 pragma Restrictions(No_Exception_Registration);
372 pragma Restrictions(No_Finalization);
373 pragma Restrictions(No_Fixed_Io);
374 pragma Restrictions(No_Floating_Point);
375 pragma Restrictions(No_Implementation_Aspect_Specifications);
376 pragma Restrictions(No_Implementation_Units);
377 pragma Restrictions(No_Implicit_Conditionals);
378 pragma Restrictions(No_Implicit_Dynamic_Code);
379 pragma Restrictions(No_Implicit_Heap_Allocations);
380 pragma Restrictions(No_Implicit_Protected_Object_Allocations);
381 pragma Restrictions(No_Implicit_Task_Allocations);
382 pragma Restrictions(No_Initialize_Scalars);
383 pragma Restrictions(No_Local_Protected_Objects);
384 pragma Restrictions(No_Local_Timing_Events);
385 pragma Restrictions(No_Multiple_Elaboration);
386 pragma Restrictions(No_Nested_Finalization);
387 pragma Restrictions(No_Protected_Type_Allocators);
388 pragma Restrictions(No_Protected_Types);
389 pragma Restrictions(No_Relative_Delay);
390 pragma Restrictions(No_Requeue_Statements);
391 pragma Restrictions(No_Secondary_Stack);
392 pragma Restrictions(No_Select_Statements);
393 pragma Restrictions(No_Specific_Termination_Handlers);
394 pragma Restrictions(No_Standard_Allocators_After_Elaboration);
395 pragma Restrictions(No_Stream_Optimizations);
396 pragma Restrictions(No_Streams);
397 pragma Restrictions(No_Task_Allocators);
398 pragma Restrictions(No_Task_At_Interrupt_Priority);
399 pragma Restrictions(No_Task_Attributes_Package);
400 pragma Restrictions(No_Task_Hierarchy);
401 pragma Restrictions(No_Tasking);
402 pragma Restrictions(No_Task_Termination);
403 pragma Restrictions(No_Terminate_Alternatives);
404 pragma Restrictions(No_Unchecked_Access);
405 pragma Restrictions(No_Unchecked_Conversion);
406 pragma Restrictions(No_Unchecked_Deallocation);
407 pragma Restrictions(No_Wide_Characters);
408 pragma Restrictions(Pure_Barriers);
409 pragma Restrictions(Simple_Barriers);
410 pragma Restrictions(Static_Priorities);
411 pragma Restrictions(Static_Storage_Size);
412 pragma Validity_Checks(ALL_CHECKS);
-(0 . 0)(1 . 1)
417 obj
-(0 . 0)(1 . 39)
422 ------------------------------------------------------------------------------
423 ------------------------------------------------------------------------------
424 -- This file is part of 'CRC32' --
425 -- --
426 -- You do not have, nor can you ever acquire the right to use, copy or --
427 -- distribute this software ; Should you use this software for any purpose, --
428 -- or copy and distribute it to anyone or in any manner, you are breaking --
429 -- the laws of whatever soi-disant jurisdiction, and you promise to --
430 -- continue doing so for the indefinite future. In any case, please --
431 -- always : read and understand any software ; verify any PGP signatures --
432 -- that you use - for any purpose. --
433 -- --
434 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
435 ------------------------------------------------------------------------------
436 ------------------------------------------------------------------------------
437
438 -- Basic test for the CRC32 implementation
439 -- S.MG, 2018
440
441 with Ada.Text_IO; use Ada.Text_IO;
442 with Interfaces; use Interfaces;
443 with CRC32;
444
445 procedure Test_CRC32 is
446 Input : constant String := "123456789";
447 Expected : constant Unsigned_32 := 16#CBF4_3926#;
448 Output : Unsigned_32;
449 begin
450 Output := CRC32.CRC(Input);
451 if Output /= Expected then
452 Put_Line("FAIL: CRC32(" & Input & ") returned " &
453 Unsigned_32'Image(Output) & " instead of " &
454 Unsigned_32'Image(Expected));
455 else
456 Put_Line("PASS: CRC32(" & Input & ") returned " &
457 Unsigned_32'Image(Output) & " as expected.");
458 end if;
459
460 end Test_CRC32;
-(0 . 0)(1 . 67)
465 ------------------------------------------------------------------------------
466 ------------------------------------------------------------------------------
467 -- This file is part of 'CRC32' --
468 -- --
469 -- You do not have, nor can you ever acquire the right to use, copy or --
470 -- distribute this software ; Should you use this software for any purpose, --
471 -- or copy and distribute it to anyone or in any manner, you are breaking --
472 -- the laws of whatever soi-disant jurisdiction, and you promise to --
473 -- continue doing so for the indefinite future. In any case, please --
474 -- always : read and understand any software ; verify any PGP signatures --
475 -- that you use - for any purpose. --
476 -- --
477 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
478 ------------------------------------------------------------------------------
479 ------------------------------------------------------------------------------
480
481 -- Edge testing for the CRC32 implementation
482 -- S.MG, 2018
483
484 with Ada.Text_IO; use Ada.Text_IO;
485 with Interfaces; use Interfaces;
486 with CRC32;
487
488
489 procedure Test_CRC32_Edge is
490 Empty : constant Character := Character'Val(0);
491 Full : constant Character := Character'Val(16#FF#);
492
493 S0 : String := Empty & Empty & Empty & Empty;
494 S255 : String := Full & Full & Full & Full;
495
496 S0F : String := Character'Val(16#0F#) & Character'Val(16#0F#);
497 SF0 : String := Character'Val(16#F0#) & Character'Val(16#F0#);
498
499 C : CRC32.CRC32 := 0;
500 begin
501 -- First some tests, independent of the bit order
502 C := CRC32.CRC(S0);
503 pragma Assert(C = 558161692,
504 "Test_CRC32_Edge - assert 1 - C is " & CRC32.CRC32'Image(C)
505 & " should be 558161692");
506 C := CRC32.CRC(S255);
507 pragma Assert(C = 16#FFFFFFFF#,
508 "Test_CRC32_Edge - assert 2 - C is " & CRC32.CRC32'Image(C)
509 & " should be 4294967295");
510 C := CRC32.CRC(S0(1 .. 1));
511 pragma Assert(C = 3523407757,
512 "Test_CRC32_Edge - assert 3 - C is " & CRC32.CRC32'Image(C)
513 & " should be 3523407757");
514 C := CRC32.CRC(S0(1 .. 2));
515 pragma Assert(C = 1104745215,
516 "Test_CRC32_Edge - assert 4 - C is " & CRC32.CRC32'Image(C)
517 & " should be 1104745215");
518
519 -- The bitorder in CRC32 is reversed, check if implemented correctly
520 C := CRC32.CRC(S0F);
521 pragma Assert(C = 1459491745,
522 "Test_CRC32_Edge - assert 5 - C is " & CRC32.CRC32'Image(C)
523 & " should be 1459491745");
524
525 C := CRC32.CRC(SF0);
526 pragma Assert(C = 3906470238,
527 "Test_CRC32_Edge - assert 6 - C is " & CRC32.CRC32'Image(C)
528 & " should be 3906470238");
529
530
531 end Test_CRC32_Edge;
-(0 . 0)(1 . 24)
536 -- Tests project for CRC32 lib
537 -- S.MG, 2018
538
539 with "../crc32.gpr";
540
541 project Tests is
542
543 for Object_Dir use "obj";
544
545 for Languages use ("Ada");
546 for Source_Dirs use (".");
547 for Exec_Dir use ".";
548
549 for Main use ("test_crc32.adb", "test_crc32_edge.adb");
550
551 package Compiler is
552 for Switches ("Ada")
553 use ("-O2", "-fdump-scos", "-gnata", "-fstack-check",
554 "-gnatyd", "-gnatym",
555 "-fdata-sections", "-ffunction-sections", "-gnatwr", "-gnatw.d",
556 "-gnatec=" & CRC32'Project_Dir & "restrict.adc");
557 end Compiler;
558
559 end Tests;
- 94D4FB2C29F384693F39A994B26A95276EA949C1BFCCA5D438581DD8EE609E400606B3FA59A413A5E330BD7781CA82F668D8C4DB2EAC6EECD67BC4529067D786(6 . 7)(6 . 8)
564 "smg_bit_keccak/smg_bit_keccak.gpr",
565 "smg_keccak/smg_keccak.gpr",
566 "smg_rsa/smg_rsa.gpr",
567 "smg_serpent/smg_serpent.gpr");
568 "smg_serpent/smg_serpent.gpr",
569 "crc32/crc32.gpr");
570
571 for Library_Name use "EuCrypt";
572 for Library_Kind use "static";
- 36DD3853F41604790D69B6DB28D86933A068B0F5D64CF2224E7FD3371497E21A92B0DBB84E4367B112C55F57F35A6EC076A8E04729EA7FD8F87BBD79D846C95D(18 . 4)(18 . 4)
577 521090 eucrypt_ch13_smg_rng diana_coman Adds methods for obtaining random values directly from bits obtained from the entropy source. Following specific types are supported: unsigned int on 32 bits, unsigned int on 64 bits, dirty float between 0 and 1, float IEEE 754/1985 between 1 and 2.
578 527560 eucrypt_manifest diana_coman Adds this manifest file that should be modified each time a new patch is added to EuCrypt.
579 543780 eucrypt_fix_256 diana_coman Fix the error in smg_oaep.adb that used 255 instead of 256 when calculating/retrieving length stored on 2 octets.
580
581 545451 eucrypt_crc32_div ave1 An alternative simple implementation of the CRC32 checsum using modulo 2 division (XOR).