key_free(private); BN_clear_free(challenge);
try_rsa_authentication(const char *authfile){	BIGNUM *challenge;	Key *public;	Key *private;	char *passphrase, *comment;	int type, i;	int plen, clen;	/* Try to load identification for the authentication key. */	public = key_new(KEY_RSA1);	if (!load_public_key(authfile, public, &comment)) {		key_free(public);		/* Could not load it.  Fail. */		return 0;	}	debug("Trying RSA authentication with key '%.100s'", comment);	/* Tell the server that we are willing to authenticate using this key. */	packet_start(SSH_CMSG_AUTH_RSA);	packet_put_bignum(public->rsa->n);	packet_send();	packet_write_wait();	/* We no longer need the public key. */	key_free(public);	/* Wait for server's response. */	type = packet_read(&plen);	/*	 * The server responds with failure if it doesn\'t like our key or	 * doesn\'t support RSA authentication.	 */	if (type == SSH_SMSG_FAILURE) {		debug("Server refused our key.");		xfree(comment);		return 0;	}	/* Otherwise, the server should respond with a challenge. */	if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)		packet_disconnect("Protocol error during RSA authentication: %d", type);	/* Get the challenge from the packet. */	challenge = BN_new();	packet_get_bignum(challenge, &clen);	packet_integrity_check(plen, clen, type);	debug("Received RSA challenge from server.");	private = key_new(KEY_RSA1);	/*	 * Load the private key.  Try first with empty passphrase; if it	 * fails, ask for a passphrase.	 */	if (!load_private_key(authfile, "", private, NULL)) {		char buf[300];		snprintf(buf, sizeof buf, "Enter passphrase for RSA key '%.100s': ",		    comment);		if (!options.batch_mode)			passphrase = read_passphrase(buf, 0);		else {			debug("Will not query passphrase for %.100s in batch mode.",			      comment);			passphrase = xstrdup("");		}		/* Load the authentication file using the pasphrase. */		if (!load_private_key(authfile, passphrase, private, NULL)) {			memset(passphrase, 0, strlen(passphrase));			xfree(passphrase);			error("Bad passphrase.");			/* Send a dummy response packet to avoid protocol error. */			packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);			for (i = 0; i < 16; i++)				packet_put_char(0);			packet_send();			packet_write_wait();			/* Expect the server to reject it... */			packet_read_expect(&plen, SSH_SMSG_FAILURE);			xfree(comment);			return 0;		}		/* Destroy the passphrase. */		memset(passphrase, 0, strlen(passphrase));		xfree(passphrase);	}	/* We no longer need the comment. */	xfree(comment);	/* Compute and send a response to the challenge. */	respond_to_rsa_challenge(challenge, private->rsa);	/* Destroy the private key. */	key_free(private);	/* We no longer need the challenge. */	BN_clear_free(challenge);	/* Wait for response from the server. */	type = packet_read(&plen);	if (type == SSH_SMSG_SUCCESS) {		debug("RSA authentication accepted by server.");		return 1;	}	if (type != SSH_SMSG_FAILURE)		packet_disconnect("Protocol error waiting RSA auth response: %d", type);	debug("RSA authentication refused.");	return 0;}