if (RegCreateKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys", &rkey) != ERROR_SUCCESS)
if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys", &rkey) != ERROR_SUCCESS)
int verify_host_key(char *hostname, int port, char *keytype, char *key){    char *otherstr, *regname;    int len;    HKEY rkey;    DWORD readlen;    DWORD type;    int ret, compare;    len = 1 + strlen(key);    /*     * Now read a saved key in from the registry and see what it     * says.     */    otherstr = smalloc(len);    regname = smalloc(3 * (strlen(hostname) + strlen(keytype)) + 15);    hostkey_regname(regname, hostname, port, keytype);    if (RegCreateKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",		     &rkey) != ERROR_SUCCESS)	return 1;		       /* key does not exist in registry */    readlen = len;    ret = RegQueryValueEx(rkey, regname, NULL, &type, otherstr, &readlen);    if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA &&	!strcmp(keytype, "rsa")) {	/*	 * Key didn't exist. If the key type is RSA, we'll try	 * another trick, which is to look up the _old_ key format	 * under just the hostname and translate that.	 */	char *justhost = regname + 1 + strcspn(regname, ":");	char *oldstyle = smalloc(len + 10);	/* safety margin */	readlen = len;	ret = RegQueryValueEx(rkey, justhost, NULL, &type,			      oldstyle, &readlen);	if (ret == ERROR_SUCCESS && type == REG_SZ) {	    /*	     * The old format is two old-style bignums separated by	     * a slash. An old-style bignum is made of groups of	     * four hex digits: digits are ordered in sensible	     * (most to least significant) order within each group,	     * but groups are ordered in silly (least to most)	     * order within the bignum. The new format is two	     * ordinary C-format hex numbers (0xABCDEFG...XYZ, with	     * A nonzero except in the special case 0x0, which	     * doesn't appear anyway in RSA keys) separated by a	     * comma. All hex digits are lowercase in both formats.	     */	    char *p = otherstr;	    char *q = oldstyle;	    int i, j;	    for (i = 0; i < 2; i++) {		int ndigits, nwords;		*p++ = '0';		*p++ = 'x';		ndigits = strcspn(q, "/");	/* find / or end of string */		nwords = ndigits / 4;		/* now trim ndigits to remove leading zeros */		while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1)		    ndigits--;		/* now move digits over to new string */		for (j = 0; j < ndigits; j++)		    p[ndigits - 1 - j] = q[j ^ 3];		p += ndigits;		q += nwords * 4;		if (*q) {		    q++;	       /* eat the slash */		    *p++ = ',';	       /* add a comma */		}		*p = '\0';	       /* terminate the string */	    }	    /*	     * Now _if_ this key matches, we'll enter it in the new	     * format. If not, we'll assume something odd went	     * wrong, and hyper-cautiously do nothing.	     */	    if (!strcmp(otherstr, key))		RegSetValueEx(rkey, regname, 0, REG_SZ, otherstr,			      strlen(otherstr) + 1);	}    }    RegCloseKey(rkey);    compare = strcmp(otherstr, key);    sfree(otherstr);    sfree(regname);    if (ret == ERROR_MORE_DATA ||	(ret == ERROR_SUCCESS && type == REG_SZ && compare))	return 2;		       /* key is different in registry */    else if (ret != ERROR_SUCCESS || type != REG_SZ)	return 1;		       /* key does not exist in registry */    else	return 0;		       /* key matched OK in registry */}