- 85D8EE9E1B9365BC2288699F301BF3D7109BDDBDB804F930EE855AAE7674806A57261DD216B816C2B5ECB6C8E8D62111065F6AB4AD9CD95AC8FA419F5FCCBC40
+ 87179F105DAC490F9AD51F357A4BB6E3CD34463DE8796428BBBDA1A1CAF84CEDC9B6FEEC85FF7208D416E1B0D5D32820F59A45675287F6456A5304AEC49DE85E
smg_comms/tests/io_rsa.adb
(7 . 16)(7 . 20)
298
299 package body IO_RSA is
300
301 procedure ReadRSAKey( Filename: in String; Key: out RSA_OAEP.RSA_skey ) is
302 procedure ReadRSAKey( Filename : in String;
303 E_Len_Chars : in Positive;
304 D_Len_Chars : in Positive;
305 Key : out RSA_OAEP.RSA_skey ) is
306 package Char_IO is new Ada.Sequential_IO(Character);
307 use Char_IO;
308 Full : String(1..RSA_len'Length*2) := (others => '0');
309 Half : String(1..RSA_half'Length*2) := (others => '0');
310 e : String(1..E_Len_Chars) := (others => '0');
311 d : String(1..D_Len_Chars) := (others => '0');
312 F : Char_IO.File_Type;
313 C : Character;
314 begin
315 Open( File => F, Mode => In_File, Name => Filename );
316
317 -- read n
318 for I in Full'Range loop
319 Read(F, Full(I));
(24 . 23)(28 . 33)
321 -- read new line character and convert to hex
322 Read(F, C);
323 Hex2Octets(Full, Key.n);
324
325 -- read e
326 for I in Half'Range loop
327 Read(F, Half(I));
328 for I in e'Range loop
329 Read(F, e(I));
330 end loop;
331 -- read new line character and convert to hex
332 -- read new line character and convert to hex, pad with 0 if needed
333 Read(F, C);
334 -- move it to Half, possibly at the end if e'len < half'len (0-led)
335 if e'Length > Half'Length then
336 raise Incorrect_E_Len;
337 else
338 Half(Half'Last-e'Length+1 .. Half'Last) := e;
339 end if;
340 Hex2Octets(Half, Key.e);
341
342 -- read d
343 for I in Full'Range loop
344 Read(F, Full(I));
345 for I in d'Range loop
346 Read(F, d(I));
347 end loop;
348
349 -- read new line character and convert to hex
350 Read(F, C);
351 if d'Length > Full'Length then
352 raise Incorrect_D_Len;
353 else
354 Full := ( others => '0' );
355 Full(Full'Last-d'Length+1 .. Full'Last) := d;
356 end if;
357 Hex2Octets(Full, Key.d);
358
359 -- read p
360 for I in Half'Range loop
361 Read(F, Half(I));
(48 . 7)(62 . 6)
363 -- read new line character and convert to hex
364 Read(F, C);
365 Hex2Octets(Half, Key.p);
366
367 -- read q
368 for I in Half'Range loop
369 Read(F, Half(I));
(56 . 16)(69 . 13)
371 -- read new line character and convert to hex
372 Read(F, C);
373 Hex2Octets(Half, Key.q);
374
375 -- read u
376 for I in Half'Range loop
377 Read(F, Half(I));
378 end loop;
379 Hex2Octets(Half, Key.u);
380
381 -- Close file
382 Close( F );
383
384 exception
385 when Char_IO.End_Error =>
386 Put_Line("ReadRSAKey ERROR: Unexpected end of file in " & Filename);
(80 . 7)(90 . 7)
388 H : String(1..Hex'Length+Hex'Length mod 2) := (others=>'0');
389 begin
390 -- first char is 0 if needed to cover full octet...
391 H(H'Length-Hex'Length+1..H'Length) := Hex;
392 H(H'Last-Hex'Length+1..H'Last) := Hex;
393 O := (others => 0);
394 for I in 0 .. H'Length/2-1 loop
395 S := "16#" & H(H'First + I*2 .. H'First + I*2 + 1) & "#";