def validate_pk_params(self): # check primality of p if not number.isPrime(self.p): raise Exception("p is not prime.") # check length of p if not (number.size(self.p) >= 2048): raise Exception( "p of insufficient length. Should be 2048 bits or greater.") # check primality of q if not number.isPrime(self.q): raise Exception("q is not prime.") # check length of q if not (number.size(self.q) >= 256): raise Exception( "q of insufficient length. Should be 256 bits or greater.") if (pow(self.g, self.q, self.p) != 1): raise Exception("g does not generate subgroup of order q.") if not (1 < self.g < self.p - 1): raise Exception("g out of range.") if not (1 < self.y < self.p - 1): raise Exception("y out of range.") if (pow(self.y, self.q, self.p) != 1): raise Exception("g does not generate proper group.")
def validate_pk_params(self): # check primality of p if not number.isPrime(self.p): raise Exception("p is not prime.") # check length of p if not (number.size(self.p) >= 2048): raise Exception("p of insufficient length. Should be 2048 bits or greater.") # check primality of q if not number.isPrime(self.q): raise Exception("q is not prime.") # check length of q if not (number.size(self.q) >= 256): raise Exception("q of insufficient length. Should be 256 bits or greater.") if (pow(self.g,self.q,self.p)!=1): raise Exception("g does not generate subgroup of order q.") if not (1 < self.g < self.p-1): raise Exception("g out of range.") if not (1 < self.y < self.p-1): raise Exception("y out of range.") if (pow(self.y,self.q,self.p)!=1): raise Exception("g does not generate proper group.")
def RandomPrime(lower, upper): ''' Generates random prime number between bounds (inclusive) ''' #efficient up to around 10 decimal places if upper - lower <= 1: return None while True: c = random.randint(lower, upper) #candidate if (number.isPrime(c)): return c
def is_prime(cls, mpz): #return numtheory.miller_rabin(mpz) return number.isPrime(mpz)
def is_prime(cls, mpz): return number.isPrime(mpz)