slen = RSA_size(key->rsa); sig = xmalloc(slen);
nid = NID_sha1; if ((evp_md = EVP_get_digestbynid(nid)) == NULL) { error("ssh_rsa_sign: EVP_get_digestbynid %d failed", nid); return -1; }
ssh_rsa_sign(    Key *key,    u_char **sigp, int *lenp,    u_char *data, int datalen){	EVP_MD *evp_md = EVP_sha1();	EVP_MD_CTX md;	u_char *digest, *sig, *ret;	u_int slen, dlen, len;	int ok;	Buffer b;	if (key == NULL || key->type != KEY_RSA || key->rsa == NULL) {		error("ssh_rsa_sign: no RSA key");		return -1;	}	slen = RSA_size(key->rsa);	sig = xmalloc(slen);	dlen = evp_md->md_size;	digest = xmalloc(dlen);	EVP_DigestInit(&md, evp_md);	EVP_DigestUpdate(&md, data, datalen);	EVP_DigestFinal(&md, digest, NULL);	ok = RSA_sign(NID_sha1, digest, dlen, sig, &len, key->rsa);	memset(digest, 'd', dlen);	xfree(digest);	if (ok != 1) {		int ecode = ERR_get_error();		error("ssh_rsa_sign: RSA_sign failed: %s", ERR_error_string(ecode, NULL));		xfree(sig);		return -1;	}	if (len < slen) {		int diff = slen - len;		debug("slen %d > len %d", slen, len);		memmove(sig + diff, sig, len);		memset(sig, 0, diff);	} else if (len > slen) {		error("ssh_rsa_sign: slen %d slen2 %d", slen, len);		xfree(sig);		return -1;	}	/* encode signature */	buffer_init(&b);	buffer_put_cstring(&b, "ssh-rsa");	buffer_put_string(&b, sig, slen);	len = buffer_len(&b);	ret = xmalloc(len);	memcpy(ret, buffer_ptr(&b), len);	buffer_free(&b);	memset(sig, 's', slen);	xfree(sig);	if (lenp != NULL)		*lenp = len;	if (sigp != NULL)		*sigp = ret;	debug2("ssh_rsa_sign: done");	return 0;}