Fix overflow of int and add GenerateKeyPair