Esempio n. 1
0
    def verify_lrs_signature(self, client_msg, client_sig):
        """Verifies whether the LRS signature is valid."""

        # modify copy of stp_array to prevent duplicate voting
        stp_array = list(self.stp_array)
        stp_array.append(msg_hash(client_msg, sha1))

        return lrs.verify(client_msg, stp_array, *client_sig, g=self.generator)
Esempio n. 2
0
    def lrs_sign(self, msg):
        """Sign for LRS."""
        ltp_array = sendrecv(self.server_addr, [Constants.GET_LTP_ARRAY])
        ltp_idx = ltp_array.index(self.pub_key)

        # modify stp_array to prevent duplicate voting
        ltp_array.append(msg_hash(msg, sha1))

        return lrs.sign(msg, self.pri_key, ltp_idx, ltp_array)
Esempio n. 3
0
    def lrs_sign(self, msg):
        """Sign for LRS."""
        generator = sendrecv(self.server_addr, [Constants.GET_GENERATOR])
        stp_array = sendrecv(self.server_addr, [Constants.GET_STP_ARRAY])
        stp = powm(generator, self.pri_key)
        stp_idx = stp_array.index(stp)

        # modify stp_array to prevent duplicate voting
        stp_array.append(msg_hash(msg, sha1))

        return lrs.sign(msg, self.pri_key, stp_idx, stp_array, g=generator)
Esempio n. 4
0
    def sign(self, msg, generator):
        """Sign with ElGamal signature."""
        r, s = 0, 0

        while s == 0:
            k = randkeyRP(1, Constants.P - 2)
            r = powm(generator, k)
            s = (msg_hash(msg, sha1) - self.pri_key * r) * modinv(
                k, Constants.P - 1)
            s %= Constants.P - 1

        return (r, s)
Esempio n. 5
0
    def verify_signature(self, msg, stp, sig):
        """Verifies signature in message posting.

		msg: The message to verify
		stp: The public key of the user
		sig: The signature

		Returns whether the signature is valid or not.
		"""
        r, s = sig
        u = powm(self.generator, msg_hash(msg, sha1))
        v = (powm(stp, r) * powm(r, s)) % Constants.P
        return u == v
Esempio n. 6
0
	def verify_lrs_signature(self, client_msg, client_sig):
		# modify copy of ltp_array to prevent duplicate voting
		ltp_array = list(self.ltp_list.keys())
		ltp_array.append(msg_hash(client_msg, sha1))

		return lrs.verify(client_msg, ltp_array, *client_sig)