FreeBSD/crypto/openssh/authfd.c
/* ask agent to sign data, returns err.h code on error, 0 on success */
ask agent to sign data, returns err.h code on error, 0 on success
ask agent to sign data returns err . h code on error 0 on success
int
ssh_agent_sign(int sock, struct sshkey *key,
    u_char **sigp, size_t *lenp,
    const u_char *data, size_t datalen, const char *alg, u_int compat)
{
	struct sshbuf *msg;
	u_char *blob = NULL, type;
	size_t blen = 0, len = 0;
	u_int flags = 0;
	int r = SSH_ERR_INTERNAL_ERROR;
	*sigp = NULL;
	*lenp = 0;
	if (datalen > SSH_KEY_MAX_SIGN_DATA_SIZE)
		return SSH_ERR_INVALID_ARGUMENT;
	if (compat & SSH_BUG_SIGBLOB)
		flags |= SSH_AGENT_OLD_SIGNATURE;
	if ((msg = sshbuf_new()) == NULL)
		return SSH_ERR_ALLOC_FAIL;
	if ((r = sshkey_to_blob(key, &blob, &blen)) != 0)
		goto out;
	flags |= agent_encode_alg(key, alg);
	if ((r = sshbuf_put_u8(msg, SSH2_AGENTC_SIGN_REQUEST)) != 0 ||
	    (r = sshbuf_put_string(msg, blob, blen)) != 0 ||
	    (r = sshbuf_put_string(msg, data, datalen)) != 0 ||
	    (r = sshbuf_put_u32(msg, flags)) != 0)
		goto out;
	if ((r = ssh_request_reply(sock, msg, msg)) != 0)
		goto out;
	if ((r = sshbuf_get_u8(msg, &type)) != 0)
		goto out;
	if (agent_failed(type)) {
		r = SSH_ERR_AGENT_FAILURE;
		goto out;
	} else if (type != SSH2_AGENT_SIGN_RESPONSE) {
		r = SSH_ERR_INVALID_FORMAT;
		goto out;
	}
	if ((r = sshbuf_get_string(msg, sigp, &len)) != 0)
		goto out;
	*lenp = len;
	r = 0;
 out:
	if (blob != NULL) {
		explicit_bzero(blob, blen);
		free(blob);
	}
	sshbuf_free(msg);
	return r;
}
int ssh_agent_sign ( int sock , struct sshkey * key , u_char * * sigp , size_t * lenp , const u_char * data , size_t datalen , const char * alg , u_int compat ) { struct sshbuf * msg ; u_char * blob = NULL , type ; size_t blen = 0 , len = 0 ; u_int flags = 0 ; int r = SSH_ERR_INTERNAL_ERROR ; * sigp = NULL ; * lenp = 0 ; if ( datalen > SSH_KEY_MAX_SIGN_DATA_SIZE ) return SSH_ERR_INVALID_ARGUMENT ; if ( compat & SSH_BUG_SIGBLOB ) flags |= SSH_AGENT_OLD_SIGNATURE ; if ( ( msg = sshbuf_new ( ) ) == NULL ) return SSH_ERR_ALLOC_FAIL ; if ( ( r = sshkey_to_blob ( key , & blob , & blen ) ) != 0 ) goto out ; flags |= agent_encode_alg ( key , alg ) ; if ( ( r = sshbuf_put_u8 ( msg , SSH2_AGENTC_SIGN_REQUEST ) ) != 0 || ( r = sshbuf_put_string ( msg , blob , blen ) ) != 0 || ( r = sshbuf_put_string ( msg , data , datalen ) ) != 0 || ( r = sshbuf_put_u32 ( msg , flags ) ) != 0 ) goto out ; if ( ( r = ssh_request_reply ( sock , msg , msg ) ) != 0 ) goto out ; if ( ( r = sshbuf_get_u8 ( msg , & type ) ) != 0 ) goto out ; if ( agent_failed ( type ) ) { r = SSH_ERR_AGENT_FAILURE ; goto out ; } else if ( type != SSH2_AGENT_SIGN_RESPONSE ) { r = SSH_ERR_INVALID_FORMAT ; goto out ; } if ( ( r = sshbuf_get_string ( msg , sigp , & len ) ) != 0 ) goto out ; * lenp = len ; r = 0 ; out : if ( blob != NULL ) { explicit_bzero ( blob , blen ) ; free ( blob ) ; } sshbuf_free ( msg ) ; return r ; }
ask agent to sign data, returns err.h code on error, 0 on success
ask agent to sign data returns err . h code on error 0 on success