Beispiel #1
0
 def __init__(self):
     self.private_key = random.randint(0, 2**100)
     self.salt = random.randint(0, 2**100)
     self.salt_bytes = self.salt.to_bytes(byteorder="big",
                                          length=get_num_byte_len(
                                              self.salt))
     self.u = random.randint(0, 2**128)
Beispiel #2
0
 def accept_salt_public_key_u(self, salt, server_public_key, u):
     self.salt = salt
     self.salt_bytes = self.salt.to_bytes(byteorder="big",
                                          length=get_num_byte_len(
                                              self.salt))
     self.server_public_key = server_public_key
     self.u = u
Beispiel #3
0
 def compute_hashes(self):
     self.s = pow(self.client_public_key * pow(self.v, self.u, self.n),
                  self.private_key, self.n)
     s_bytes = self.s.to_bytes(byteorder="big",
                               length=get_num_byte_len(self.s))
     hasher = hashlib.sha256()
     hasher.update(s_bytes)
     self.k = hasher.digest()
Beispiel #4
0
 def compute_hashes(self):
     self.salt_bytes = self.salt.to_bytes(byteorder="big",
                                          length=get_num_byte_len(
                                              self.salt))
     s_bytes = bytearray([0])
     hasher = hashlib.sha256()
     hasher.update(s_bytes)
     self.K = hasher.digest()
Beispiel #5
0
 def compute_hashes(self):
     hasher = hashlib.sha256()
     hasher.update(self.salt_bytes + self.password.encode("ascii"))
     x = int(hasher.digest().hex(), 16)
     self.s = pow(self.server_public_key, self.private_key + (self.u * x),
                  self.n)
     s_bytes = self.s.to_bytes(byteorder="big",
                               length=get_num_byte_len(self.s))
     hasher = hashlib.sha256()
     hasher.update(s_bytes)
     self.k = hasher.digest()
Beispiel #6
0
 def crack_password(self, path_to_dict):
     self.load_dict(path_to_dict)
     for w in self.valid_words:
         hasher_x = hashlib.sha256()
         hasher_x.update(self.salt_bytes + w.encode("ascii"))
         x = int(hasher_x.digest().hex(), 16)
         v = pow(self.g, x, self.n)
         s = pow(self.client_public_key * pow(v, self.u, self.n),
                 self.private_key, self.n)
         s_bytes = s.to_bytes(byteorder="big", length=get_num_byte_len(s))
         hasher_k = hashlib.sha256()
         hasher_k.update(s_bytes)
         k = hasher_k.digest()
         hasher_hmac = hashlib.sha256()
         hasher_hmac.update(k + self.salt_bytes)
         check_hmac = hasher_hmac.digest().hex()
         if check_hmac == self.client_hmac:
             print("Successfully cracked password. Password = {}".format(w))
             return
     raise Exception("Failed to crack password")