def __init__(self, primes, e, blind=True, rnd=default_crypto_random): self.primes = primes self.n = primitives.product(*primes) self.e = e self.bit_size = primitives.integer_bit_size(self.n) self.byte_size = primitives.integer_byte_size(self.n) self.exponents = [] for prime in primes: exponent, a, b = primitives.bezout(e, prime-1) assert b == 1 if exponent < 0: exponent += prime-1 self.exponents.append(exponent) self.crts = [1] R = primes[0] for prime in primes[1:]: crt, a, b = primitives.bezout(R, prime) assert b == 1 R *= prime self.crts.append(crt) public = RsaPublicKey(self.n, self.e) if blind: while True: blind_factor = rnd.getrandbits(self.bit_size-1) self.blind = public.rsaep(blind_factor) u, v, gcd = primitives.bezout(blind_factor, self.n) if gcd == 1: self.blind_inv = u if u > 0 else u + self.n assert (blind_factor * self.blind_inv) % self.n == 1 break else: self.blind = None self.blind_inv = None
def __init__(self, primes, e, blind=True, rnd=random.SystemRandom): self.primes = primes self.n = primitives.product(*primes) self.e = e self.bit_size = primitives.integer_bit_size(self.n) self.byte_size = primitives.integer_byte_size(self.n) self.exponents = [] for prime in primes: exponent, a, b = primitives.bezout(e, prime - 1) assert b == 1 if exponent < 0: exponent += prime - 1 self.exponents.append(exponent) self.crts = [1] R = primes[0] for prime in primes[1:]: crt, a, b = primitives.bezout(R, prime) assert b == 1 R *= prime self.crts.append(crt) public = RsaPublicKey(self.n, self.e) if blind: while True: blind_factor = rnd().getrandbits(self.bit_size - 1) self.blind = public.rsaep(blind_factor) u, v, gcd = primitives.bezout(blind_factor, self.n) if gcd == 1: self.blind_inv = u if u > 0 else u + self.n assert (blind_factor * self.blind_inv) % self.n == 1 break else: self.blind = None self.blind_inv = None
def __init__(self, n, e): self.n = n self.e = e self.bit_size = primitives.integer_bit_size(n) self.byte_size = primitives.integer_byte_size(n)
def __init__(self, n, d): self.n = n self.d = d self.bit_size = primitives.integer_bit_size(n) self.byte_size = primitives.integer_byte_size(n)