Merged changes to keypair operations from upstream.