tree checksum vpatch file split hunks

all signers: diana_coman

antecedents: smg_comms_80cols smg_comms_packing_rsa smg_comms_skeys_smsgs

press order:

smg_comms_genesisdiana_coman
smg_comms_raw_typesdiana_coman
smg_comms_packing_serpentdiana_coman
smg_comms_c_wrappersdiana_coman
smg_comms_rsa_oaepdiana_coman
smg_comms_packing_rsadiana_coman
smg_comms_80colsdiana_coman
smg_comms_skeys_smsgsdiana_coman
smg_comms_io_rsa_tests_onlydiana_coman

patch:

- 32A691949AF3FB21EAF17C73269D01A30CB9F940EE5662772EB2C5E67A8352AEDC07B8A7CBA6A6D7F7BE1E42559E003B82BBEB97FB059FFB579BCC33A9AB2693
+ 74EC120B48CC4434D960AF06970594E47C843327FB3C12314CF1C68B7C5FD0899BF402E431398D0C5FF1F12B9151A9EB87915CBE4746E537FDC3376948F596AF
smg_comms/manifest
(6 . 3)(6 . 4)
5 548433 smg_comms_packing_rsa diana_coman Packing/Unpacking RSA messages <-> RSA packets of Eulora's communication protocol.
6 548894 smg_comms_80cols diana_coman Changes tests for RSA to read the key from a file in order to avoid lines > 80 columns in the code itself.
7 549511 smg_comms_skeys_smsgs diana_coman Defines data structures and message types as well as methods for reading/writing Serpent keysets to/from Serpent messages.
8 549785 smg_comms_io_rsa_tests_only diana_coman Small refactoring of tests extracting the reading of RSA key into package of its own so it can be used throughout tests and thus get rid of the too long lines in test_packing.adb.
-
+ 85D8EE9E1B9365BC2288699F301BF3D7109BDDBDB804F930EE855AAE7674806A57261DD216B816C2B5ECB6C8E8D62111065F6AB4AD9CD95AC8FA419F5FCCBC40
smg_comms/tests/io_rsa.adb
(0 . 0)(1 . 91)
13 -- S.MG, 2018
14
15 with Ada.Sequential_IO;
16 with Raw_Types; use Raw_Types;
17 with Ada.Text_IO; use Ada.Text_IO;
18 with Interfaces; use Interfaces;
19
20 package body IO_RSA is
21
22 procedure ReadRSAKey( Filename: in String; Key: out RSA_OAEP.RSA_skey ) is
23 package Char_IO is new Ada.Sequential_IO(Character);
24 use Char_IO;
25 Full : String(1..RSA_len'Length*2) := (others => '0');
26 Half : String(1..RSA_half'Length*2) := (others => '0');
27 F : Char_IO.File_Type;
28 C : Character;
29 begin
30 Open( File => F, Mode => In_File, Name => Filename );
31
32 -- read n
33 for I in Full'Range loop
34 Read(F, Full(I));
35 end loop;
36 -- read new line character and convert to hex
37 Read(F, C);
38 Hex2Octets(Full, Key.n);
39
40 -- read e
41 for I in Half'Range loop
42 Read(F, Half(I));
43 end loop;
44 -- read new line character and convert to hex
45 Read(F, C);
46 Hex2Octets(Half, Key.e);
47
48 -- read d
49 for I in Full'Range loop
50 Read(F, Full(I));
51 end loop;
52 -- read new line character and convert to hex
53 Read(F, C);
54 Hex2Octets(Full, Key.d);
55
56 -- read p
57 for I in Half'Range loop
58 Read(F, Half(I));
59 end loop;
60 -- read new line character and convert to hex
61 Read(F, C);
62 Hex2Octets(Half, Key.p);
63
64 -- read q
65 for I in Half'Range loop
66 Read(F, Half(I));
67 end loop;
68 -- read new line character and convert to hex
69 Read(F, C);
70 Hex2Octets(Half, Key.q);
71
72 -- read u
73 for I in Half'Range loop
74 Read(F, Half(I));
75 end loop;
76 Hex2Octets(Half, Key.u);
77
78 -- Close file
79 Close( F );
80
81 exception
82 when Char_IO.End_Error =>
83 Put_Line("ReadRSAKey ERROR: Unexpected end of file in " & Filename);
84 when others =>
85 Put_Line("ReadRSAKey ERROR: can not open file " & Filename);
86
87 end ReadRSAKey;
88
89 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets ) is
90 S : String := "16#AA#";
91 -- to make sure that input String has EVEN number of chars (ie full octets)
92 H : String(1..Hex'Length+Hex'Length mod 2) := (others=>'0');
93 begin
94 -- first char is 0 if needed to cover full octet...
95 H(H'Length-Hex'Length+1..H'Length) := Hex;
96 O := (others => 0);
97 for I in 0 .. H'Length/2-1 loop
98 S := "16#" & H(H'First + I*2 .. H'First + I*2 + 1) & "#";
99 O(O'Last - H'Length/2 + 1 + I) := Unsigned_8'Value(S);
100 end loop;
101 end Hex2Octets;
102
103 end IO_RSA;
-
+ 57AD398331BF9B99C93592FCA3BDEFF7CA8EBFD630EC3FC142706498EB4A7DCB05F21520670D5945C26046237C7DE2C93E021801157B5BF8BF99308FB004D8E4
smg_comms/tests/io_rsa.ads
(0 . 0)(1 . 21)
108 -- reading a RSA key pair from a file
109 -- NB: this is for TESTING purposes only, NOT a production IO package!
110 -- S.MG, 2018
111
112 with Raw_Types;
113 with RSA_OAEP;
114
115 package IO_RSA is
116
117 -- reads a full private key from specified file, in Hex format
118 -- one component per line, in order: n, e, d, p, q, u
119 -- NB: length of each component has to match *precisely* the expected length
120 -- specifically, using Raw_Types:
121 -- n, d are RSA_len'Length*2;
122 -- e, p, q, u are RSA_half'Length*2
123 procedure ReadRSAKey( Filename: in String; Key: out RSA_OAEP.RSA_skey );
124
125 -- convert hexadecimal strings to octets representation
126 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets );
127
128 end IO_RSA;
- AA23A7DCA5D7DB80C185AB5C81D4E3645D3A32CE795559DC6C057806BA4928D1C56B0528FC45578DFB0AE69152B290ABC591EB86931B59E1A862ADF7AD480AE5
+ EAFEF048291AFF4715A31FE02B0BA62CAB5D4B2D5D1E904B4A25DBA9B08584B198C4BAB46CA115B4809DD8506875719D6F30C506797CD0B399A2077C22BA1882
smg_comms/tests/test_packing.adb
(6 . 6)(6 . 7)
133 with RSA_OAEP; use RSA_OAEP;
134 with Serpent; use Serpent;
135 with RNG; use RNG;
136 with IO_RSA;
137
138 with Interfaces; use Interfaces;
139 with Ada.Text_IO; use Ada.Text_IO;
(71 . 20)(72 . 10)
141 SKey : RSA_skey;
142 Success : Boolean;
143 Pkt : RSA_Pkt;
144 n: String := "C6579F8646180EED0DC1F02E0DDD2B43EABB3F702D79D9928E2CDA5E1D42DF5D9ED7773F80B1F8D9B0DB7D4D00F55647640D70768F63D3CED56A39C681D08D6191F318BB79DC969B470A7364D53335C8318EF35E39D5DF706AB6F2393C6DD2128C142DBAB1806EB35E26C908F0A48419313D2D0F33DD430655DBFEC722899EC21C238E8DB7003430BBC39BAD990F9887F6B03E1344F537EC97389B78DBC656718ACD7B0FDC13DD24534F417BC7A18F077A0C4227354CEA19670331B6CAA3DFC17BBA7E70C14510D9EB3B63F3014994EC87BD23E868C0AE6E9EC55027577F62C0280B2D7DD1135001844923E5455C4566E066B3FDE968C6BC4DC672F229FCE366440403D7A4F4A8BFBA5679B7D0844BA1231277D13A77C9E2B5A1CB138C1B7AB5B4D4832448723A3DE70ED2E86D5FC5174F949A02DE8E404304BEB95F9BF40F3AA3CA15622D2776294BE7E19233406FF563CB8C25A1CB5AADBC1899DA3F2AE38533931FE032EE3232C2CD4F219FADF95B91635C0762A476A4DE5013F4384093F0FB715028D97F93B2E6F057B99EE344D83ADF2686FD5C9C793928BEF3182E568C4339C36C744C8E9CA7D4B9A16AA039CBF6F38CC97B12D87644E94C9DBD6BC93A93A03ED61ECC5874586E3A310E958F858735E30019D345C62E5127B80652C8A970A14B31F03B3A157CD5";
145 e: String := "F74D78E382FC19B064411C6C20E0FDB2985F843007A54C7D8400BB459468624126E7D175F397E55C57AF25858EAE2D2952FB7998C119A6103606733EB5E1D27FCA1FACF14ADE94101D383D1B25DA511805569BC344EAD384EDBF3F3A541B34887FE199D99D7F62E6E9D516F88D6F5AD3E020DF04D402A02CC628A0064362FE8516CF7CD6040E9521407AB90EE6B5AFFF9EA9EBB16A7D3407CE81FD3844F519880556AB94AB349C1F3BBB6FDB4C4B377FE4C091EBDC2C3A1BD3AA56382D8D80E7742B5C751008FD6ECDD2EC3B2E3B6C566F698ED672000B403766DD63C3ACBDE16A14FB02E83A2EB6AA018BFC0020401E790DEE24E9";
146 d: String := "698DA05DA25B230211EEF0CBA12083A1457B749A11937AC9993859F69A3BF38D575E5166AF2EC88D77F1DF04E68AEA358EACF7659FD4722A4F5A1C8BA7676DA97A9FBA75451152F8F68887D3451A9CCFFFE9EB80979786E37495B17687A6212F77FA616E4C0CD8A8EB7AEB88EA6CCABB7F3E854FB94B35394A09F95F0D6F997947E865CC0606F437C30FE8C48D96FBF5E2F52807BC9E9ED7BBEB23D5C45EDDCD16FE2BF410A9A1E5EF879E71C0D41FAE270C0C5D442860103F8C3944E802F33DB38432F11F763A7AF593656108E4A98A44A8549913CE5DCEC1A6500F280E3190991B2B938561CFACD8BC5183AAC9A4914BFE52C3BE39BB83688E1DE52479107EF8E087DCDB409432FC954C6349407E81DDFB11AE92BABB32A31868597958C9C76E0B4156F380955F0E09C1F3B98BB4CDD59E1B5C7D8CC2AA7491B0D319D219CF459A527CE1AA2729DEC53269653BF0ED3E0253F4451168437E3B069E48350CA4C3EC82134E87135624C768D1330B0D70C6E447FD9945BF06FCB91AA334C0FD8EEF1ADBC15928B3DB62077B537F7E9F468CC95CD5AAFEAE1F760A863B48D07B163F670E2E5B550BB3E960230BA9FDAED9903AE2E669A7F3C4D1F1E25B8E8EDB8CC6E6FD2164E66F4E64ED77BEF1EC9E6CEA5624FD84C0680248746DC1C8187145F3CD2411659DAEAD11D";
147 p: String := "CDD6F7673A501FB24C44D56CA1D434F6CB3334E193E02F8E906241906BCB7412DD2159825B24C22002F373E647C2DA62A854F3841C00FD5985D03227CA9B54A69380BA9D63BE738BDF9E65C247E43E1220EEDD9281DCA78B32A4E1B786B7697ED0C3195D5AF2990881B11D6FC9EC9F940067B2DEA2A516FAA5F269C98F0B67628A6D2708515A4A58041AA17A93E4C4DD95C85BC38351DDA1DCF3DFD91C505B22383132649CF9F9233852C7207075BCF43C71038F043F1EC53E9787FB051B7927D020903233C16897B993C8089D8464451F086E756CF20E46CE6ED4A6AC5C327A0AAFBECBAAFD177969E7C952C76A4F4E7C85BF7F63";
148 q: String := "F6ACF0790A250802C8D45DAC549CDBEF7806D5877A5DF0069136A458FAC4F0B0858060A873DA6355A965A064A0BC1BBB874872CD7ED89674AD407533041E74BCA317EC73597D335115523F61A05071E5ED81EE2A05331F65D4DC7A25AD7938B124CF03F49154B6693FB0B598B33ABDEF85C599A57A9B7347EAFF82638E1CBC28FCDFFF1FF04A18C2DBF3938395C2F8D1782B43D3A25EF7633B5DDAC89EFD3BAA64D976425A0891E00B876E9DE9FE4B6492B0EA8DFC7C8DEEC61721356EC816295B1BD9CD9DA3E30D2D90DC9CB3987F4BE042104900E036F3044A016749EF910CCFB9F377A90849B4CCCF4471A74E67EF6C814C9467";
149 u: String := "854B89ED10F52258D00D6B3FA7F1FD22752804668F51FF7806DB82E22CB8B3AA8448D9B8E9DB14D31A36AEC2BCFA89E341B7334D494E97ED8051244136192233332C4612D963E7B6AF2535FDB7FE97E28DDFEBDFB3E1AFC29D05DBDF37106A817D3AB1864C7F7F247982897EDA6A92BED47D9C68305CD170C7301ACEB05F8A6382E73CC7614B2D8D758669B3A99AB64114809254B0BE21F40341A5B48B9B032603B14875B87EB5E16603FD16552E146A0FC6964958DFC25AA9FFCCD1ED1F4DEAF9FBAA0D7357F5FF0803FEB9BA78E74AC6B3070F417CEC6CFC7A3CF1E305FC7B76B7ED71893999AF797B2EBDE41FE90F076CCEDBFB";
150 begin
151 -- initialize RSA key with values previously obtained from EuCrypt
152 Hex2Octets( n, SKey.n );
153 Hex2Octets( e, SKey.e );
154 Hex2Octets( d, SKey.d );
155 Hex2Octets( p, SKey.p );
156 Hex2Octets( q, SKey.q );
157 Hex2Octets( u, SKey.u );
158 -- initialize with RSA pair previously generated
159 IO_RSA.ReadRSAKey( "keys_rsa.txt", SKey );
160
161 -- copy n and e for public key
162 PKey.n := SKey.n;
163 PKey.e := SKey.e;
(113 . 20)(104 . 4)
165
166 end Test_Pack_Unpack_RSA;
167
168 -- helper methods
169 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets ) is
170 S : String := "16#AA#";
171 -- to make sure that input String has EVEN number of chars (ie full octets)
172 H : String(1..Hex'Length+Hex'Length mod 2) := (others=>'0');
173 begin
174 -- first char is 0 if needed to cover full octet...
175 H(H'Length-Hex'Length+1..H'Length) := Hex;
176 O := (others => 0);
177 for I in 0 .. H'Length/2-1 loop
178 S := "16#" & H(H'First + I*2 .. H'First + I*2 + 1) & "#";
179 O(O'Last - H'Length/2 + 1 + I) := Unsigned_8'Value(S);
180 end loop;
181 end Hex2Octets;
182
183
184 end Test_Packing;
- 0B774F9947B49EC87836A030BA9AE0B8AD0C802DF3FAA23A00D1019BA4CEF610765F36CD7E36212EBDB80EE32691E39277A42C11F88E9B3FA949E1CAB6FA676F
+ F3C2249DBA0E03E0FFBEC136B9A7CB0193C9DA04530E64852E358A3F9E4212464C60D9B3B85E6209622F37CC9D9C52C6722511719F05E38EEE5E5AC50CA4885B
smg_comms/tests/test_packing.ads
(15 . 7)(15 . 4)
189 -- testing pack/unpack for RSA
190 procedure Test_Pack_Unpack_RSA;
191
192 -- helper methods
193 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets );
194
195 end Test_Packing;
- D8FB2B62B07A71DE0B2269325308207B9B2CFA850195D64339F7D35B33DE572BCC01121CFE6EEC977A2B12097EA34C39F12E27BC651E26E47F5A7DAD74AE27F1
+ 6D2A795035290C00E290240A4D93260ACDC2D7253CE4742BEE41515920FDFB6EE78C4154753EF5F0FFF15DED3D28FC69CA0AA90EF417FAC0E914F3E4D4EB4A10
smg_comms/tests/test_rsa_oaep.adb
(3 . 12)(3 . 12)
200 with Interfaces; use Interfaces;
201 with Interfaces.C; use Interfaces.C;
202 with Ada.Text_IO; use Ada.Text_IO;
203 with Ada.Sequential_IO;
204 with RSA_OAEP; use RSA_OAEP;
205 with OAEP; use OAEP;
206 with Raw_Types; use Raw_Types;
207 with RNG; use RNG;
208 with Keccak; use Keccak;
209 with IO_RSA;
210
211 package body Test_RSA_OAEP is
212
(104 . 7)(104 . 7)
214 skey: RSA_skey;
215 begin
216 -- initialize with RSA pair previously generated
217 ReadRSAKey( "keys_rsa.txt", skey );
218 IO_RSA.ReadRSAKey( "keys_rsa.txt", skey );
219
220 -- copy n and e for public key
221 pkey.n := skey.n;
(140 . 7)(140 . 7)
223 Len : Natural;
224 begin
225 -- initialize with RSA pair previously generated
226 ReadRSAKey( "keys_rsa.txt", skey );
227 IO_RSA.ReadRSAKey( "keys_rsa.txt", skey );
228 -- copy n and e for public key
229 pkey.n := skey.n;
230 pkey.e := skey.e;
(180 . 19)(180 . 6)
232 end test_rsa_oaep;
233
234 -- helper methods
235 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets ) is
236 S : String := "16#AA#";
237 -- to make sure that input String has EVEN number of chars (ie full octets)
238 H : String(1..Hex'Length+Hex'Length mod 2) := (others=>'0');
239 begin
240 -- first char is 0 if needed to cover full octet...
241 H(H'Length-Hex'Length+1..H'Length) := Hex;
242 O := (others => 0);
243 for I in 0 .. H'Length/2-1 loop
244 S := "16#" & H(H'First + I*2 .. H'First + I*2 + 1) & "#";
245 O(O'Last - H'Length/2 + 1 + I) := Unsigned_8'Value(S);
246 end loop;
247 end Hex2Octets;
248
249 procedure PrintOctets( O: in Raw_Types.Octets; Title: in String ) is
250 begin
(203 . 71)(190 . 4)
252 New_Line;
253 end PrintOctets;
254
255 procedure ReadRSAKey( Filename: in String; Key: out RSA_OAEP.RSA_skey ) is
256 package Char_IO is new Ada.Sequential_IO(Character);
257 use Char_IO;
258 Full : String(1..RSA_len'Length*2) := (others => '0');
259 Half : String(1..RSA_half'Length*2) := (others => '0');
260 F : Char_IO.File_Type;
261 C : Character;
262 begin
263 Open( File => F, Mode => In_File, Name => Filename );
264
265 -- read n
266 for I in Full'Range loop
267 Read(F, Full(I));
268 end loop;
269 -- read new line character and convert to hex
270 Read(F, C);
271 Hex2Octets(Full, Key.n);
272
273 -- read e
274 for I in Half'Range loop
275 Read(F, Half(I));
276 end loop;
277 -- read new line character and convert to hex
278 Read(F, C);
279 Hex2Octets(Half, Key.e);
280
281 -- read d
282 for I in Full'Range loop
283 Read(F, Full(I));
284 end loop;
285 -- read new line character and convert to hex
286 Read(F, C);
287 Hex2Octets(Full, Key.d);
288
289 -- read p
290 for I in Half'Range loop
291 Read(F, Half(I));
292 end loop;
293 -- read new line character and convert to hex
294 Read(F, C);
295 Hex2Octets(Half, Key.p);
296
297 -- read q
298 for I in Half'Range loop
299 Read(F, Half(I));
300 end loop;
301 -- read new line character and convert to hex
302 Read(F, C);
303 Hex2Octets(Half, Key.q);
304
305 -- read u
306 for I in Half'Range loop
307 Read(F, Half(I));
308 end loop;
309 Hex2Octets(Half, Key.u);
310
311 -- Close file
312 Close( F );
313
314 exception
315 when Char_IO.End_Error =>
316 Put_Line("ReadRSAKey ERROR: Unexpected end of file in " & Filename);
317 when others =>
318 Put_Line("ReadRSAKey ERROR: can not open file " & Filename);
319
320 end ReadRSAKey;
321
322 end Test_RSA_OAEP;
- 88B6D8984DF53BCBC6D173D67B4BA34E0F25EF40D204C3787DAAE8BD38C8B633AD4EF8FF39F10BC5D541423774386BA0C671FB49218DF1A89A48A0DDCDFBD324
+ 30C188E997945F1E93BE60C3D4C9D19F96C316252CA5FD8E538BCE871D6E67C0538EE113EA9456B37E0E91572D2B218E70B139A5BDB8D79B64EED2D5E7AFC71B
smg_comms/tests/test_rsa_oaep.ads
(9 . 13)(9 . 5)
327 procedure test_rsa; -- test rsa only
328 procedure test_rsa_oaep; -- test rsa+oaep
329
330 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets );
331 procedure PrintOctets( O: in Raw_Types.Octets; Title: in String );
332 -- reads a full private key from specified file, in Hex format
333 -- one component per line, in order: n, e, d, p, q, u
334 -- NB: length of each component has to match *precisely* the expected length
335 -- specifically, using Raw_Types:
336 -- n, d are RSA_len'Length*2;
337 -- e, p, q, u are RSA_half'Length*2
338 procedure ReadRSAKey( Filename: in String; Key: out RSA_OAEP.RSA_skey );
339 end Test_RSA_OAEP;