def generateKey(keySize): print('Generating prime p...') p = rabinMiller.generateLargePrime(keySize) print('Generating prime q...') q = rabinMiller.generateLargePrime(keySize) n = p * q print('Generating e that is relatively prime to (p - 1) * (q - 1)...') while True: e = random.randrange(2 ** (keySize - 1), 2 ** (keySize)) if cryptoMath.gcd(e, (p - 1) * (q - 1)) == 1: break print('Calculating d that is mod inverse of e...') d = cryptoMath.findModInverse(e, (p - 1) * (q - 1)) publicKey = (n, e) privateKey = (n, d) return (publicKey, privateKey)
def generateKey(keySize): print('Generating prime p...') p = rabinMiller.generateLargePrime(keySize) # select large prime number. e_1 = primitiveRoot(p) # one primitive root on modulo p. d = random.randrange(3, p) # private_key -> have to be greater than 2 for safety. e_2 = cryptoMath.findModInverse(pow(e_1, d, p), p) publicKey = (keySize, e_1, e_2, p) privateKey = (keySize, d) return publicKey, privateKey
def generateKey(keySize): print('Generating prime p...') p = rabinMiller.generateLargePrime(keySize) # select large prime number. e_1 = primitiveRoot(p) # one primitive root on modulo p. d = random.randrange( 3, p) # private_key -> have to be greater than 2 for safety. e_2 = cryptoMath.findModInverse(pow(e_1, d, p), p) publicKey = (keySize, e_1, e_2, p) privateKey = (keySize, d) return publicKey, privateKey