raw
smg_comms_rsa_oaep      1  --S.MG, 2018
smg_comms_rsa_oaep 2
smg_comms_rsa_oaep 3 with Interfaces; use Interfaces;
smg_comms_rsa_oaep 4 with Interfaces.C; use Interfaces.C;
smg_comms_rsa_oaep 5 with RSA_OAEP; use RSA_OAEP;
smg_comms_rsa_oaep 6 with OAEP; use OAEP;
smg_comms_rsa_oaep 7 with Raw_Types; use Raw_Types;
smg_comms_rsa_oaep 8 with RNG; use RNG;
smg_comms_rsa_oaep 9 with Keccak; use Keccak;
smg_comms_rsa_oaep 10
smg_comms_rsa_oaep 11 with Ada.Text_IO; use Ada.Text_IO;
smg_comms_rsa_oaep 12
smg_comms_rsa_oaep 13 package body Test_RSA_OAEP is
smg_comms_rsa_oaep 14
smg_comms_rsa_oaep 15 procedure test_char_array is
smg_comms_rsa_oaep 16 S : String := OAEP.TMSR_STR;
smg_comms_packing... 17 O : Octets := Raw_Types.OAEP_RESERVED;
smg_comms_rsa_oaep 18 A : char_array(0..O'Length-1) := (others => '0');
smg_comms_rsa_oaep 19 B : Octets(0..O'Length -1) := (others => 0);
smg_comms_rsa_oaep 20 Fail : Boolean := FALSE;
smg_comms_rsa_oaep 21 begin
smg_comms_rsa_oaep 22 Octets_To_Char_Array(O, A);
smg_comms_rsa_oaep 23 Char_Array_To_Octets(A, B);
smg_comms_rsa_oaep 24
smg_comms_rsa_oaep 25 if B /= O then
smg_comms_rsa_oaep 26 Put_Line("FAIL: char_array_to_octets");
smg_comms_rsa_oaep 27 else
smg_comms_rsa_oaep 28 Put_Line("PASS: char_array_to_octets");
smg_comms_rsa_oaep 29 end if;
smg_comms_rsa_oaep 30
smg_comms_rsa_oaep 31 for I in 0..S'Length-1 loop
smg_comms_rsa_oaep 32 declare
smg_comms_rsa_oaep 33 C : Character := Character(A(A'First + size_t(I)));
smg_comms_rsa_oaep 34 E : Character := S(S'First + I);
smg_comms_rsa_oaep 35 begin
smg_comms_rsa_oaep 36 if C /= E then
smg_comms_rsa_oaep 37 Fail := TRUE;
smg_comms_rsa_oaep 38 Put("Error at pos " & Integer'Image(I) & ": ");
smg_comms_rsa_oaep 39 Put(Integer'Image(Character'Pos(C)));
smg_comms_rsa_oaep 40 Put_Line(" instead of " & Integer'Image(Character'Pos(E)));
smg_comms_rsa_oaep 41 end if;
smg_comms_rsa_oaep 42 end;
smg_comms_rsa_oaep 43 end loop;
smg_comms_rsa_oaep 44 if FAIL then
smg_comms_rsa_oaep 45 Put_Line("FAIL: test octets_to_char_array");
smg_comms_rsa_oaep 46 else
smg_comms_rsa_oaep 47 Put_Line("PASS: test octets_to_char_array");
smg_comms_rsa_oaep 48 end if;
smg_comms_rsa_oaep 49 end test_char_array;
smg_comms_rsa_oaep 50
smg_comms_rsa_oaep 51 -- test OAEP encrypt + decrypt
smg_comms_rsa_oaep 52 procedure test_oaep is
smg_comms_rsa_oaep 53 Plain: Octets(1..MAX_LEN_MSG);
smg_comms_rsa_oaep 54 Short: Octets(0..10);
smg_comms_rsa_oaep 55 Encr : OAEP_Block;
smg_comms_rsa_oaep 56 Decr : OAEP_HALF;
smg_comms_rsa_oaep 57 Len : Natural;
smg_comms_rsa_oaep 58 Entropy: OAEP_Block;
smg_comms_rsa_oaep 59 Success : Boolean;
smg_comms_rsa_oaep 60 begin
smg_comms_rsa_oaep 61 RNG.Get_Octets(Plain);
smg_comms_rsa_oaep 62 RNG.Get_Octets(Entropy);
smg_comms_rsa_oaep 63 RNG.Get_Octets(Short);
smg_comms_rsa_oaep 64
smg_comms_rsa_oaep 65 -- test full length message
smg_comms_rsa_oaep 66 OAEP_Encrypt(Plain, Entropy, Encr);
smg_comms_rsa_oaep 67 OAEP_Decrypt(Encr, Len, Decr, Success);
smg_comms_rsa_oaep 68
smg_comms_rsa_oaep 69 if not Success or Len/8 /= Plain'Length then
smg_comms_rsa_oaep 70 Put_Line("FAIL: oaep encrypt/decrypt on max len message.");
smg_comms_rsa_oaep 71 else
smg_comms_rsa_oaep 72 if Decr(Decr'First..Decr'First+Len/8-1) /=
smg_comms_rsa_oaep 73 Plain(Plain'First..Plain'First+Len/8-1) then
smg_comms_rsa_oaep 74 Put_Line("FAIL: oaep encrypt/decrypt on max len message - " &
smg_comms_rsa_oaep 75 "result different from expected.");
smg_comms_rsa_oaep 76 else
smg_comms_rsa_oaep 77 Put_Line("PASS: oaep encrypt/decrypt on max len message.");
smg_comms_rsa_oaep 78 end if;
smg_comms_rsa_oaep 79 end if;
smg_comms_rsa_oaep 80
smg_comms_rsa_oaep 81 -- test short message
smg_comms_rsa_oaep 82 OAEP_Encrypt(Short, Entropy, Encr);
smg_comms_rsa_oaep 83 OAEP_Decrypt(Encr, Len, Decr, Success);
smg_comms_rsa_oaep 84 if not Success or Len/8 /= Short'Length then
smg_comms_rsa_oaep 85 Put_Line("FAIL: oaep encrypt/decrypt on short message.");
smg_comms_rsa_oaep 86 else
smg_comms_rsa_oaep 87 if Decr(Decr'First..Decr'First+Len/8-1) /=
smg_comms_rsa_oaep 88 Short(Short'First..Short'First+Len/8-1) then
smg_comms_rsa_oaep 89 Put_Line("FAIL: oaep encrypt/decrypt on short message - " &
smg_comms_rsa_oaep 90 "result different from expected.");
smg_comms_rsa_oaep 91 else
smg_comms_rsa_oaep 92 Put_Line("PASS: oaep encrypt/decrypt on short message.");
smg_comms_rsa_oaep 93 end if;
smg_comms_rsa_oaep 94 end if;
smg_comms_rsa_oaep 95
smg_comms_rsa_oaep 96 end test_oaep;
smg_comms_rsa_oaep 97
smg_comms_rsa_oaep 98 -- test JUST RSA (i.e. without oaep) with RSA key pair previously generated
smg_comms_rsa_oaep 99 procedure test_rsa is
smg_comms_rsa_oaep 100 n: String := "C6579F8646180EED0DC1F02E0DDD2B43EABB3F702D79D9928E2CDA5E1D42DF5D9ED7773F80B1F8D9B0DB7D4D00F55647640D70768F63D3CED56A39C681D08D6191F318BB79DC969B470A7364D53335C8318EF35E39D5DF706AB6F2393C6DD2128C142DBAB1806EB35E26C908F0A48419313D2D0F33DD430655DBFEC722899EC21C238E8DB7003430BBC39BAD990F9887F6B03E1344F537EC97389B78DBC656718ACD7B0FDC13DD24534F417BC7A18F077A0C4227354CEA19670331B6CAA3DFC17BBA7E70C14510D9EB3B63F3014994EC87BD23E868C0AE6E9EC55027577F62C0280B2D7DD1135001844923E5455C4566E066B3FDE968C6BC4DC672F229FCE366440403D7A4F4A8BFBA5679B7D0844BA1231277D13A77C9E2B5A1CB138C1B7AB5B4D4832448723A3DE70ED2E86D5FC5174F949A02DE8E404304BEB95F9BF40F3AA3CA15622D2776294BE7E19233406FF563CB8C25A1CB5AADBC1899DA3F2AE38533931FE032EE3232C2CD4F219FADF95B91635C0762A476A4DE5013F4384093F0FB715028D97F93B2E6F057B99EE344D83ADF2686FD5C9C793928BEF3182E568C4339C36C744C8E9CA7D4B9A16AA039CBF6F38CC97B12D87644E94C9DBD6BC93A93A03ED61ECC5874586E3A310E958F858735E30019D345C62E5127B80652C8A970A14B31F03B3A157CD5";
smg_comms_rsa_oaep 101 e: String := "F74D78E382FC19B064411C6C20E0FDB2985F843007A54C7D8400BB459468624126E7D175F397E55C57AF25858EAE2D2952FB7998C119A6103606733EB5E1D27FCA1FACF14ADE94101D383D1B25DA511805569BC344EAD384EDBF3F3A541B34887FE199D99D7F62E6E9D516F88D6F5AD3E020DF04D402A02CC628A0064362FE8516CF7CD6040E9521407AB90EE6B5AFFF9EA9EBB16A7D3407CE81FD3844F519880556AB94AB349C1F3BBB6FDB4C4B377FE4C091EBDC2C3A1BD3AA56382D8D80E7742B5C751008FD6ECDD2EC3B2E3B6C566F698ED672000B403766DD63C3ACBDE16A14FB02E83A2EB6AA018BFC0020401E790DEE24E9";
smg_comms_rsa_oaep 102 d: String := "698DA05DA25B230211EEF0CBA12083A1457B749A11937AC9993859F69A3BF38D575E5166AF2EC88D77F1DF04E68AEA358EACF7659FD4722A4F5A1C8BA7676DA97A9FBA75451152F8F68887D3451A9CCFFFE9EB80979786E37495B17687A6212F77FA616E4C0CD8A8EB7AEB88EA6CCABB7F3E854FB94B35394A09F95F0D6F997947E865CC0606F437C30FE8C48D96FBF5E2F52807BC9E9ED7BBEB23D5C45EDDCD16FE2BF410A9A1E5EF879E71C0D41FAE270C0C5D442860103F8C3944E802F33DB38432F11F763A7AF593656108E4A98A44A8549913CE5DCEC1A6500F280E3190991B2B938561CFACD8BC5183AAC9A4914BFE52C3BE39BB83688E1DE52479107EF8E087DCDB409432FC954C6349407E81DDFB11AE92BABB32A31868597958C9C76E0B4156F380955F0E09C1F3B98BB4CDD59E1B5C7D8CC2AA7491B0D319D219CF459A527CE1AA2729DEC53269653BF0ED3E0253F4451168437E3B069E48350CA4C3EC82134E87135624C768D1330B0D70C6E447FD9945BF06FCB91AA334C0FD8EEF1ADBC15928B3DB62077B537F7E9F468CC95CD5AAFEAE1F760A863B48D07B163F670E2E5B550BB3E960230BA9FDAED9903AE2E669A7F3C4D1F1E25B8E8EDB8CC6E6FD2164E66F4E64ED77BEF1EC9E6CEA5624FD84C0680248746DC1C8187145F3CD2411659DAEAD11D";
smg_comms_rsa_oaep 103 p: String := "CDD6F7673A501FB24C44D56CA1D434F6CB3334E193E02F8E906241906BCB7412DD2159825B24C22002F373E647C2DA62A854F3841C00FD5985D03227CA9B54A69380BA9D63BE738BDF9E65C247E43E1220EEDD9281DCA78B32A4E1B786B7697ED0C3195D5AF2990881B11D6FC9EC9F940067B2DEA2A516FAA5F269C98F0B67628A6D2708515A4A58041AA17A93E4C4DD95C85BC38351DDA1DCF3DFD91C505B22383132649CF9F9233852C7207075BCF43C71038F043F1EC53E9787FB051B7927D020903233C16897B993C8089D8464451F086E756CF20E46CE6ED4A6AC5C327A0AAFBECBAAFD177969E7C952C76A4F4E7C85BF7F63";
smg_comms_rsa_oaep 104 q: String := "F6ACF0790A250802C8D45DAC549CDBEF7806D5877A5DF0069136A458FAC4F0B0858060A873DA6355A965A064A0BC1BBB874872CD7ED89674AD407533041E74BCA317EC73597D335115523F61A05071E5ED81EE2A05331F65D4DC7A25AD7938B124CF03F49154B6693FB0B598B33ABDEF85C599A57A9B7347EAFF82638E1CBC28FCDFFF1FF04A18C2DBF3938395C2F8D1782B43D3A25EF7633B5DDAC89EFD3BAA64D976425A0891E00B876E9DE9FE4B6492B0EA8DFC7C8DEEC61721356EC816295B1BD9CD9DA3E30D2D90DC9CB3987F4BE042104900E036F3044A016749EF910CCFB9F377A90849B4CCCF4471A74E67EF6C814C9467";
smg_comms_rsa_oaep 105 u: String := "854B89ED10F52258D00D6B3FA7F1FD22752804668F51FF7806DB82E22CB8B3AA8448D9B8E9DB14D31A36AEC2BCFA89E341B7334D494E97ED8051244136192233332C4612D963E7B6AF2535FDB7FE97E28DDFEBDFB3E1AFC29D05DBDF37106A817D3AB1864C7F7F247982897EDA6A92BED47D9C68305CD170C7301ACEB05F8A6382E73CC7614B2D8D758669B3A99AB64114809254B0BE21F40341A5B48B9B032603B14875B87EB5E16603FD16552E146A0FC6964958DFC25AA9FFCCD1ED1F4DEAF9FBAA0D7357F5FF0803FEB9BA78E74AC6B3070F417CEC6CFC7A3CF1E305FC7B76B7ED71893999AF797B2EBDE41FE90F076CCEDBFB";
smg_comms_rsa_oaep 106 Plain: OAEP_Block := (others => 0);
smg_comms_rsa_oaep 107 Decr : OAEP_Block := (others => 0);
smg_comms_rsa_oaep 108 Encr : RSA_len;
smg_comms_rsa_oaep 109 pkey: RSA_pkey;
smg_comms_rsa_oaep 110 skey: RSA_skey;
smg_comms_rsa_oaep 111 begin
smg_comms_rsa_oaep 112 -- initialize with RSA pair previously generated
smg_comms_rsa_oaep 113 Hex2Octets( n, skey.n );
smg_comms_rsa_oaep 114 Hex2Octets( e, skey.e );
smg_comms_rsa_oaep 115 Hex2Octets( d, skey.d );
smg_comms_rsa_oaep 116 Hex2Octets( p, skey.p );
smg_comms_rsa_oaep 117 Hex2Octets( q, skey.q );
smg_comms_rsa_oaep 118 Hex2Octets( u, skey.u );
smg_comms_rsa_oaep 119 -- copy n and e for public key
smg_comms_rsa_oaep 120 pkey.n := skey.n;
smg_comms_rsa_oaep 121 pkey.e := skey.e;
smg_comms_rsa_oaep 122 -- get random data
smg_comms_rsa_oaep 123 RNG.Get_Octets(Plain);
smg_comms_rsa_oaep 124 -- make first octet < RSA key's modulus first octet
smg_comms_rsa_oaep 125 Plain(Plain'First) := 16#00#;
smg_comms_rsa_oaep 126 -- naked rsa encrypt/decrypt
smg_comms_rsa_oaep 127 Put_Line("Encrypting with RSA public key...");
smg_comms_rsa_oaep 128 Public_RSA( Plain, pkey, Encr );
smg_comms_rsa_oaep 129 Put_Line("Decrypting with RSA private key...");
smg_comms_rsa_oaep 130 Private_RSA( Encr, skey, Decr );
smg_comms_rsa_oaep 131 Put_Line("Checking...");
smg_comms_rsa_oaep 132
smg_comms_rsa_oaep 133 -- check result
smg_comms_rsa_oaep 134 if Decr /= Plain then
smg_comms_rsa_oaep 135 Put_Line("FAIL: RSA encrypt/decrypt result doesn't match plain.");
smg_comms_rsa_oaep 136 else
smg_comms_rsa_oaep 137 Put_Line("PASS: RSA encrypt/decrypt");
smg_comms_rsa_oaep 138 end if;
smg_comms_rsa_oaep 139 end test_rsa;
smg_comms_rsa_oaep 140
smg_comms_rsa_oaep 141 -- test rsa+oaep with RSA key pair previously generated
smg_comms_rsa_oaep 142 procedure test_rsa_oaep is
smg_comms_rsa_oaep 143 n: String := "C6579F8646180EED0DC1F02E0DDD2B43EABB3F702D79D9928E2CDA5E1D42DF5D9ED7773F80B1F8D9B0DB7D4D00F55647640D70768F63D3CED56A39C681D08D6191F318BB79DC969B470A7364D53335C8318EF35E39D5DF706AB6F2393C6DD2128C142DBAB1806EB35E26C908F0A48419313D2D0F33DD430655DBFEC722899EC21C238E8DB7003430BBC39BAD990F9887F6B03E1344F537EC97389B78DBC656718ACD7B0FDC13DD24534F417BC7A18F077A0C4227354CEA19670331B6CAA3DFC17BBA7E70C14510D9EB3B63F3014994EC87BD23E868C0AE6E9EC55027577F62C0280B2D7DD1135001844923E5455C4566E066B3FDE968C6BC4DC672F229FCE366440403D7A4F4A8BFBA5679B7D0844BA1231277D13A77C9E2B5A1CB138C1B7AB5B4D4832448723A3DE70ED2E86D5FC5174F949A02DE8E404304BEB95F9BF40F3AA3CA15622D2776294BE7E19233406FF563CB8C25A1CB5AADBC1899DA3F2AE38533931FE032EE3232C2CD4F219FADF95B91635C0762A476A4DE5013F4384093F0FB715028D97F93B2E6F057B99EE344D83ADF2686FD5C9C793928BEF3182E568C4339C36C744C8E9CA7D4B9A16AA039CBF6F38CC97B12D87644E94C9DBD6BC93A93A03ED61ECC5874586E3A310E958F858735E30019D345C62E5127B80652C8A970A14B31F03B3A157CD5";
smg_comms_rsa_oaep 144 e: String := "F74D78E382FC19B064411C6C20E0FDB2985F843007A54C7D8400BB459468624126E7D175F397E55C57AF25858EAE2D2952FB7998C119A6103606733EB5E1D27FCA1FACF14ADE94101D383D1B25DA511805569BC344EAD384EDBF3F3A541B34887FE199D99D7F62E6E9D516F88D6F5AD3E020DF04D402A02CC628A0064362FE8516CF7CD6040E9521407AB90EE6B5AFFF9EA9EBB16A7D3407CE81FD3844F519880556AB94AB349C1F3BBB6FDB4C4B377FE4C091EBDC2C3A1BD3AA56382D8D80E7742B5C751008FD6ECDD2EC3B2E3B6C566F698ED672000B403766DD63C3ACBDE16A14FB02E83A2EB6AA018BFC0020401E790DEE24E9";
smg_comms_rsa_oaep 145 d: String := "698DA05DA25B230211EEF0CBA12083A1457B749A11937AC9993859F69A3BF38D575E5166AF2EC88D77F1DF04E68AEA358EACF7659FD4722A4F5A1C8BA7676DA97A9FBA75451152F8F68887D3451A9CCFFFE9EB80979786E37495B17687A6212F77FA616E4C0CD8A8EB7AEB88EA6CCABB7F3E854FB94B35394A09F95F0D6F997947E865CC0606F437C30FE8C48D96FBF5E2F52807BC9E9ED7BBEB23D5C45EDDCD16FE2BF410A9A1E5EF879E71C0D41FAE270C0C5D442860103F8C3944E802F33DB38432F11F763A7AF593656108E4A98A44A8549913CE5DCEC1A6500F280E3190991B2B938561CFACD8BC5183AAC9A4914BFE52C3BE39BB83688E1DE52479107EF8E087DCDB409432FC954C6349407E81DDFB11AE92BABB32A31868597958C9C76E0B4156F380955F0E09C1F3B98BB4CDD59E1B5C7D8CC2AA7491B0D319D219CF459A527CE1AA2729DEC53269653BF0ED3E0253F4451168437E3B069E48350CA4C3EC82134E87135624C768D1330B0D70C6E447FD9945BF06FCB91AA334C0FD8EEF1ADBC15928B3DB62077B537F7E9F468CC95CD5AAFEAE1F760A863B48D07B163F670E2E5B550BB3E960230BA9FDAED9903AE2E669A7F3C4D1F1E25B8E8EDB8CC6E6FD2164E66F4E64ED77BEF1EC9E6CEA5624FD84C0680248746DC1C8187145F3CD2411659DAEAD11D";
smg_comms_rsa_oaep 146 p: String := "CDD6F7673A501FB24C44D56CA1D434F6CB3334E193E02F8E906241906BCB7412DD2159825B24C22002F373E647C2DA62A854F3841C00FD5985D03227CA9B54A69380BA9D63BE738BDF9E65C247E43E1220EEDD9281DCA78B32A4E1B786B7697ED0C3195D5AF2990881B11D6FC9EC9F940067B2DEA2A516FAA5F269C98F0B67628A6D2708515A4A58041AA17A93E4C4DD95C85BC38351DDA1DCF3DFD91C505B22383132649CF9F9233852C7207075BCF43C71038F043F1EC53E9787FB051B7927D020903233C16897B993C8089D8464451F086E756CF20E46CE6ED4A6AC5C327A0AAFBECBAAFD177969E7C952C76A4F4E7C85BF7F63";
smg_comms_rsa_oaep 147 q: String := "F6ACF0790A250802C8D45DAC549CDBEF7806D5877A5DF0069136A458FAC4F0B0858060A873DA6355A965A064A0BC1BBB874872CD7ED89674AD407533041E74BCA317EC73597D335115523F61A05071E5ED81EE2A05331F65D4DC7A25AD7938B124CF03F49154B6693FB0B598B33ABDEF85C599A57A9B7347EAFF82638E1CBC28FCDFFF1FF04A18C2DBF3938395C2F8D1782B43D3A25EF7633B5DDAC89EFD3BAA64D976425A0891E00B876E9DE9FE4B6492B0EA8DFC7C8DEEC61721356EC816295B1BD9CD9DA3E30D2D90DC9CB3987F4BE042104900E036F3044A016749EF910CCFB9F377A90849B4CCCF4471A74E67EF6C814C9467";
smg_comms_rsa_oaep 148 u: String := "854B89ED10F52258D00D6B3FA7F1FD22752804668F51FF7806DB82E22CB8B3AA8448D9B8E9DB14D31A36AEC2BCFA89E341B7334D494E97ED8051244136192233332C4612D963E7B6AF2535FDB7FE97E28DDFEBDFB3E1AFC29D05DBDF37106A817D3AB1864C7F7F247982897EDA6A92BED47D9C68305CD170C7301ACEB05F8A6382E73CC7614B2D8D758669B3A99AB64114809254B0BE21F40341A5B48B9B032603B14875B87EB5E16603FD16552E146A0FC6964958DFC25AA9FFCCD1ED1F4DEAF9FBAA0D7357F5FF0803FEB9BA78E74AC6B3070F417CEC6CFC7A3CF1E305FC7B76B7ED71893999AF797B2EBDE41FE90F076CCEDBFB";
smg_comms_rsa_oaep 149 Plain: Octets(1..MAX_LEN_MSG) := (others=>20);
smg_comms_rsa_oaep 150 Short: Octets(1..10);
smg_comms_rsa_oaep 151 Decr : RSA_len;
smg_comms_rsa_oaep 152 Encr : RSA_len;
smg_comms_rsa_oaep 153 pkey: RSA_pkey;
smg_comms_rsa_oaep 154 skey: RSA_skey;
smg_comms_rsa_oaep 155 Success: Boolean;
smg_comms_rsa_oaep 156 Len : Natural;
smg_comms_rsa_oaep 157 begin
smg_comms_rsa_oaep 158 -- initialize with RSA pair previously generated
smg_comms_rsa_oaep 159 Hex2Octets( n, skey.n );
smg_comms_rsa_oaep 160 Hex2Octets( e, skey.e );
smg_comms_rsa_oaep 161 Hex2Octets( d, skey.d );
smg_comms_rsa_oaep 162 Hex2Octets( p, skey.p );
smg_comms_rsa_oaep 163 Hex2Octets( q, skey.q );
smg_comms_rsa_oaep 164 Hex2Octets( u, skey.u );
smg_comms_rsa_oaep 165 -- copy n and e for public key
smg_comms_rsa_oaep 166 pkey.n := skey.n;
smg_comms_rsa_oaep 167 pkey.e := skey.e;
smg_comms_rsa_oaep 168
smg_comms_rsa_oaep 169 -- test with 0 message of length Plain'Length
smg_comms_rsa_oaep 170 RSA_OAEP.Encrypt(Plain, pkey, Encr);
smg_comms_rsa_oaep 171 RSA_OAEP.Decrypt(Encr, skey, Decr, Len, Success);
smg_comms_rsa_oaep 172 if (not Success) or Len /= Plain'Length
smg_comms_rsa_oaep 173 or Plain /= Decr(Decr'First..Decr'First+Plain'Length-1) then
smg_comms_rsa_oaep 174 Put_Line("FAIL: RSA_OAEP on max len message 20-filled.");
smg_comms_rsa_oaep 175 else
smg_comms_rsa_oaep 176 Put_Line("PASS: RSA_OAEP on max len message 20-filled.");
smg_comms_rsa_oaep 177 end if;
smg_comms_rsa_oaep 178
smg_comms_rsa_oaep 179 -- get random data for "plain" message
smg_comms_rsa_oaep 180 RNG.Get_Octets(Plain);
smg_comms_rsa_oaep 181 RSA_OAEP.Encrypt(Plain, pkey, Encr);
smg_comms_rsa_oaep 182 RSA_OAEP.Decrypt(Encr, skey, Decr, Len, Success);
smg_comms_rsa_oaep 183 if (not Success) or Len /= Plain'Length
smg_comms_rsa_oaep 184 or Plain /= Decr(Decr'First..Decr'First+Plain'Length-1) then
smg_comms_rsa_oaep 185 Put_Line("FAIL: RSA_OAEP on random data of max length.");
smg_comms_rsa_oaep 186 else
smg_comms_rsa_oaep 187 Put_Line("PASS: RSA_OAEP on random data of max length.");
smg_comms_rsa_oaep 188 end if;
smg_comms_rsa_oaep 189
smg_comms_rsa_oaep 190 -- get random data for "short" message
smg_comms_rsa_oaep 191 RNG.Get_Octets(Short);
smg_comms_rsa_oaep 192 RSA_OAEP.Encrypt(Short, pkey, Encr);
smg_comms_rsa_oaep 193 RSA_OAEP.Decrypt(Encr, skey, Decr, Len, Success);
smg_comms_rsa_oaep 194 if (not Success) or Len /= Short'Length
smg_comms_rsa_oaep 195 or Short /= Decr(Decr'First..Decr'First+Short'Length-1) then
smg_comms_rsa_oaep 196 Put_Line("FAIL: RSA_OAEP on random data of short length.");
smg_comms_rsa_oaep 197 else
smg_comms_rsa_oaep 198 Put_Line("PASS: RSA_OAEP on random data of short length.");
smg_comms_rsa_oaep 199 end if;
smg_comms_rsa_oaep 200
smg_comms_rsa_oaep 201 end test_rsa_oaep;
smg_comms_rsa_oaep 202
smg_comms_rsa_oaep 203 -- helper methods
smg_comms_rsa_oaep 204 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets ) is
smg_comms_rsa_oaep 205 S : String := "16#AA#";
smg_comms_rsa_oaep 206 -- to make sure that input String has EVEN number of chars (ie full octets)
smg_comms_rsa_oaep 207 H : String(1..Hex'Length+Hex'Length mod 2) := (others=>'0');
smg_comms_rsa_oaep 208 begin
smg_comms_rsa_oaep 209 -- first char is 0 if needed to cover full octet...
smg_comms_rsa_oaep 210 H(H'Length-Hex'Length+1..H'Length) := Hex;
smg_comms_rsa_oaep 211 O := (others => 0);
smg_comms_rsa_oaep 212 for I in 0 .. H'Length/2-1 loop
smg_comms_rsa_oaep 213 S := "16#" & H(H'First + I*2 .. H'First + I*2 + 1) & "#";
smg_comms_rsa_oaep 214 O(O'Last - H'Length/2 + 1 + I) := Unsigned_8'Value(S);
smg_comms_rsa_oaep 215 end loop;
smg_comms_rsa_oaep 216 end Hex2Octets;
smg_comms_rsa_oaep 217
smg_comms_rsa_oaep 218 procedure PrintOctets( O: in Raw_Types.Octets; Title: in String ) is
smg_comms_rsa_oaep 219 begin
smg_comms_rsa_oaep 220 Put_Line(Title);
smg_comms_rsa_oaep 221 for V of O loop
smg_comms_rsa_oaep 222 Put(Unsigned_8'Image(V) & " ");
smg_comms_rsa_oaep 223 end loop;
smg_comms_rsa_oaep 224 New_Line;
smg_comms_rsa_oaep 225 end PrintOctets;
smg_comms_rsa_oaep 226
smg_comms_rsa_oaep 227 end Test_RSA_OAEP;