def c_t_tls_hand_enc_cert_verify_msg(self, enc_alg, enc_key_len, msg_size, alg_option): # Public encrypt try: # extract information L().log(604, enc_alg, enc_key_len, msg_size) algorithm = EnumTrafor().to_value(enc_alg) key_len = EnumTrafor().to_value(enc_key_len) # read Database if enc_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_cert_verify_msg'], mode='ENCRYPTION', param_len=key_len, alg=algorithm, \ data_size=msg_size, description='t_tls_hand_enc_cert_verify_msg') else: # RSA: have to slice the message and encrypt each of those if msg_size > ((float(key_len) / 8) - 11): size_to_enc_in = ceil((float(key_len) / 8) - 11) else: size_to_enc_in = msg_size db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_cert_verify_msg'], exp=alg_option, mode='ENCRYPTION', keylen=key_len, \ alg=algorithm, data_size=size_to_enc_in, description='t_tls_hand_enc_cert_verify_msg') # RSA: have to slice the message and encrypt each of those nr_chuncks = math.ceil(msg_size / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_hand_enc_cert_verify_msg') return 0.001 except: logging.error("Error: Could not calculate the Value in 't_tls_hand_enc_cert_verify_msg'") return 0.000000001
def c_t_tls_hand_dec_client_keyex_msg(self, pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option): ''' time to decrypt the inner registration message -> So this is a private decryption with the sec module private key (after this was public encrypted) ''' try: # extract infos L().log(701, pub_dec_alg, pub_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(pub_dec_alg) al_mode = EnumTrafor().to_value(pub_dec_alg_option) key_len = EnumTrafor().to_value(pub_dec_keylen) # DB Lookup if pub_dec_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_dec_client_keyex_msg'], mode='DECRYPTION', \ param_len=key_len, alg=algorithm, data_size=size_to_dec, description='t_tls_hand_dec_client_keyex_msg') else: db_val = TimingDBMap().lookup_interpol(exp=al_mode, lib=self.library_tags['t_tls_hand_dec_client_keyex_msg'], mode='DECRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_tls_hand_dec_client_keyex_msg') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_dec_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_dec_client_keyex_msg'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option])) L().log(603, 't_tls_hand_dec_client_keyex_msg') return 0.01 # self.settings['t_tls_hand_dec_client_keyex_msg'] = 'ecuSW.app_lay.ecu_auth.SSMA_DECR_INNER_REG_MSG' except: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_dec_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_dec_client_keyex_msg'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option])) return 0.000000001
def c_t_ecu_auth_conf_msg_enc(self, size_to_enc, sym_enc_alg, sym_enc_keylen, sym_enc_alg_mode): ''' time to encrypt the conf. msg with the ecu key''' try: # extract infos L().log(703, sym_enc_alg, sym_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(sym_enc_alg) algo_mode = EnumTrafor().to_value(sym_enc_alg_mode) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=algo_mode, lib=self.library_tags['t_ecu_auth_conf_msg_enc'], mode='ENCRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_ecu_auth_conf_msg_enc') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_conf_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_conf_msg_enc'], size_to_enc, sym_enc_alg, sym_enc_keylen, sym_enc_alg_mode ])) L().log(603, 't_ecu_auth_conf_msg_enc') return 0.01 # self.settings['t_ecu_auth_reg_msg_outter_dec'] = 'ecuSW.app_lay.ecu_auth.SSMA_DECR_OUTTER_REG_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_conf_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_conf_msg_enc'], size_to_enc, sym_enc_alg, sym_enc_keylen, sym_enc_alg_mode ])) return 0.000000001
def c_t_str_auth_enc_grant_msg(self, sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode): ''' time to encrypt the grant message''' try: # extract infos L().log(706, sym_enc_alg, sym_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(sym_enc_alg) algo_mode = EnumTrafor().to_value(sym_enc_alg_mode) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=algo_mode, lib=self.library_tags['t_str_auth_enc_grant_msg'], mode='ENCRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_str_auth_enc_grant_msg') # return values if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_enc_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_enc_grant_msg'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) L().log(603, 't_str_auth_enc_grant_msg') return 0.01 # self.settings['t_str_auth_enc_grant_msg'] = 'ecuSW.app_lay.stream_auth.SSMA_STREAM_ENC_GRANT_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_enc_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_enc_grant_msg'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) return 0.000000001
def c_t_prf_for_key_legitimation(self, mac_alg, mac_keylen): ''' key generation with AES is a Random Function so same as a PRF''' try: # extract information algorithm = EnumTrafor().to_value(SymAuthMechEnum.AES) key_len = EnumTrafor().to_value(AuKeyLengthEnum.bit_192) # read Database db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_prf_for_key_legitimation'], mode='KEYGEN', keylen=key_len, alg=algorithm) # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_prf_for_key_legitimation') return 0.001 except: logging.error( "Error: Could not calculate the Value in 't_prf_for_key_legitimation'" ) return 0.000000001
def c_t_generate_mac(self, input_size, mac_alg, mac_keylen): ''' generation of the comparison hash is a AES CMAC operation''' try: # extract infos L().log(605, mac_alg, input_size) algorithm = EnumTrafor().to_value(mac_alg) key_len = EnumTrafor().to_value(mac_keylen) alg_mode = "CMAC" # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_generate_compare_mac'], keylen=key_len, mode='ENCRYPTION', alg=algorithm, alg_mode=alg_mode, data_size=input_size) # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_generate_mac') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.error( "Error: Could not calculate the Value in 't_generate_mac'") return 0.000000001 return 0
def c_t_key_exchange_decryption(self, msg_size, dec_alg, dec_key_len, alg_option): ''' Private decryption or alternatively symmetric encryption with master key''' try: # extract information L().log(604, dec_alg, dec_key_len, msg_size) algorithm = EnumTrafor().to_value(dec_alg) key_len = EnumTrafor().to_value(dec_key_len) alg_mode = EnumTrafor().to_value(alg_option) # Symmertic Encryption if isinstance(dec_alg, SymAuthMechEnum): db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_key_exchange_encryption'], mode='DECRYPTION', keylen=key_len, alg=algorithm, alg_mode=alg_mode, data_size=msg_size) else: # read Database if dec_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_key_exchange_decryption'], mode='DECRYPTION', param_len=key_len, alg=algorithm, data_size=msg_size) else: # RSA: have to slice the message and encrypt each of those if msg_size > ((float(key_len) / 8) - 11): size_to_enc_in = ceil((float(key_len) / 8) - 11) else: size_to_enc_in = msg_size db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_key_exchange_decryption'], exp=alg_option, mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_enc_in) # RSA: have to slice the message and encrypt each of those nr_chuncks = math.ceil(msg_size / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_key_exchange_decryption') return 0.001 except: logging.error( "Error: Could not calculate the Value in 't_key_exchange_decryption'" ) return 0.000000001
def c_t_ecu_auth_reg_msg_outter_dec(self, pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option): ''' time to decrypt the outter registration message -> Verify == Public Decrypt! ''' try: # extract infos L().log(702, pub_dec_alg, pub_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(pub_dec_alg) alg_opt = EnumTrafor().to_value(pub_dec_alg_option) key_len = EnumTrafor().to_value(pub_dec_keylen) # DB Lookup if pub_dec_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_outter_dec'], mode='VERIFY', param_len=key_len, \ alg=algorithm, data_size=size_to_dec, description='t_ecu_auth_reg_msg_outter_dec') if pub_dec_alg == AsymAuthMechEnum.RSA and self.library_tags[ 't_ecu_auth_reg_msg_outter_dec'] == "CyaSSL": if size_to_dec > ((float(key_len) / 8) - 11): size_to_dec_in = ceil((float(key_len) / 8) - 11) else: size_to_dec_in = size_to_dec db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_outter_dec'], exp=alg_opt, mode='ENCRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_dec_in, description='t_ecu_auth_reg_msg_outter_dec') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(size_to_dec / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks if pub_dec_alg == AsymAuthMechEnum.RSA and self.library_tags[ 't_ecu_auth_reg_msg_outter_dec'] in [ "Crypto_Lib_SW", "Crypto_Lib_HW" ]: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_outter_dec'], exp=alg_opt, mode='VERIFY', \ keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_ecu_auth_reg_msg_outter_dec') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_outter_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_outter_dec'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option ])) L().log(603, 't_ecu_auth_reg_msg_outter_dec') return 0.01 # self.settings['t_ecu_auth_reg_msg_outter_dec'] = 'ecuSW.app_lay.ecu_auth.SSMA_DECR_OUTTER_REG_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_outter_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_outter_dec'], pub_dec_alg, pub_dec_keylen, size_to_dec, pub_dec_alg_option ])) return 0.000000001
def _rsa_dec_output(self, input_size, key_length): ''' RSA: size after decryption Input: input_size float size before algorithm applied key_length AuKeyLengthEnum key length used for encryption Output: output_size float size after algorithm applied ''' nr_chuncks = math.ceil( input_size / (float(EnumTrafor().to_value(key_length) / 8) - 11)) if nr_chuncks <= 0: nr_chuncks = 1 return (EnumTrafor().to_value(key_length) / 8) * nr_chuncks
def _rsa_enc_output(self, input_size, key_length): ''' encryption = public encrypt when bigger than the keylength it is assumed that the message is chuncked input length per chunck is then keylen - 11 Input: input_size float size before algorithm applied key_length AuKeyLengthEnum key length used for encryption Output: output_size float size after algorithm applied ''' nr_chuncks = math.ceil( input_size / (float(EnumTrafor().to_value(key_length) / 8) - 11)) if nr_chuncks <= 0: nr_chuncks = 1 return (EnumTrafor().to_value(key_length) / 8) * nr_chuncks
def c_t_reg_msg_hash(self, size_to_hash, hash_mech): try: # extract infos L().log(605, hash_mech, size_to_hash) algorithm = EnumTrafor().to_value(hash_mech) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_hash'], mode='HASH', alg=algorithm, data_size=size_to_hash, description='t_reg_msg_hash') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_hash' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_hash'], size_to_hash, hash_mech ])) L().log(603, 't_reg_msg_hash') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_hash' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_hash'], size_to_hash, hash_mech ])) return 0.000000001
def c_t_normal_msg_enc(self, sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode=False): ''' time to encrypt a normal message''' try: # extract infos L().log(607, 't_normal_msg_enc', sym_enc_alg, sym_enc_keylen, size_to_enc) algorithm_mode = EnumTrafor().to_value(sym_enc_alg_mode) algorithm = EnumTrafor().to_value(sym_enc_alg) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_normal_msg_enc'], alg_mode=algorithm_mode, mode='ENCRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_normal_msg_enc') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_normal_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_normal_msg_enc'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) L().log(603, 't_normal_msg_enc') return 0.01 # self.settings['t_normal_msg_enc'] = 'ecuSW.comm_mod.authorizer.SCCM_STREAM_ENC_SIMP_MSG_SESS_KEY' except: logging.warn( "Error: Could not find in DB the Value in 't_normal_msg_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_normal_msg_enc'], sym_enc_alg, sym_enc_keylen, size_to_enc, sym_enc_alg_mode ])) return 0.000000001
def c_t_conf_msg_dec_time(self, sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode): ''' time to decrypt the confirmation message''' try: # extract infos L().log(607, 't_conf_msg_dec_time', sym_dec_alg, sym_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(sym_dec_alg) algorithm_mode = EnumTrafor().to_value(sym_dec_alg_mode) key_len = EnumTrafor().to_value(sym_dec_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_conf_msg_dec_time'], alg_mode=algorithm_mode, mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_conf_msg_dec_time') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_conf_msg_dec_time' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_conf_msg_dec_time'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) L().log(603, 't_conf_msg_dec_time') return 0.01 # self.settings['t_conf_msg_dec_time'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_DEC_CONF_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_conf_msg_dec_time' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_conf_msg_dec_time'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) return 0.000000001
def c_t_grant_msg_stream_dec(self, sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode): ''' time to decrypt the grant message ''' try: # extract infos L().log(610, 't_grant_msg_stream_dec', sym_dec_alg, sym_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(sym_dec_alg) key_len = EnumTrafor().to_value(sym_dec_keylen) alg_modee = EnumTrafor().to_value(sym_dec_alg_mode) # DB Lookup db_val = TimingDBMap().lookup_interpol( alg_mode=alg_modee, lib=self.library_tags['t_grant_msg_stream_dec'], mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_grant_msg_stream_dec') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_grant_msg_stream_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_grant_msg_stream_dec'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) L().log(603, 't_grant_msg_stream_dec') return 0.01 # self.settings['t_grant_msg_stream_dec'] = 'ecuSW.comm_mod.authorizer.SCCM_STREAM_DEC_GRANT_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_grant_msg_stream_dec' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_grant_msg_stream_dec'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_mode ])) return 0.000000001
def c_t_tls_record_dec(self, msg_size, enc_alg, enc_key_len, enc_alg_mode): # Decrypt the content with symmetric algorithm try: # extract infos algorithm = EnumTrafor().to_value(enc_alg) algorithm_mode = EnumTrafor().to_value(enc_alg_mode) key_len = EnumTrafor().to_value(enc_key_len) # DB Lookup db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_record_dec'], alg_mode=algorithm_mode, mode='DECRYPTION', keylen=key_len, alg=algorithm, data_size=msg_size, description='t_tls_record_dec') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_record_dec') return 0.01 except: logging.error("Error: Could not calculate the Value in 't_tls_record_dec'") return 0.000000001
def _ecc_sign_output(self, input_size, key_length): ''' ECDSA - used by both cryptolib and CyaSSL -> Signs a hash Input: input_size float size before algorithm applied key_length AuKeyLengthEnum key length used for encryption Output: output_size float size after algorithm applied ''' key_len = EnumTrafor().to_value(key_length) ecc_signature_size = 2 * (key_len / 8) + 6 return ecc_signature_size
def c_t_tls_record_mac_rec_side(self, mac_size, mac_alg, mac_key_len): # Create verification hash try: # extract infos L().log(605, mac_alg, mac_size) algorithm = EnumTrafor().to_value(mac_alg) key_len = EnumTrafor().to_value(mac_key_len) alg_mode = "CMAC" # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=alg_mode, lib=self.library_tags['t_tls_record_mac_rec_side'], keylen=key_len, mode='ENCRYPTION', alg=algorithm, data_size=mac_size, description='t_tls_record_mac_rec_side') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_record_mac_rec_side') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.error("Error: Could not calculate the Value in 't_tls_record_mac_rec_side'") return 0.000000001 return 0
def c_t_reg_msg_sym_keygen(self, sym_enc_alg, sym_enc_keylen): ''''time to create the symmetric ECU Key''' # self.settings['t_reg_msg_sym_keygen'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ENC_REG_MSG_CREATE_SYM_KEY' try: # extract information L().log(604, sym_enc_alg, sym_enc_keylen, 0) algorithm = EnumTrafor().to_value(sym_enc_alg) key_len = EnumTrafor().to_value(sym_enc_keylen) # read Database db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_sym_keygen'], mode='KEYGEN', keylen=key_len, alg=algorithm, description='t_reg_msg_sym_keygen') # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_sym_keygen' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_sym_keygen'], sym_enc_alg, sym_enc_keylen ])) L().log(603, 't_reg_msg_sym_keygen') return 0.001 except: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_sym_keygen' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_sym_keygen'], sym_enc_alg, sym_enc_keylen ])) return 0.000000001
def c_t_str_auth_keygen_grant_msg(self, sym_enc_alg, sym_enc_keylen): ''' time to generate a session key ''' try: # extract infos L().log(707, sym_enc_alg, sym_enc_keylen) algorithm = EnumTrafor().to_value(sym_enc_alg) key_len = EnumTrafor().to_value(sym_enc_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_str_auth_keygen_grant_msg'], mode='KEYGEN', keylen=key_len, alg=algorithm, description='t_str_auth_keygen_grant_msg') # return values if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_keygen_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_keygen_grant_msg'], sym_enc_alg, sym_enc_keylen ])) L().log(603, 't_str_auth_keygen_grant_msg') return 0.01 # self.settings['t_str_auth_keygen_grant_msg'] = 'ecuSW.app_lay.stream_auth.SSMA_SESS_KEYGEN_GRANT_MSG' except: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_keygen_grant_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_keygen_grant_msg'], sym_enc_alg, sym_enc_keylen ])) return 0.000000001
def c_t_str_auth_decr_req_msg(self, sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_option): ''' time to decrypt the request message with the ecu key''' try: # extract infos L().log(704, sym_dec_alg, sym_dec_keylen, size_to_dec) algorithm = EnumTrafor().to_value(sym_dec_alg) alg_option = EnumTrafor().to_value(sym_dec_alg_option) key_len = EnumTrafor().to_value(sym_dec_keylen) # DB Lookup db_val = TimingDBMap().lookup_interpol(alg_mode=alg_option, lib=self.library_tags['t_str_auth_decr_req_msg'], mode='DECRYPTION', \ keylen=key_len, alg=algorithm, data_size=size_to_dec, description='t_str_auth_decr_req_msg') # return values if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_decr_req_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_decr_req_msg'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_option ])) L().log(603, 't_str_auth_decr_req_msg') return 0.01 # self.settings['t_str_auth_decr_req_msg'] = 'ecuSW.app_lay.stream_auth.SSMA_STREAM_REQ_INI_DECR' except: logging.warn( "Error: Could not find in DB the Value in 't_str_auth_decr_req_msg' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_str_auth_decr_req_msg'], sym_dec_alg, sym_dec_keylen, size_to_dec, sym_dec_alg_option ])) return 0.000000001
def c_t_tls_hand_enc_client_keyex_msg(self, pub_enc_alg, pub_enc_keylen, size_to_enc, pub_enc_alg_option): ''''enrypt the client keyexchange message -> public encryption ''' try: # extract information L().log(604, pub_enc_alg, pub_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(pub_enc_alg) key_len = EnumTrafor().to_value(pub_enc_keylen) # read Database if pub_enc_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_client_keyex_msg'], mode='ENCRYPTION', param_len=key_len, alg=algorithm, data_size=size_to_enc, description='t_tls_hand_enc_client_keyex_msg') else: if size_to_enc > ((float(key_len) / 8) - 11): size_to_enc_in = ceil((float(key_len) / 8) - 11) else: size_to_enc_in = size_to_enc db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_enc_client_keyex_msg'], exp=pub_enc_alg_option, mode='ENCRYPTION', keylen=key_len, alg=algorithm, data_size=size_to_enc_in, description='t_tls_hand_enc_client_keyex_msg') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(size_to_enc / ((float(key_len) / 8) - 11)) db_val = db_val * nr_chuncks # return result if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_enc_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_enc_client_keyex_msg'], size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option])) L().log(603, 't_tls_hand_enc_client_keyex_msg') return 0.001 # self.settings['t_tls_hand_enc_client_keyex_msg'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ENC_REG_MSG_INNER' except: logging.warn("Error: Could not find in DB the Value in 't_tls_hand_enc_client_keyex_msg' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_tls_hand_enc_client_keyex_msg'], size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option])) return 0.000000001
def c_t_tls_hand_send_client_finish_hash(self, input_size, hash_alg): try: # extract infos L().log(605, hash_alg, input_size) algorithm = EnumTrafor().to_value(hash_alg) # DB Lookup db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_tls_hand_send_client_finish_hash'], mode='HASH', alg=algorithm, data_size=input_size, description='t_tls_hand_send_client_finish_hash') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: L().log(603, 't_tls_hand_send_client_finish_hash') return 0.01 # self.settings['t_reg_msg_hash'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_HASH_REG_MSG' except: logging.error("Error: Could not calculate the Value in 't_tls_record_mac_rec_side'") return 0.000000001 return 0
def c_t_ecu_auth_reg_msg_create_comp_hash(self, size_to_hash, hash_mech): ''' time it takes to create the hash for the comparision in the registration message ''' try: # extract infos L().log(605, hash_mech, size_to_hash) algorithm = EnumTrafor().to_value(hash_mech) # DB Lookup db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_create_comp_hash'], mode='HASH', alg=algorithm, data_size=size_to_hash, description='t_ecu_auth_reg_msg_create_comp_hash') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_create_comp_hash' use 0.0...01\nUsed input: %s" % str([ self. library_tags['t_ecu_auth_reg_msg_create_comp_hash'], size_to_hash, hash_mech ])) L().log(603, 't_reg_msg_hash') return 0.01 except: logging.warn( "Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_create_comp_hash' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_create_comp_hash'], size_to_hash, hash_mech ])) return 0.000000001
def c_t_reg_msg_outter_enc(self, size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option): ''' time to encrypt the outter part of the reg. msg. i.e. the hashed inner part -> sign procedure ''' try: # extract infos L().log(606, pub_enc_alg, pub_enc_keylen, size_to_enc) algorithm = EnumTrafor().to_value(pub_enc_alg) key_len = EnumTrafor().to_value(pub_enc_keylen) # DB Lookup if pub_enc_alg == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_outter_enc'], mode='SIGN', param_len=key_len, alg=algorithm, data_size=size_to_enc, description='t_reg_msg_outter_enc') if pub_enc_alg == AsymAuthMechEnum.RSA and self.library_tags[ 't_reg_msg_outter_enc'] == "CyaSSL": if size_to_enc > (float(key_len) / 8): size_to_enc_in = ceil(float(key_len) / 8) else: size_to_enc_in = size_to_enc db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_outter_enc'], mode='DECRYPTION', exp=pub_enc_alg_option, keylen=key_len, alg=algorithm, data_size=size_to_enc_in, description='t_reg_msg_outter_enc') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(size_to_enc / (float(key_len) / 8)) db_val = db_val * nr_chuncks if pub_enc_alg == AsymAuthMechEnum.RSA and self.library_tags[ 't_reg_msg_outter_enc'] in [ "Crypto_Lib_SW", "Crypto_Lib_HW" ]: db_val = TimingDBMap().lookup_interpol( lib=self.library_tags['t_reg_msg_outter_enc'], mode='SIGN', exp=pub_enc_alg_option, keylen=key_len, alg=algorithm, data_size=size_to_enc, description='t_reg_msg_outter_enc') # return value if db_val: return G().val_log_info(db_val, 602, db_val) else: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_outter_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_outter_enc'], size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option ])) L().log(603, 't_reg_msg_outter_enc') return 0.01 # self.settings['t_reg_msg_outter_enc'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ENC_REG_MSG_OUTTER' except: logging.warn( "Error: Could not find in DB the Value in 't_reg_msg_outter_enc' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_reg_msg_outter_enc'], size_to_enc, pub_enc_alg, pub_enc_keylen, pub_enc_alg_option ])) return 0.000000001
def c_t_adv_msg_secmodcert_enc(self, cert_hash_mech, cert_enc_mech, cert_enc_keylen, \ cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn, cert_size): ''' time to validate the certificates of the security module ''' try: # extract parameters db_value = False algorithm = EnumTrafor().to_value(cert_enc_mech) hash_algorithm = EnumTrafor().to_value(cert_hash_mech) key_length = EnumTrafor().to_value(cert_enc_keylen) # logging L().log(601, cert_enc_mech, cert_enc_keylen, cert_size_hashtosign, cert_ca_len) # CrypLi RSA: Verify = Time of hash creation + time to encrypt hash / CyaSSL & CrypLi ECC: Verify operation if cert_enc_mech == AsymAuthMechEnum.ECC: db_value = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='VERIFY', param_len=key_length, alg=algorithm, data_size=cert_size_hashtosign, description='t_adv_msg_secmodcert_enc') if self.library_tags['t_adv_msg_secmodcert_enc'] in [ "Crypto_Lib_SW", "Crypto_Lib_HW" ] and cert_enc_mech == AsymAuthMechEnum.RSA: # 1. create hash of certificate content db_val_1 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='HASH', alg=hash_algorithm, data_size=cert_size, description='t_adv_msg_secmodcert_enc') # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt) if cert_size_hashsigned > ((key_length / 8) - 11): cert_size_hashsigned_in = ceil((float(key_length) / 8) - 11) else: cert_size_hashsigned_in = cert_size_hashsigned db_val_2 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='VERIFY', keylen=key_length, alg=algorithm, data_size=cert_size_hashsigned_in, exp=cert_alg_optn, description='t_adv_msg_secmodcert_enc') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(cert_size_hashsigned / ((float(key_length) / 8) - 11)) db_val_2 = db_val_2 * nr_chuncks # 3. create hash of digital signature db_val_3 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='HASH', alg=hash_algorithm, data_size=cert_size_hashtosign, description='t_adv_msg_secmodcert_enc') db_value = db_val_1 + db_val_2 + db_val_3 if self.library_tags[ 't_adv_msg_secmodcert_enc'] == "CyaSSL" and cert_enc_mech == AsymAuthMechEnum.RSA: # 1. create hash of certificate content db_val_1 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='HASH', alg=hash_algorithm, data_size=cert_size, description='t_adv_msg_secmodcert_enc') # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt) if cert_size_hashsigned > ((key_length / 8) - 11): cert_size_hashsigned_in = ceil((float(key_length) / 8) - 11) else: cert_size_hashsigned_in = cert_size_hashsigned db_val_2 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='ENCRYPTION', keylen=key_length, alg=algorithm, data_size=cert_size_hashsigned_in, exp=cert_alg_optn, description='t_adv_msg_secmodcert_enc') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(cert_size_hashsigned / ((float(key_length) / 8) - 11)) db_val_2 = db_val_2 * nr_chuncks # 3. create hash of digital signature db_val_3 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_adv_msg_secmodcert_enc'], mode='HASH', alg=hash_algorithm, data_size=cert_size_hashtosign, description='t_adv_msg_secmodcert_enc') db_value = db_val_1 + db_val_2 + db_val_3 # Set value if db_value: L().log(602, db_value) else: logging.warn("Error: Could not find in DB the Value in 't_adv_msg_secmodcert_enc' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_adv_msg_secmodcert_enc'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \ cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn])) return G().val_log_info(0.0000000001, 603, 't_adv_msg_secmodcert_enc') # repeat cert_ca_len times abs_time = cert_ca_len * db_value return abs_time # self.settings['t_adv_msg_secmodcert_enc'] = 'ecuSW.comm_mod.authenticator.SCCM_ECU_ADV_SEC_MOD_CERT_VAL' except: logging.warn("Error: Could not find in DB the Value in 't_adv_msg_secmodcert_enc' use 0.0...01\nUsed input: %s" % str([self.library_tags['t_adv_msg_secmodcert_enc'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \ cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn])) return 0.000000001
def c_t_ecu_auth_reg_msg_validate_cert(self, cert_hash_mech, cert_enc_mech, cert_enc_keylen, \ cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn, cert_size): ''' time to validate the ecus certificate, hash to sign is the size of the Certificate to be signed ''' try: # extract infos L().log(700, cert_enc_mech, cert_enc_keylen, cert_size_hashtosign, cert_ca_len) db_val = False algorithm = EnumTrafor().to_value(cert_enc_mech) hash_alg = EnumTrafor().to_value(cert_hash_mech) key_len = EnumTrafor().to_value(cert_enc_keylen) # CrypLi RSA: Verify = Time of hash creation + time to encrypt hash / CyaSSL & CrypLi ECC: Verify operation if cert_enc_mech == AsymAuthMechEnum.ECC: db_val = TimingDBMap().lookup_interpol(lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='VERIFY', \ param_len=key_len, alg=algorithm, data_size=cert_size_hashtosign, description='t_ecu_auth_reg_msg_validate_cert') if self.library_tags['t_ecu_auth_reg_msg_validate_cert'] in [ "Crypto_Lib_SW", "Crypto_Lib_HW" ] and cert_enc_mech == AsymAuthMechEnum.RSA: # RSA SIGN = DECRYPTION, VERIFY= ENCRYPTION # 1. create hash of certificate content db_val_1 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='HASH', alg=hash_alg, data_size=cert_size, description='t_ecu_auth_reg_msg_validate_cert') # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt) if cert_size_hashsigned > ((float(key_len) / 8) - 11): cert_size_hashsigned_in = ceil((float(key_len) / 8) - 11) else: cert_size_hashsigned_in = cert_size_hashsigned db_val_2 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='VERIFY', keylen=key_len, alg=algorithm, data_size=cert_size_hashsigned_in, exp=cert_alg_optn, description='t_ecu_auth_reg_msg_validate_cert') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(cert_size_hashsigned / ((float(key_len) / 8) - 11)) db_val_2 = db_val_2 * nr_chuncks # 3. create hash of digital signature db_val_3 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='HASH', alg=hash_alg, data_size=cert_size_hashtosign, description='t_ecu_auth_reg_msg_validate_cert') db_val = db_val_1 + db_val_2 + db_val_3 if self.library_tags[ 't_ecu_auth_reg_msg_validate_cert'] == "CyaSSL" and cert_enc_mech == AsymAuthMechEnum.RSA: # 1. create hash of certificate content db_val_1 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='HASH', alg=hash_alg, data_size=cert_size, description='t_ecu_auth_reg_msg_validate_cert') # 2. decrypt digital signature (signed hash size) using public key of certificate (public key operation -> similar to public encrypt) if cert_size_hashsigned > ((float(key_len) / 8) - 11): cert_size_hashsigned_in = ceil((float(key_len) / 8) - 11) else: cert_size_hashsigned_in = cert_size_hashsigned db_val_2 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='ENCRYPTION', keylen=key_len, alg=algorithm, data_size=cert_size_hashsigned_in, exp=cert_alg_optn, description='t_ecu_auth_reg_msg_validate_cert') # in case of RSA have to slice the message and encrypt each of those nr_chuncks = math.ceil(cert_size_hashsigned / ((float(key_len) / 8) - 11)) db_val_2 = db_val_2 * nr_chuncks # 3. create hash of digital signature db_val_3 = TimingDBMap().lookup_interpol( lib=self.library_tags['t_ecu_auth_reg_msg_validate_cert'], mode='HASH', alg=hash_alg, data_size=cert_size_hashtosign, description='t_ecu_auth_reg_msg_validate_cert') db_val = db_val_1 + db_val_2 + db_val_3 # return value if db_val: L().log(602, db_val) else: logging.warn("Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_validate_cert' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_validate_cert'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \ cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn])) L().log(603, 't_ecu_auth_reg_msg_validate_cert') return 0.0000000001 abs_time = cert_ca_len * db_val # repeat cert_ca_len times return abs_time # self.settings['t_ecu_auth_reg_msg_validate_cert'] = 'ecuSW.app_lay.ecu_auth.SSMA_VALID_CERT_REG_MSG' except: logging.warn("Error: Could not find in DB the Value in 't_ecu_auth_reg_msg_validate_cert' use 0.0...01\nUsed input: %s" % str([ self.library_tags['t_ecu_auth_reg_msg_validate_cert'], cert_hash_mech, cert_enc_mech, cert_enc_keylen, \ cert_ca_len, cert_size_hashtosign, cert_size_hashsigned, cert_alg_optn])) return 0.000000001