示例#1
0
    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.")
示例#2
0
    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.")
示例#3
0
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
示例#4
0
 def is_prime(cls, mpz):
     #return numtheory.miller_rabin(mpz)
     return number.isPrime(mpz)
示例#5
0
 def is_prime(cls, mpz):
     #return numtheory.miller_rabin(mpz)
     return number.isPrime(mpz)
示例#6
0
 def is_prime(cls, mpz):
     return number.isPrime(mpz)
示例#7
0
文件: algs.py 项目: vinilios/zeus
 def is_prime(cls, mpz):
     return number.isPrime(mpz)