1with AUnit.Assertions;
2with Crypto.Types;
3use Crypto.Types;
4with Ada.Text_IO;
5
6package body Test.Types is
7
8   -----------------------------------------------------------------------------
9   -------------------------------- Type - Declaration -------------------------
10   -----------------------------------------------------------------------------
11
12   -----------------------------------------------------------------------------
13   ------------------------ Register Random Tests -------------------------
14   -----------------------------------------------------------------------------
15
16   procedure Register_Tests(T : in out Types_Test) is
17      use Test_Cases.Registration;
18   begin
19      Register_Routine(T, Types_Test1'Access,"R to DWord");
20      Register_Routine(T, Types_Test2'Access,"R to Bytes");
21      Register_Routine(T, Types_Test3'Access,"Bytes xor Byte");
22      Register_Routine(T, Types_Test4'Access,"B_Block64 to Bytes");
23      Register_Routine(T, Types_Test5'Access,"B_Block128 to Bytes");
24      Register_Routine(T, Types_Test6'Access,"B_Block192 to Bytes");
25      Register_Routine(T, Types_Test7'Access,"B_Block256 to Bytes");
26      Register_Routine(T, Types_Test8'Access,"W_Blocks to Bytes");
27      Register_Routine(T, Types_Test9'Access,"Is_Zero");
28      Register_Routine(T, Types_Test10'Access,"+ Operator: Words and Word");
29      Register_Routine(T, Types_Test11'Access,"+ Operator: Bytes and Byte");
30      Register_Routine(T, Types_Test12'Access,"+ Operator: Words and Byte");
31      Register_Routine(T, Types_Test13'Access,"+ Operator: DWords and DWord");
32      Register_Routine(T, Types_Test14'Access,"+ Operator: DWords and Byte");
33      Register_Routine(T, Types_Test15'Access,"Characters to Word");
34      Register_Routine(T, Types_Test16'Access,"DWord to Byte_DWord");
35      Register_Routine(T, Types_Test17'Access,"Words xor Words");
36      Register_Routine(T, Types_Test21'Access,"DWords to Bytes");
37      Register_Routine(T, Types_Test22'Access,"Word to Hex (String)");
38      Register_Routine(T, Types_Test23'Access,"DWord to Hex (String)");
39      Register_Routine(T, Types_Test24'Access,"Left Part");
40      Register_Routine(T, Types_Test25'Access,"Right Part");
41      Register_Routine(T, Types_Test26'Access,"DW_Block512 to Bytes");
42      Register_Routine(T, Types_Test27'Access,"Bytes to B_Block64");
43      Register_Routine(T, Types_Test28'Access,"Bytes to B_Block128");
44      Register_Routine(T, Types_Test29'Access,"Bytes to B_Block192");
45      Register_Routine(T, Types_Test30'Access,"Bytes to B_Block256");
46      Register_Routine(T, Types_Test31'Access,"Words xor Words Constraint_Error Test");
47      Register_Routine(T, Types_Test32'Access,"Bytes xor Bytes Constraint_Error Test");
48      Register_Routine(T, Types_Test33'Access,"DWords xor DWords Constraint_Error Test");
49      Register_Routine(T, Types_Test34'Access,"Byte to Hex");
50   end Register_Tests;
51
52   -----------------------------------------------------------------------------
53   --------------------------- Name Random Tests ---------------------------
54   -----------------------------------------------------------------------------
55
56   function Name(T : Types_Test) return Test_String is
57   begin
58      return new String'("Types Tests");
59   end Name;
60
61   -----------------------------------------------------------------------------
62   ----------------------------------- Test 1 ----------------------------------
63   -----------------------------------------------------------------------------
64
65   procedure Types_Test1(T : in out Test_Cases.Test_Case'Class) is
66      use AUnit.Assertions;
67      I : constant Crypto.Types.Byte_DWord := (2, 1, 1, 1, 1, 1, 1, 1);
68      O : Crypto.Types.DWord;
69   begin
70      O := Crypto.Types.R_To_DWord(I);
71
72      Assert(O = 2#0000000100000001000000010000000100000001000000010000000100000010#, "R to DWord failed");
73   end Types_Test1;
74
75   -----------------------------------------------------------------------------
76   ----------------------------------- Test 2 ----------------------------------
77   -----------------------------------------------------------------------------
78
79   procedure Types_Test2(T : in out Test_Cases.Test_Case'Class) is
80      use AUnit.Assertions;
81      I : constant Crypto.Types.DWord := 2#0000000100000001000000010000000100000001000000010000000100000010#;
82      O : Crypto.Types.Byte_DWord;
83   begin
84      O := Crypto.Types.R_To_Bytes(I);
85
86      Assert(O = (2, 1, 1, 1, 1, 1, 1, 1), "R to Bytes failed");
87   end Types_Test2;
88
89   -----------------------------------------------------------------------------
90   ----------------------------------- Test 3 ----------------------------------
91   -----------------------------------------------------------------------------
92
93   procedure Types_Test3(T : in out Test_Cases.Test_Case'Class) is
94      use AUnit.Assertions;
95      I1 : constant Crypto.Types.Byte := 2#00000101#;
96      I2 : constant Crypto.Types.Bytes(0..1) := (2#00000001#,2#00000010#);
97      O  : Crypto.Types.Bytes(0..1);
98      Confirmed_O : constant Crypto.Types.Bytes(0..1) := (2#00000001#,2#00000111#);
99   begin
100      O := I2 xor I1;
101
102      Assert(O = Confirmed_O, "Bytes xor Byte failed");
103   end Types_Test3;
104
105   -----------------------------------------------------------------------------
106   ----------------------------------- Test 4 ----------------------------------
107   -----------------------------------------------------------------------------
108
109   procedure Types_Test4(T : in out Test_Cases.Test_Case'Class) is
110      use AUnit.Assertions;
111      I : Crypto.Types.B_Block64;
112      O : Crypto.Types.Bytes(0..7);
113      Equal : Boolean := true;
114   begin
115      I := (1, 2, 3, 4, 5, 6, 7, 8);
116      O := Crypto.Types.To_Bytes(I);
117      for j in I'Range loop
118         if I(j) /= O(j) then
119            Equal := false;
120         end if;
121      end loop;
122
123      Assert(Equal, "B_Block64 to Bytes failed");
124   end Types_Test4;
125
126   -----------------------------------------------------------------------------
127   ----------------------------------- Test 5 ----------------------------------
128   -----------------------------------------------------------------------------
129
130   procedure Types_Test5(T : in out Test_Cases.Test_Case'Class) is
131      use AUnit.Assertions;
132      I : Crypto.Types.B_Block128;
133      O : Crypto.Types.Bytes(0..15);
134      Equal : Boolean := true;
135   begin
136      I := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
137      O := Crypto.Types.To_Bytes(I);
138      for j in I'Range loop
139         if I(j) /= O(j) then
140            Equal := false;
141         end if;
142      end loop;
143
144      Assert(Equal, "B_Block128 to Bytes failed");
145   end Types_Test5;
146
147   -----------------------------------------------------------------------------
148   ----------------------------------- Test 6 ----------------------------------
149   -----------------------------------------------------------------------------
150
151   procedure Types_Test6(T : in out Test_Cases.Test_Case'Class) is
152      use AUnit.Assertions;
153      I : Crypto.Types.B_Block192;
154      O : Crypto.Types.Bytes(0..23);
155      Equal : Boolean := true;
156   begin
157      I := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24);
158      O := Crypto.Types.To_Bytes(I);
159      for j in I'Range loop
160         if I(j) /= O(j) then
161            Equal := false;
162         end if;
163      end loop;
164
165      Assert(Equal, "B_Block192 to Bytes failed");
166   end Types_Test6;
167
168   -----------------------------------------------------------------------------
169   ----------------------------------- Test 7 ----------------------------------
170   -----------------------------------------------------------------------------
171
172   procedure Types_Test7(T : in out Test_Cases.Test_Case'Class) is
173      use AUnit.Assertions;
174      I : Crypto.Types.B_Block256;
175      O : Crypto.Types.Bytes(0..31);
176      Equal : Boolean := true;
177   begin
178      I := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32);
179      O := Crypto.Types.To_Bytes(I);
180      for j in I'Range loop
181         if I(j) /= O(j) then
182            Equal := false;
183         end if;
184      end loop;
185
186      Assert(Equal, "B_Block256 to Bytes failed");
187   end Types_Test7;
188
189   -----------------------------------------------------------------------------
190   ----------------------------------- Test 8 ----------------------------------
191   -----------------------------------------------------------------------------
192
193   procedure Types_Test8(T : in out Test_Cases.Test_Case'Class) is
194      use AUnit.Assertions;
195      I : Crypto.Types.Words(0..1);
196      O : Crypto.Types.Bytes(0..7);
197      I_W256 : constant Crypto.Types.W_Block256 := (others => 0);
198      O_W256 : Crypto.Types.Bytes(0..31);
199      O2_W256 : Crypto.Types.Bytes(0..31);
200      I_W512 : constant Crypto.Types.W_Block512 := (others => 0);
201      O_W512 : Crypto.Types.Bytes(0..63);
202      O2_W512 : Crypto.Types.Bytes(0..63);
203   begin
204      --show that To_Bytes(Words) works, if so, also the other procedures should work
205      I(0) := 16#01020304#;
206      I(1) := 16#05060708#;
207      O := Crypto.Types.To_Bytes(I);
208
209      O_W256 := Crypto.Types.To_Bytes(I_W256);
210      O2_W256 := Crypto.Types.To_Bytes(Words(I_W256));
211
212      O_W512 := Crypto.Types.To_Bytes(I_W512);
213      O2_W512 := Crypto.Types.To_Bytes(Words(I_W512));
214
215      Assert(O(0) = 16#01# and O(1) = 16#02# and O(2) = 16#03# and O(3) = 16#04#
216                    and O(4) = 16#05# and O(5) = 16#06# and O(6) = 16#07#
217                    and O(7) = 16#08# and O_W256 = O2_W256 and O_W512 = O2_W512,
218                    "W_Blocks to Bytes failed");
219   end Types_Test8;
220
221   -----------------------------------------------------------------------------
222   ----------------------------------- Test 9 ----------------------------------
223   -----------------------------------------------------------------------------
224
225   procedure Types_Test9(T : in out Test_Cases.Test_Case'Class) is
226      use AUnit.Assertions;
227      I1 : constant Crypto.Types.Bytes(0..9) := (0,0,0,0,0,0,0,0,0,0);
228      I2 : constant Crypto.Types.Bytes(0..9) := (0,0,0,0,1,0,0,0,0,0);
229      O1 : Boolean;
230      O2 : Boolean;
231   begin
232      O1 := Crypto.Types.Is_Zero(I1);
233      O2 := Crypto.Types.Is_Zero(I2);
234
235      Assert(O1 and (O2 = False), "Is_Zero Test failed");
236   end Types_Test9;
237
238   -----------------------------------------------------------------------------
239   ----------------------------------- Test 10 ----------------------------------
240   -----------------------------------------------------------------------------
241
242   procedure Types_Test10(T : in out Test_Cases.Test_Case'Class) is
243      use AUnit.Assertions;
244      I1 : constant Crypto.Types.Words(0..1) := (16#00000000#,16#FFFFFFFF#);
245      I2 : constant Crypto.Types.Word := 16#00000001#;
246      I3 : constant Crypto.Types.Words(0..2) := (16#FFFFFFFF#,16#FFFFFFFF#, 16#FFFFFFFF#);
247      O1 : Crypto.Types.Words(0..1);
248      O2 : Crypto.Types.Words(0..1);
249      O3 : Crypto.Types.Words(0..2);
250   begin
251      O1 := I1 + I2;
252      O2 := I2 + I1;
253      O3 := I3 + I2;
254
255      Assert(O1(0) = 16#00000001# and O1(1) = 16#00000000# and O2 = O1 and O3(0) = 16#00000000#
256      		     and O3(1) = 16#00000000# and O3(2) = 16#00000000#, "+ Operator: Words and Word Test failed");
257   end Types_Test10;
258
259
260   -----------------------------------------------------------------------------
261   ----------------------------------- Test 11 ----------------------------------
262   -----------------------------------------------------------------------------
263
264   procedure Types_Test11(T : in out Test_Cases.Test_Case'Class) is
265      use AUnit.Assertions;
266      I1 : constant Crypto.Types.Bytes(0..1) := (16#00#,16#FF#);
267      I2 : constant Crypto.Types.Byte := 16#01#;
268      I3 : constant Crypto.Types.Bytes(0..2) := (16#FF#,16#FF#,16#FF#);
269      O1 : Crypto.Types.Bytes(0..1);
270      O2 : Crypto.Types.Bytes(0..1);
271      O3 : Crypto.Types.Bytes(0..2);
272   begin
273      O1 := I1 + I2;
274      O2 := I2 + I1;
275      O3 := I3 + I2;
276
277      Assert(O1(0) = 16#01# and O1(1) = 16#00# and O2 = O1 and O3(0) = 16#00# and O3(1) = 16#00#
278           	     and O3(2) = 16#00#, "+ Operator: Bytes and Byte Test failed");
279   end Types_Test11;
280
281   -----------------------------------------------------------------------------
282   ----------------------------------- Test 12 ----------------------------------
283   -----------------------------------------------------------------------------
284
285   procedure Types_Test12(T : in out Test_Cases.Test_Case'Class) is
286      use AUnit.Assertions;
287      I1 : constant Crypto.Types.Words(0..1) := (16#00000000#,16#FFFFFFFF#);
288      I2 : constant Crypto.Types.Byte := 16#01#;
289      I3 : constant Crypto.Types.Words(0..2) := (16#FFFFFFFF#,16#FFFFFFFF#,16#FFFFFFFF#);
290      O1 : Crypto.Types.Words(0..1);
291      O2 : Crypto.Types.Words(0..2);
292   begin
293      O1 := I1 + I2;
294      O2 := I3 + I2;
295
296      Assert(O1(0) = 16#00000001# and O1(1) = 16#00000000# and O2(0) = 16#00000000#
297             	     and O2(1) = 16#00000000# and O2(2) = 16#00000000#, "+ Operator: Words and Byte Test failed");
298   end Types_Test12;
299
300   -----------------------------------------------------------------------------
301   ----------------------------------- Test 13 ----------------------------------
302   -----------------------------------------------------------------------------
303
304   procedure Types_Test13(T : in out Test_Cases.Test_Case'Class) is
305      use AUnit.Assertions;
306      I1 : constant Crypto.Types.DWords(0..1) := (16#0000000000000000#,16#FFFFFFFFFFFFFFFF#);
307      I2 : constant Crypto.Types.DWord := 16#0000000000000001#;
308      I3 : constant Crypto.Types.DWords(0..2) := (16#FFFFFFFFFFFFFFFF#,16#FFFFFFFFFFFFFFFF#,16#FFFFFFFFFFFFFFFF#);
309      O1 : Crypto.Types.DWords(0..1);
310      O2 : Crypto.Types.DWords(0..1);
311      O3 : Crypto.Types.DWords(0..2);
312   begin
313      O1 := I1 + I2;
314      O2 := I2 + I1;
315      O3 := I3 + I2;
316
317      Assert(O1(0) = 16#0000000000000001# and O1(1) = 16#0000000000000000# and O2 = O1 and
318             	     O3(0) = 16#0000000000000000# and O3(1) = 16#0000000000000000# and O3(2) = 16#0000000000000000#, "+ Operator: DWords and DWord Test failed");
319   end Types_Test13;
320
321   -----------------------------------------------------------------------------
322   ----------------------------------- Test 14 ----------------------------------
323   -----------------------------------------------------------------------------
324
325   procedure Types_Test14(T : in out Test_Cases.Test_Case'Class) is
326      use AUnit.Assertions;
327      I1 : constant Crypto.Types.DWords(0..1) := (16#0000000000000000#,16#FFFFFFFFFFFFFFFF#);
328      I2 : constant Crypto.Types.Byte := 16#01#;
329      I3 : constant Crypto.Types.DWords(0..2) := (16#FFFFFFFFFFFFFFFF#,16#FFFFFFFFFFFFFFFF#,16#FFFFFFFFFFFFFFFF#);
330      O1 : Crypto.Types.DWords(0..1);
331      O2 : Crypto.Types.DWords(0..2);
332   begin
333      O1 := I1 + I2;
334      O2 := I3 + I2;
335
336      Assert(O1(0) = 16#0000000000000001# and O1(1) = 16#0000000000000000# and
337             	     O2(0) = 16#0000000000000000# and O2(1) = 16#0000000000000000# and O2(2) = 16#0000000000000000#, "+ Operator: DWords and Byte Test failed");
338   end Types_Test14;
339
340   -----------------------------------------------------------------------------
341   ----------------------------------- Test 15 ----------------------------------
342   -----------------------------------------------------------------------------
343
344   procedure Types_Test15(T : in out Test_Cases.Test_Case'Class) is
345      use AUnit.Assertions;
346      O : Crypto.Types.Word;
347   begin
348      O := Crypto.Types.To_Word('A','B','C','D');
349
350      Assert(O = 16#41424344#, "Characters to Word failed");
351   end Types_Test15;
352
353   -----------------------------------------------------------------------------
354   ----------------------------------- Test 16 ----------------------------------
355   -----------------------------------------------------------------------------
356
357   procedure Types_Test16(T : in out Test_Cases.Test_Case'Class) is
358      use AUnit.Assertions;
359      I : constant Crypto.Types.DWord := 16#0102030405060708#;
360      O : Crypto.Types.Byte_DWord;
361   begin
362      O := Crypto.Types.To_Bytes(I);
363
364      Assert(O(0) = 16#01# and O(1) = 16#02# and O(2) = 16#03# and O(3) = 16#04# and O(4) = 16#05# and O(5) = 16#06# and O(6) = 16#07# and O(7) = 16#08#, "DWord to Byte_DWord failed");
365   end Types_Test16;
366
367   -----------------------------------------------------------------------------
368   ----------------------------------- Test 17 ----------------------------------
369   -----------------------------------------------------------------------------
370
371   procedure Types_Test17(T : in out Test_Cases.Test_Case'Class) is
372      use AUnit.Assertions;
373      I1 : constant Crypto.Types.Words(0..1) := (2#00000000_00000000_00000000_00000101#,2#00000000_00000000_00000000_00000101#);
374      I2 : constant Crypto.Types.Words(0..1) := (2#00000000_00000000_00000000_00000001#,2#00000000_00000000_00000000_00000010#);
375      O  : Crypto.Types.Words(0..1);
376   begin
377      O := I2 xor I1;
378
379      Assert(O(0) = 2#00000000_00000000_00000000_00000100# and O(1) = 2#00000000_00000000_00000000_00000111#, "Words xor Words failed");
380   end Types_Test17;
381
382   -----------------------------------------------------------------------------
383   ----------------------------------- Test 21 ----------------------------------
384   -----------------------------------------------------------------------------
385
386   procedure Types_Test21(T : in out Test_Cases.Test_Case'Class) is
387      use AUnit.Assertions;
388      I1 : constant Crypto.Types.DWords(0..0) := (0 => 16#10_20_30_40_50_60_70_80#);
389      O1 : Crypto.Types.Bytes(0..7);
390   begin
391      O1 := Crypto.Types.To_Bytes(I1);
392
393      Assert(O1 = (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#), "DWords to Bytes failed");
394   end Types_Test21;
395
396   -----------------------------------------------------------------------------
397   ----------------------------------- Test 22 ----------------------------------
398   -----------------------------------------------------------------------------
399
400   procedure Types_Test22(T : in out Test_Cases.Test_Case'Class) is
401      use AUnit.Assertions;
402      I1 : constant Crypto.Types.Word := 16#10_20_30_40#;
403      O1 : Crypto.Types.Hex_Word;
404   begin
405      O1 := Crypto.Types.To_Hex(I1);
406
407      Assert(O1 = "10203040", "Word to Hex (String) failed");
408   end Types_Test22;
409
410   -----------------------------------------------------------------------------
411   ----------------------------------- Test 23 ----------------------------------
412   -----------------------------------------------------------------------------
413
414   procedure Types_Test23(T : in out Test_Cases.Test_Case'Class) is
415      use AUnit.Assertions;
416      I1 : constant Crypto.Types.DWord := 16#10_20_30_40_50_60_70_80#;
417      O1 : Crypto.Types.Hex_DWord;
418   begin
419      O1 := Crypto.Types.To_Hex(I1);
420
421      Assert(O1 = "1020304050607080", "DWord to Hex (String) failed");
422   end Types_Test23;
423
424   -----------------------------------------------------------------------------
425   ----------------------------------- Test 24 ----------------------------------
426   -----------------------------------------------------------------------------
427
428   procedure Types_Test24(T : in out Test_Cases.Test_Case'Class) is
429      use AUnit.Assertions;
430      I1 : constant Crypto.Types.Bytes(0..3) := (16#10#,16#20#,16#30#,16#40#);
431      O1 : Crypto.Types.Bytes(0..1);
432   begin
433      O1 := Crypto.Types.Left_Part(I1);
434
435      Assert(O1 = (16#10#,16#20#), "Left Part failed");
436   end Types_Test24;
437
438   -----------------------------------------------------------------------------
439   ----------------------------------- Test 25 ----------------------------------
440   -----------------------------------------------------------------------------
441
442   procedure Types_Test25(T : in out Test_Cases.Test_Case'Class) is
443      use AUnit.Assertions;
444      I1 : constant Crypto.Types.Bytes(0..3) := (16#10#,16#20#,16#30#,16#40#);
445      O1 : Crypto.Types.Bytes(0..1);
446   begin
447      O1 := Crypto.Types.Right_Part(I1);
448
449      Assert(O1 = (16#30#,16#40#), "Left Part failed");
450   end Types_Test25;
451
452   -----------------------------------------------------------------------------
453   ----------------------------------- Test 26 ----------------------------------
454   -----------------------------------------------------------------------------
455
456   procedure Types_Test26(T : in out Test_Cases.Test_Case'Class) is
457      use AUnit.Assertions;
458      I1 : constant Crypto.Types.DW_Block512 := (16#10_20_30_40_50_60_70_80#, 16#11_21_31_41_51_61_71_81#,
459                                        16#12_22_32_42_52_62_72_82#, 16#13_23_33_43_53_63_73_83#,
460                                        16#14_24_34_44_54_64_74_84#, 16#15_25_35_45_55_65_75_85#,
461                                       	16#16_26_36_46_56_66_76_86#, 16#17_27_37_47_57_67_77_87#);
462      O1 : Crypto.Types.Bytes(0..63);
463   begin
464      O1 := Crypto.Types.To_Bytes(I1);
465
466      Assert(O1 = (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,
467        	   16#11#,16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#,
468        	   16#12#,16#22#,16#32#,16#42#,16#52#,16#62#,16#72#,16#82#,
469        	   16#13#,16#23#,16#33#,16#43#,16#53#,16#63#,16#73#,16#83#,
470        	   16#14#,16#24#,16#34#,16#44#,16#54#,16#64#,16#74#,16#84#,
471        	   16#15#,16#25#,16#35#,16#45#,16#55#,16#65#,16#75#,16#85#,
472        	   16#16#,16#26#,16#36#,16#46#,16#56#,16#66#,16#76#,16#86#,
473       		   16#17#,16#27#,16#37#,16#47#,16#57#,16#67#,16#77#,16#87#), "DW_Block512 to Bytes failed");
474   end Types_Test26;
475
476   -----------------------------------------------------------------------------
477   ----------------------------------- Test 27 ----------------------------------
478   -----------------------------------------------------------------------------
479
480   procedure Types_Test27(T : in out Test_Cases.Test_Case'Class) is
481      use AUnit.Assertions;
482      I1 : constant Crypto.Types.Bytes(0..7) := (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#);
483      O1 : Crypto.Types.B_Block64;
484   begin
485      O1 := Crypto.Types.To_B_Block64(I1);
486
487      Assert(O1 = (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#), "Bytes to B_Block64 failed");
488   end Types_Test27;
489
490   -----------------------------------------------------------------------------
491   ----------------------------------- Test 28 ----------------------------------
492   -----------------------------------------------------------------------------
493
494   procedure Types_Test28(T : in out Test_Cases.Test_Case'Class) is
495      use AUnit.Assertions;
496      I1 : constant Crypto.Types.Bytes(0..15) := (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,
497                                       	16#11#,16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#);
498      O1 : Crypto.Types.B_Block128;
499   begin
500      O1 := Crypto.Types.To_B_Block128(I1);
501
502      Assert(O1 = (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,16#11#,
503      		   16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#), "Bytes to B_Block128 failed");
504   end Types_Test28;
505
506   -----------------------------------------------------------------------------
507   ----------------------------------- Test 29 ----------------------------------
508   -----------------------------------------------------------------------------
509
510   procedure Types_Test29(T : in out Test_Cases.Test_Case'Class) is
511      use AUnit.Assertions;
512      I1 : constant Crypto.Types.Bytes(0..23) := (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,
513                                        16#11#,16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#,
514                                       	16#12#,16#22#,16#32#,16#42#,16#52#,16#62#,16#72#,16#82#);
515      O1 : Crypto.Types.B_Block192;
516   begin
517      O1 := Crypto.Types.To_B_Block192(I1);
518
519      Assert(O1 = (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,
520                   16#11#,16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#,
521                   16#12#,16#22#,16#32#,16#42#,16#52#,16#62#,16#72#,16#82#), "Bytes to B_Block192 failed");
522   end Types_Test29;
523
524   -----------------------------------------------------------------------------
525   ----------------------------------- Test 30 ----------------------------------
526   -----------------------------------------------------------------------------
527
528   procedure Types_Test30(T : in out Test_Cases.Test_Case'Class) is
529      use AUnit.Assertions;
530      I1 : constant Crypto.Types.Bytes(0..31) := (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,
531                                        16#11#,16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#,
532                                        16#12#,16#22#,16#32#,16#42#,16#52#,16#62#,16#72#,16#82#,
533                                       	16#13#,16#23#,16#33#,16#43#,16#53#,16#63#,16#73#,16#83#);
534      O1 : Crypto.Types.B_Block256;
535   begin
536      O1 := Crypto.Types.To_B_Block256(I1);
537
538      Assert(O1 = (16#10#,16#20#,16#30#,16#40#,16#50#,16#60#,16#70#,16#80#,
539                   16#11#,16#21#,16#31#,16#41#,16#51#,16#61#,16#71#,16#81#,
540                   16#12#,16#22#,16#32#,16#42#,16#52#,16#62#,16#72#,16#82#,
541                   16#13#,16#23#,16#33#,16#43#,16#53#,16#63#,16#73#,16#83#), "Bytes to B_Block256 failed");
542   end Types_Test30;
543
544   -----------------------------------------------------------------------------
545   ----------------------------------- Test 31 ----------------------------------
546   -----------------------------------------------------------------------------
547
548   procedure Types_Test31(T : in out Test_Cases.Test_Case'Class) is
549      use AUnit.Assertions;
550      I1 : constant Crypto.Types.Words(0..1) := (2#00000000_00000000_00000000_00000101#,2#00000000_00000000_00000000_00000101#);
551      I2 : constant Crypto.Types.Words(0..0) := (0 => 2#00000000_00000000_00000000_00000001#);
552      O  : Crypto.Types.Words(0..1);
553      pragma Unreferenced (O);
554   begin
555      O := I2 xor I1;
556
557      Assert(False, "Constraint_Error was expected but did not occur");
558   exception
559      when Constraint_Error => Assert(True, "");
560      when Error : others => Assert(False, "Constraint_Words_Error was expected but another (unexpected) exception occured");
561   end Types_Test31;
562
563   -----------------------------------------------------------------------------
564   ----------------------------------- Test 32 ----------------------------------
565   -----------------------------------------------------------------------------
566
567   procedure Types_Test32(T : in out Test_Cases.Test_Case'Class) is
568      use AUnit.Assertions;
569      I1 : constant Crypto.Types.Bytes(0..1) := (2#00000000#,2#00000000#);
570      I2 : constant Crypto.Types.Bytes(0..0) := (0 => 2#00000000#);
571      O  : Crypto.Types.Bytes(0..1);
572   begin
573      O := I2 xor I1;
574
575      Assert(False, "Constraint_Error was expected but did not occur");
576   exception
577      when Constraint_Error => Assert(True, "");
578      when Error : others => Assert(False, "Constraint_Error was expected but another (unexpected) exception occured");
579   end Types_Test32;
580
581   -----------------------------------------------------------------------------
582   ----------------------------------- Test 33 ----------------------------------
583   -----------------------------------------------------------------------------
584
585   procedure Types_Test33(T : in out Test_Cases.Test_Case'Class) is
586      use AUnit.Assertions;
587      I1 : constant Crypto.Types.DWords(0..1) := (16#00_00_00_00_00_00_00_00#,16#00_00_00_00_00_00_00_00#);
588      I2 : constant Crypto.Types.DWords(0..0) := (0 => 16#00_00_00_00_00_00_00_00#);
589      O  : Crypto.Types.DWords(0..1);
590   begin
591      O := I2 xor I1;
592
593      Assert(False, "Constraint_Error was expected but did not occur");
594   exception
595      when Constraint_Error => Assert(True, "");
596      when Error : others => Assert(False, "Constraint_Error was expected but another (unexpected) exception occured");
597   end Types_Test33;
598
599   -----------------------------------------------------------------------------
600   ----------------------------------- Test 34 ----------------------------------
601   -----------------------------------------------------------------------------
602
603   procedure Types_Test34(T : in out Test_Cases.Test_Case'Class) is
604      use AUnit.Assertions;
605      I1 : constant Crypto.Types.Byte := 16#00#;
606      I2 : constant Crypto.Types.Byte := 16#25#;
607      O1 : Crypto.Types.Hex_Byte;
608      O2 : Crypto.Types.Hex_Byte;
609   begin
610      O1 := Crypto.Types.To_Hex(I1);
611      O2 := Crypto.Types.To_Hex(I2);
612
613      Assert(O1 = "00" and O2 = "25", "Constraint_Error was expected but did not occur");
614   end Types_Test34;
615
616
617end Test.Types;
618