Exemple #1
0
    def compute_server_values(self,
                              username,
                              verifier,
                              byte_size=DEFAULT_SECRETSIZE):
        '''Calculates server values'''
        l = self.N.bit_length()

        self.b = obj_to_int(get_randombytes(byte_size))
        k = obj_to_int(compute_hash(self.N, compute_padding(self.g, l)))

        self.B = (k * verifier + pow(self.g, self.b, self.N)) % self.N
        return self.B
Exemple #2
0
    def compute_client_values(self, byte_size=DEFAULT_SECRETSIZE):
        '''
		Computes client's private and public values:
		a = random()
		A = g^a % N  
		'''
        self.a = obj_to_int(get_randombytes(byte_size))
        self.A = pow(self.g, self.a, self.N)
        return self.A
Exemple #3
0
    def compute_premaster_secret(self, salt, server_B):
        '''Calculates client premaster secret'''
        server_B = obj_to_int(server_B)
        l = self.N.bit_length()

        padded_client_A = compute_padding(self.A, l)
        padded_server_B = compute_padding(server_B, l)

        u = obj_to_int(compute_hash(padded_client_A, padded_server_B))
        x = self._compute_x(salt, self.username, self.password)

        padded_g = compute_padding(self.g, l)
        k = obj_to_int(compute_hash(self.N, padded_g))

        t1 = server_B - k * pow(self.g, x, self.N)
        t2 = self.a + u * x
        self.premaster_secret = pow(t1, t2, self.N)
        return self.premaster_secret
Exemple #4
0
    def compute_premaster_secret(self, salt, server_B):
        '''
		Calculates client premaster secret
        u = SHA1(PAD(A) | PAD(B))
        k = SHA1(N | PAD(g))
        x = SHA1(s | SHA1(I | ":" | P))
        <premaster secret> = (B - (k * g^x)) ^ (a + (u * x)) % N
		'''
        server_B = obj_to_int(server_B)
        l = self.N.bit_length()

        padded_client_A = compute_padding(self.A, l)
        padded_server_B = compute_padding(server_B, l)

        u = obj_to_int(compute_hash(padded_client_A, padded_server_B))
        x = self._compute_x(salt, self.username, self.password)

        padded_g = compute_padding(self.g, l)
        k = obj_to_int(compute_hash(self.N, padded_g))

        t1 = server_B - k * pow(self.g, x, self.N)
        t2 = self.a + u * x
        self.premaster_secret = pow(t1, t2, self.N)
        return self.premaster_secret
Exemple #5
0
    def compute_premaster_secret(self,
                                 username,
                                 salt,
                                 verifier,
                                 client_A,
                                 scs=DEFAULT_SECRETSIZE):
        '''Calculates server premaster secret'''
        l = self.N.bit_length()
        padded_client_A = compute_padding(client_A, l)
        padded_server_B = compute_padding(self.B, l)
        u = obj_to_int(compute_hash(padded_client_A, padded_server_B))

        self.premaster_secret = pow(client_A * pow(verifier, u, self.N),
                                    self.b, self.N)
        return self.premaster_secret