-- reading a RSA key pair from a file -- NB: this is for TESTING purposes only, NOT a production IO package! -- S.MG, 2018 with Raw_Types; with RSA_OAEP; package IO_RSA is Incorrect_E_Len: exception; Incorrect_D_Len: exception; -- reads a full private key from specified file, in Hex format -- one component per line, in order: n, e, d, p, q, u -- NB: length of each component has to match *precisely* the expected length -- e (public exponent) has the length given as argument -- if E_Len < RSA_half'Length then e is stored 0-led in Key.e -- if E_Len > RSA_half'Length then this will FAIL. -- specifically, using Raw_Types: -- n is RSA_len'Length octets (so *2 chars read); -- p, q, u are RSA_half'Length (so *2 chars read); -- e is RSA_half'Length but E_Len_Chars chars will be read; -- d is RSA_len'Length but D_Len_Chars chars will be read; procedure ReadRSAKey( Filename : in String; E_Len_Chars : in Positive; D_Len_Chars : in Positive; Key : out RSA_OAEP.RSA_skey ); -- convert hexadecimal strings to octets representation procedure Hex2Octets( Hex: in String; O: out Raw_Types.Octets ); end IO_RSA;