1with AUnit.Assertions; 2with Crypto.Types.Big_Numbers; 3with Big_Number_Constants; 4 5pragma Elaborate_All(Crypto.Types.Big_Numbers); 6pragma Optimize(Time); 7 8package body Test.Big_Number_RL is 9 10------------------------------------------------------------------------------------ 11-------------------------------- Type - Declaration -------------------------------- 12------------------------------------------------------------------------------------ 13 14 package Big is new Crypto.Types.Big_Numbers(4096); 15 use Big; 16 use Big.Utils; 17 18 use Big_Number_Constants; 19 20 X_4096, X_4095, X_1025, X_1024, X_768, X_1, X_0, P, Q, R, Z : 21 Big_Unsigned; 22 23------------------------------------------------------------------------------------ 24------------------------------------ Constants ------------------------------------- 25------------------------------------------------------------------------------------ 26 27 procedure Constants is 28 begin 29 30 X_4096 := To_Big_Unsigned(Cons_4096); 31 X_4095 := To_Big_Unsigned(Cons_4095); 32 X_1025 := To_Big_Unsigned(Cons_1025); 33 X_1024 := To_Big_Unsigned(Cons_1024); 34 X_768 := To_Big_Unsigned(Cons_768); 35 X_1 := To_Big_Unsigned("1"); 36 X_0 := To_Big_Unsigned("0"); 37 38 end Constants; 39 40------------------------------------------------------------------------------------ 41---------------------------- Register Big_Number Test 1 ---------------------------- 42------------------------------------------------------------------------------------ 43 44 procedure Register_Tests(T : in out Big_Number_Test) is 45 use Test_Cases.Registration; 46 begin 47 48 Register_Routine(T, Big_Number_Test1'Access,"Shift Right"); 49 Register_Routine(T, Big_Number_Test2'Access,"Shift Right"); 50 Register_Routine(T, Big_Number_Test3'Access,"Shift Right"); 51 Register_Routine(T, Big_Number_Test4'Access,"Shift Right"); 52 Register_Routine(T, Big_Number_Test5'Access,"Shift Right"); 53 54 end Register_Tests; 55 56------------------------------------------------------------------------------------ 57------------------------------- Name Big Number Tests ------------------------------ 58------------------------------------------------------------------------------------ 59 60 function Name(T : Big_Number_Test) return Test_String is 61 begin 62 return new String'("Big Number Tests"); 63 end Name; 64 65------------------------------------------------------------------------------------ 66------------------------------------ Start Tests ----------------------------------- 67------------------------------------------------------------------------------------ 68-------------------------------------- Test 1 -------------------------------------- 69------------------------------------------------------------------------------------ 70 71 procedure Big_Number_Test1(T : in out Test_Cases.Test_Case'Class) is 72 use AUnit.Assertions; 73 begin 74 75 Constants; 76 P := Shift_Right(X_1024,3); 77 Q := To_Big_Unsigned("22471164185778948846616314884862809170224712236778832" & 78 "15917876014471658447568762039158855966530094200264001423498392416970734872" & 79 "11018020778116059288299342655472209866781081856595377774501557617649316353" & 80 "69010625721104768835292807860184239138817603404645418813835573287279993405" & 81 "742309964538104419541203028017151"); 82 Assert(P = Q, "Failed with 1024 Bit shifted right 3 times."); 83 84 P := Shift_Right(X_1024,187); 85 Q := To_Big_Unsigned("91644492539119875854140108587759483170309565350946088" & 86 "09421263904739540481712929330990490965063881080137395042950079910423806995" & 87 "44226348054414240833330066547856411977855334787272537640367327320839841280" & 88 "263415847919229777715415602675691481187407177449471"); 89 Assert(P = Q, "Failed with 1024 Bit shifted Right 187 times."); 90 91 P := Shift_Right(P,6); 92 Q := To_Big_Unsigned("14319451959237480602209391966837419245360869586085326" & 93 "26472072485115553200267645207967264213291231418771467975460949986003719843" & 94 "03785366883502225130207822898102564371539896060511334006307394893881225200" & 95 "04115872623737965276803368791807679393553237147647"); 96 Assert(P = Q, "Failed with 837 Bit shifted Right 6 times."); 97 98 end Big_Number_Test1; 99 100------------------------------------------------------------------------------------ 101-------------------------------------- Test 2 -------------------------------------- 102------------------------------------------------------------------------------------ 103 104 procedure Big_Number_Test2(T : in out Test_Cases.Test_Case'Class) is 105 use AUnit.Assertions; 106 begin 107 108 Q := To_Big_Unsigned("2#1000010001#"); 109 P := Shift_Right(Q,2); 110 Assert(P = 132, "Failed with 9 Bit shifted 2 times."); 111 112 P := Shift_Right(P,3); 113 Assert(P = 16, "Failed with 7 Bit shifted 3 times."); 114 115 end Big_Number_Test2; 116 117------------------------------------------------------------------------------------ 118-------------------------------------- Test 3 -------------------------------------- 119------------------------------------------------------------------------------------ 120 121 procedure Big_Number_Test3(T : in out Test_Cases.Test_Case'Class) is 122 use AUnit.Assertions; 123 begin 124 125 P := Shift_Right(X_1025,167); 126 Q := To_Big_Unsigned("96096215408700162943630818502518487824790522797433645" & 127 "26947711220176168400152616586172685054182824167486149144556422992152553844" & 128 "05286687137505466996049907860485085046091635529899088428785810612776957410" & 129 "293491536147754283397719630991265870577566668501257551872"); 130 Assert(P = Q, "Failed with 1025 Bit shifted 167 times."); 131 132 end Big_Number_Test3; 133 134------------------------------------------------------------------------------------ 135-------------------------------------- Test 4 -------------------------------------- 136------------------------------------------------------------------------------------ 137 138 procedure Big_Number_Test4(T : in out Test_Cases.Test_Case'Class) is 139 use AUnit.Assertions; 140 begin 141 142 P := Shift_Right(X_4096,3072); 143 Assert(P = X_1024, "Failed with 4096 Bit shifted 3072 times"); 144 145 end Big_Number_Test4; 146 147------------------------------------------------------------------------------------ 148-------------------------------------- Test 5 -------------------------------------- 149------------------------------------------------------------------------------------ 150 151 procedure Big_Number_Test5(T : in out Test_Cases.Test_Case'Class) is 152 use AUnit.Assertions; 153 begin 154 155 P := Shift_Right(X_0,1000); 156 Assert(P = X_0, "Failed with 0 Bit shifted 1000 times."); 157 158 end Big_Number_Test5; 159 160------------------------------------------------------------------------------------ 161 162end Test.Big_Number_RL; 163