def ElGamalGenerate(): """ Generate ElGamal KeyPair """ x = random().randint(2, elgamal_p) y = pow(elgamal_g, x, elgamal_p) return ElGamalKey(y, x)
def serialize(self, priv=False): if priv and not self.has_private(): raise ValueError('No private key material in this Destination') data = bytes() if self.cert.type == CertificateType.KEY: encpub = self.enckey.get_pubkey() sigpub = self.sigkey.get_pubkey() enc_end = min(256, self.cert.enctype.pubkey_len) sig_start = max(256, 384-self.cert.sigtype.pubkey_len) if len(self.padding) == 0: # Generate random padding pad_len = sig_start - enc_end # Wrap with int() for Py2 self.padding = int(random().getrandbits(pad_len*8)).to_bytes( pad_len, 'big') data += encpub[:enc_end] data += self.padding data += sigpub[:384-sig_start] data += self.cert.serialize() elif self.cert.type != CertificateType.MULTI: data += self.enckey.get_pubkey() data += self.sigkey.get_pubkey() data += self.cert.serialize() else: raise NotImplementedError('Multiple certs not yet supported') if priv: data += self.enckey.get_privkey() data += self.sigkey.get_privkey() self._log.debug('serialize len=%d' % len(data)) return data
def _generate(): """Generate a DSA key pair. This needs an audit. """ x = random().randint(1, 2 ** 160) y = pow(dsa_g, x, dsa_p) return DSAKey._construct(y, x)
def _generate(): """Generate an ElGamal key pair. This needs an audit. """ x = random().randint(2, elgamal_p) y = pow(elgamal_g, x, elgamal_p) return ElGamalKey._construct(y, x)
def _generate(): """Generate a DSA key pair. This needs an audit. """ x = random().randint(1, 2**160) y = pow(dsa_g, x, dsa_p) return DSAKey._construct(y, x)
def DSAGenerate(): """ Generate DSA KeyPair this needs an audit """ x = random().randint(1, 2 ** 160) y = pow(dsa_g, x, dsa_p) return DSAKey(y, x)
def DSA_SHA1_SIGN(key, data, doublehash=True): """ generate DSA-SHA1 signature """ if key.has_private(): k = random().randint(1, key.q - 1) if doublehash: data = sha1(data) R, S = key.sign(data, k) return int(R).to_bytes(20,'big') + int(S).to_bytes(20,'big') else: raise I2CPException('No Private Key')
def _sign(self, data): """Generate DSA-SHA1 signature.""" k = random().randint(1, self.key.q - 1) data = sha1(data) R, S = self.key.sign(data, k) return int(R).to_bytes(20, 'big') + int(S).to_bytes(20, 'big')