Add key generation function