raw
smg_comms_io_rsa_...    1  -- reading a RSA key pair from a file
smg_comms_io_rsa_... 2 -- NB: this is for TESTING purposes only, NOT a production IO package!
smg_comms_io_rsa_... 3 -- S.MG, 2018
smg_comms_io_rsa_... 4
smg_comms_io_rsa_... 5 with Raw_Types;
smg_comms_io_rsa_... 6 with RSA_OAEP;
smg_comms_io_rsa_... 7
smg_comms_io_rsa_... 8 package IO_RSA is
smg_comms_io_rsa_... 9
smg_comms_shorter_e 10 Incorrect_E_Len: exception;
smg_comms_shorter_e 11 Incorrect_D_Len: exception;
smg_comms_shorter_e 12
smg_comms_io_rsa_... 13 -- reads a full private key from specified file, in Hex format
smg_comms_io_rsa_... 14 -- one component per line, in order: n, e, d, p, q, u
smg_comms_io_rsa_... 15 -- NB: length of each component has to match *precisely* the expected length
smg_comms_shorter_e 16 -- e (public exponent) has the length given as argument
smg_comms_shorter_e 17 -- if E_Len < RSA_half'Length then e is stored 0-led in Key.e
smg_comms_shorter_e 18 -- if E_Len > RSA_half'Length then this will FAIL.
smg_comms_io_rsa_... 19 -- specifically, using Raw_Types:
smg_comms_shorter_e 20 -- n is RSA_len'Length octets (so *2 chars read);
smg_comms_shorter_e 21 -- p, q, u are RSA_half'Length (so *2 chars read);
smg_comms_shorter_e 22 -- e is RSA_half'Length but E_Len_Chars chars will be read;
smg_comms_shorter_e 23 -- d is RSA_len'Length but D_Len_Chars chars will be read;
smg_comms_shorter_e 24 procedure ReadRSAKey( Filename : in String;
smg_comms_shorter_e 25 E_Len_Chars : in Positive;
smg_comms_shorter_e 26 D_Len_Chars : in Positive;
smg_comms_shorter_e 27 Key : out RSA_OAEP.RSA_skey );
smg_comms_io_rsa_... 28
smg_comms_io_rsa_... 29 -- convert hexadecimal strings to octets representation
smg_comms_io_rsa_... 30 procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets );
smg_comms_io_rsa_... 31
smg_comms_io_rsa_... 32 end IO_RSA;