def to_string(self): # VerifyingKey.from_string(vk.to_string()) == vk as long as the # curves are the same: the curve itself is not included in the # serialized form order = self.pubkey.order x_str = number_to_string(self.pubkey.point.x(), order) y_str = number_to_string(self.pubkey.point.y(), order) return x_str + y_str
def to_der(self): order = self.pubkey.order x_str = number_to_string(self.pubkey.point.x(), order) y_str = number_to_string(self.pubkey.point.y(), order) point_str = "\x00\x04" + x_str + y_str return der.encode_sequence(der.encode_sequence(encoded_oid_ecPublicKey, self.curve.encoded_oid), der.encode_bitstring(point_str))
def list_network_conf_files(self): ''' Builds a list of tuples with configuration files for wpa_supplicant or other strategies, that have been stored due to previous connections. The structure of the tuple is (autonumeric, dir, filename) ''' from conf import Conf import os, logging, util logger = logging.getLogger(Conf.LOGGER_NAME) network_index = 1 stored_networks = list() networks_dir = self.conf_files[Conf.PATH_NETWORKS_DIR] if Conf.DEBUG_MODE: logger.info("Scanning " + networks_dir) #candidate_lists will be a lists of lists because it returns one list per subdirectory to walk candidate_lists = [conf_file for root,dirs,conf_file in os.walk(networks_dir)] not_ser = lambda x: not util.is_net_serialization_filename(x) #traverse all lists in lists return all files in the hierarchy for clist in candidate_lists: for conf_file in filter(not_ser, clist): order = util.number_to_string(network_index,2) stored_networks.append((order, networks_dir, conf_file)) network_index += 1 return stored_networks
def generate_k(order, secexp, hash_func, data): ''' order - order of the DSA generator used in the signature secexp - secure exponent (private key) in numeric form hash_func - reference to the same hash function used for generating hash data - hash in binary form of the signing data ''' qlen = bit_length(order) holen = hash_func().digest_size rolen = (qlen + 7) / 8 bx = number_to_string(secexp, order) + bits2octets(data, order) # Step B v = b('\x01') * holen # Step C k = b('\x00') * holen # Step D k = hmac.new(k, v + b('\x00') + bx, hash_func).digest() # Step E v = hmac.new(k, v, hash_func).digest() # Step F k = hmac.new(k, v + b('\x01') + bx, hash_func).digest() # Step G v = hmac.new(k, v, hash_func).digest() # Step H while True: # Step H1 t = b('') # Step H2 while len(t) < rolen: v = hmac.new(k, v, hash_func).digest() t += v # Step H3 secret = bits2int(t, qlen) if secret >= 1 and secret < order: return secret k = hmac.new(k, v + b('\x00'), hash_func).digest() v = hmac.new(k, v, hash_func).digest()
def to_string(self): secexp = self.privkey.secret_multiplier s = number_to_string(secexp, self.privkey.order) return s
def to_string_just_y_point(self): order = self.pubkey.order y_str = number_to_string(self.pubkey.point.y(), order) return y_str
def to_string_just_x_point(self): order = self.pubkey.order x_str = number_to_string(self.pubkey.point.x(), order) return x_str
def generate_k(order, secexp, hash_func, data): ''' order - order of the DSA generator used in the signature secexp - secure exponent (private key) in numeric form hash_func - reference to the same hash function used for generating hash data - hash in binary form of the signing data ''' qlen = bit_length(order) holen = hash_func().digest_size rolen = (qlen + 7) / 8 bx = number_to_string(secexp, order) + bits2octets(data, order) # debug(hex(order), 'input - `order`') # debug(data, 'input - `data`') # debug(hex(secexp), 'input - `secexp`') # debug(qlen, 'setup - `qlen`') # debug(holen, 'setup - `holen`') # debug(rolen, 'setup - `rolen`') # debug(bx, 'setup - `bx`') # Step B v = b('\x01') * holen # Step C k = b('\x00') * holen # Step D k = hmac.new(k, v + b('\x00') + bx, hash_func).digest() # debug(k, 'Step d - `k`') # Step E v = hmac.new(k, v, hash_func).digest() # debug(v, 'Step e - `v`') # Step F k = hmac.new(k, v + b('\x01') + bx, hash_func).digest() # debug(k, 'Step f - `k`') # Step G v = hmac.new(k, v, hash_func).digest() # debug(v, 'Step g - `v`') # Step H while True: # Step H1 t = b('') # Step H2 while len(t) < rolen: v = hmac.new(k, v, hash_func).digest() t += v # debug(t, 'Step h.2.END - `t`') # Step H3 secret = bits2int(t, qlen) # debug(hex(secret), 'Step h.3.a - secret (`k`)') if secret >= 1 and secret < order: return secret k = hmac.new(k, v + b('\x00'), hash_func).digest() # debug(k, 'Step h.3.b - `k`') v = hmac.new(k, v, hash_func).digest()