Exemple #1
0
int main(int argc, char **argv)
{
	int ret = EXIT_SUCCESS;
	if (argc != 2 && argc != 3) {
		printf("Uso: %s numero_de_bytes\n", argv[0]);
	}
	else {
		if ((strcmp(argv[1], "--help")) == 0) {
			printf("RandomKey %s\n", VERSION);
			printf("Uso: %s numero_de_bytes\n", argv[0]);
			printf("Uso: %s numero_de_bytes archivo.txt\n", argv[0]);
			printf("Contacto: [email protected]\n");
		}
		else {
			if (checkarg(argv[1]) < 0) {
				printf("%s error: %s no es valido\n", argv[0], argv[1]);
				ret = EXIT_FAILURE;
			}
			else {
				if (argv[2]) {
					ret = filekey(atoi(argv[1]), argv[2]);
				}
				else {
					makekey(atoi(argv[1]));
				}
			}
		}
	}
	return ret;
}
Exemple #2
0
// enters color struct into hashtable, with a key based on the functional type,
// and the owner. (the owner changes when a player touches an object, etc.)
void savecs(struct colorset *colors, int colortype, int ownedby)
{
    ENTRY entry, *res;
    char *keystr;
    struct entrylist *currentry;

    keystr = makekey(colortype, ownedby);

    entry.key = keystr;
    entry.data = (void *) colors;

    if ((res = hsearch(entry, ENTER)) == NULL) {
	fprintf(stderr,
		"*** error: failed to insert hash table element.\n");
	exit(6);
    }

    // keep a list of entries to free later on.
    currentry = malloc(sizeof(struct entrylist));

    entrylast->next = currentry;
    currentry->prev = entrylast;
    currentry->next = NULL;

    currentry->entry = res;

    entrylast = currentry;

}
Exemple #3
0
// finds the appropriate color pair based on the type of the object and the
// "owner".
struct colorset *findcolors(int colortype, int ownedby)
{
    ENTRY entry, *res;
    char *keystr;

    keystr = makekey(colortype, ownedby);

    entry.key = keystr;

    if ((res = hsearch(entry, FIND)) == NULL) {
	fprintf(stderr, "*** error: failed to find element: %s.\n",
		keystr);
	exit(6);
    }

    free(keystr);

    return (struct colorset *) res->data;
}
Exemple #4
0
/*
 * Initialization, before editing a new file.
 * Main thing here is to get a new buffer (in fileinit),
 * rest is peripheral state resetting.
 */
void
init(void)
{
	register int i;

	fileinit();
	dot = zero = truedol = unddol = dol = fendcore;
	one = zero+1;
	undkind = UNDNONE;
	chng = 0;
	edited = 0;
	for (i = 0; i <= 'z'-'a'+1; i++)
		names[i] = 1;
	anymarks = 0;
#ifdef CRYPT
        if(xflag) {
                xtflag = 1;
                makekey(key, tperm);
        }
#endif
}
Exemple #5
0
static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only,
			   char **commentptr, char *passphrase,
			   const char **error)
{
    unsigned char buf[16384];
    unsigned char keybuf[16];
    int len;
    int i, j, ciphertype;
    int ret = 0;
    struct MD5Context md5c;
    char *comment;

    *error = NULL;

    /* Slurp the whole file (minus the header) into a buffer. */
    len = fread(buf, 1, sizeof(buf), fp);
    fclose(fp);
    if (len < 0 || len == sizeof(buf)) {
	*error = "error reading file";
	goto end;		       /* file too big or not read */
    }

    i = 0;
    *error = "file format error";

    /*
     * A zero byte. (The signature includes a terminating NUL.)
     */
    if (len - i < 1 || buf[i] != 0)
	goto end;
    i++;

    /* One byte giving encryption type, and one reserved uint32. */
    if (len - i < 1)
	goto end;
    ciphertype = buf[i];
    if (ciphertype != 0 && ciphertype != SSH_CIPHER_3DES)
	goto end;
    i++;
    if (len - i < 4)
	goto end;		       /* reserved field not present */
    if (buf[i] != 0 || buf[i + 1] != 0 || buf[i + 2] != 0
	|| buf[i + 3] != 0) goto end;  /* reserved field nonzero, panic! */
    i += 4;

    /* Now the serious stuff. An ordinary SSH-1 public key. */
    j = makekey(buf + i, len - i, key, NULL, 1);
    if (j < 0)
	goto end;		       /* overran */
    i += j;

    /* Next, the comment field. */
    j = toint(GET_32BIT(buf + i));
    i += 4;
    if (j < 0 || len - i < j)
	goto end;
    comment = snewn(j + 1, char);
    if (comment) {
	memcpy(comment, buf + i, j);
	comment[j] = '\0';
    }
    i += j;
    if (commentptr)
	*commentptr = dupstr(comment);
    if (key)
	key->comment = comment;
    else
	sfree(comment);

    if (pub_only) {
	ret = 1;
	goto end;
    }

    if (!key) {
	ret = ciphertype != 0;
	*error = NULL;
	goto end;
    }

    /*
     * Decrypt remainder of buffer.
     */
    if (ciphertype) {
	MD5Init(&md5c);
	MD5Update(&md5c, (unsigned char *)passphrase, strlen(passphrase));
	MD5Final(keybuf, &md5c);
	des3_decrypt_pubkey(keybuf, buf + i, (len - i + 7) & ~7);
	smemclr(keybuf, sizeof(keybuf));	/* burn the evidence */
    }

    /*
     * We are now in the secret part of the key. The first four
     * bytes should be of the form a, b, a, b.
     */
    if (len - i < 4)
	goto end;
    if (buf[i] != buf[i + 2] || buf[i + 1] != buf[i + 3]) {
	*error = "wrong passphrase";
	ret = -1;
	goto end;
    }
    i += 4;

    /*
     * After that, we have one further bignum which is our
     * decryption exponent, and then the three auxiliary values
     * (iqmp, q, p).
     */
    j = makeprivate(buf + i, len - i, key);
    if (j < 0) goto end;
    i += j;
    j = ssh1_read_bignum(buf + i, len - i, &key->iqmp);
    if (j < 0) goto end;
    i += j;
    j = ssh1_read_bignum(buf + i, len - i, &key->q);
    if (j < 0) goto end;
    i += j;
    j = ssh1_read_bignum(buf + i, len - i, &key->p);
    if (j < 0) goto end;
    i += j;

    if (!rsa_verify(key)) {
	*error = "rsa_verify failed";
	freersakey(key);
	ret = 0;
    } else
	ret = 1;

  end:
    smemclr(buf, sizeof(buf));       /* burn the evidence */
    return ret;
}
Exemple #6
0
static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
    int i, j, len;
    unsigned char session_id[16];
    unsigned char *rsabuf, *keystr1, *keystr2;
    unsigned char cookie[8];
    struct RSAKey servkey, hostkey;
    struct MD5Context md5c;
    unsigned long supported_ciphers_mask;
    int cipher_type;

    extern struct ssh_cipher ssh_3des;
    extern struct ssh_cipher ssh_blowfish;

    crBegin;

    random_init();

    while (!ispkt)
	crReturnV;

    if (pktin.type != 2)
	fatalbox("Public key packet not received");

    memcpy(cookie, pktin.body, 8);

    MD5Init(&md5c);

    i = makekey(pktin.body+8, &servkey, &keystr1);

    j = makekey(pktin.body+8+i, &hostkey, &keystr2);

    supported_ciphers_mask = (pktin.body[12+i+j] << 24) |
                             (pktin.body[13+i+j] << 16) |
                             (pktin.body[14+i+j] << 8) |
                             (pktin.body[15+i+j]);

    MD5Update(&md5c, keystr2, hostkey.bytes);
    MD5Update(&md5c, keystr1, servkey.bytes);
    MD5Update(&md5c, pktin.body, 8);

    MD5Final(session_id, &md5c);

    for (i=0; i<32; i++)
	session_key[i] = random_byte();

    len = (hostkey.bytes > servkey.bytes ? hostkey.bytes : servkey.bytes);

    rsabuf = malloc(len);
    if (!rsabuf)
	fatalbox("Out of memory");

    verify_ssh_host_key(savedhost, &hostkey);

    for (i=0; i<32; i++) {
	rsabuf[i] = session_key[i];
	if (i < 16)
	    rsabuf[i] ^= session_id[i];
    }

    if (hostkey.bytes > servkey.bytes) {
	rsaencrypt(rsabuf, 32, &servkey);
	rsaencrypt(rsabuf, servkey.bytes, &hostkey);
    } else {
	rsaencrypt(rsabuf, 32, &hostkey);
	rsaencrypt(rsabuf, hostkey.bytes, &servkey);
    }

    cipher_type = cfg.cipher == CIPHER_BLOWFISH ? SSH_CIPHER_BLOWFISH :
                  SSH_CIPHER_3DES;
    if ((supported_ciphers_mask & (1 << cipher_type)) == 0) {
	c_write("Selected cipher not supported, falling back to 3DES\r\n", 53);
	cipher_type = SSH_CIPHER_3DES;
    }

    s_wrpkt_start(3, len+15);
    pktout.body[0] = cipher_type;
    memcpy(pktout.body+1, cookie, 8);
    pktout.body[9] = (len*8) >> 8;
    pktout.body[10] = (len*8) & 0xFF;
    memcpy(pktout.body+11, rsabuf, len);
    pktout.body[len+11] = pktout.body[len+12] = 0;   /* protocol flags */
    pktout.body[len+13] = pktout.body[len+14] = 0;
    s_wrpkt();

    free(rsabuf);

    cipher = cipher_type == SSH_CIPHER_BLOWFISH ? &ssh_blowfish :
             &ssh_3des;
    cipher->sesskey(session_key);

    do { crReturnV; } while (!ispkt);

    if (pktin.type != 14)
	fatalbox("Encryption not successfully enabled");

    fflush(stdout);
    {
	static char username[100];
	static int pos = 0;
	static char c;
	if (!*cfg.username) {
	    c_write("login as: ", 10);
	    while (pos >= 0) {
		do { crReturnV; } while (ispkt);
		while (inlen--) switch (c = *in++) {
		  case 10: case 13:
		    username[pos] = 0;
		    pos = -1;
		    break;
		  case 8: case 127:
		    if (pos > 0) {
			c_write("\b \b", 3);
			pos--;
		    }
		    break;
		  case 21: case 27:
		    while (pos > 0) {
			c_write("\b \b", 3);
			pos--;
		    }
		    break;
		  case 3: case 4:
		    random_save_seed();
		    exit(0);
		    break;
		  default:
		    if (c >= ' ' && c <= '~' && pos < 40) {
			username[pos++] = c;
			c_write(&c, 1);
		    }
		    break;
		}
	    }
	    c_write("\r\n", 2);
	    username[strcspn(username, "\n\r")] = '\0';
	} else {
	    char stuff[200];
	    strncpy(username, cfg.username, 99);
	    username[99] = '\0';
	    sprintf(stuff, "Sent username \"%s\".\r\n", username);
	    c_write(stuff, strlen(stuff));
	}
	s_wrpkt_start(4, 4+strlen(username));
	pktout.body[0] = pktout.body[1] = pktout.body[2] = 0;
	pktout.body[3] = strlen(username);
	memcpy(pktout.body+4, username, strlen(username));
	s_wrpkt();
    }

    do { crReturnV; } while (!ispkt);

    while (pktin.type == 15) {
	static char password[100];
	static int pos;
	static char c;
	c_write("password: "******"\r\n", 2);
	s_wrpkt_start(9, 4+strlen(password));
	pktout.body[0] = pktout.body[1] = pktout.body[2] = 0;
	pktout.body[3] = strlen(password);
	memcpy(pktout.body+4, password, strlen(password));
	s_wrpkt();
	memset(password, 0, strlen(password));
	do { crReturnV; } while (!ispkt);
	if (pktin.type == 15) {
	    c_write("Access denied\r\n", 15);
	} else if (pktin.type != 14) {
	    fatalbox("Strange packet received, type %d", pktin.type);
	}
    }

    if (!cfg.nopty) {
        i = strlen(cfg.termtype);
        s_wrpkt_start(10, i+5*4+1);
        pktout.body[0] = (i >> 24) & 0xFF;
        pktout.body[1] = (i >> 16) & 0xFF;
        pktout.body[2] = (i >> 8) & 0xFF;
        pktout.body[3] = i & 0xFF;
        memcpy(pktout.body+4, cfg.termtype, i);
        i += 4;
        pktout.body[i++] = (rows >> 24) & 0xFF;
        pktout.body[i++] = (rows >> 16) & 0xFF;
        pktout.body[i++] = (rows >> 8) & 0xFF;
        pktout.body[i++] = rows & 0xFF;
        pktout.body[i++] = (cols >> 24) & 0xFF;
        pktout.body[i++] = (cols >> 16) & 0xFF;
        pktout.body[i++] = (cols >> 8) & 0xFF;
        pktout.body[i++] = cols & 0xFF;
        memset(pktout.body+i, 0, 9);       /* 0 pixwidth, 0 pixheight, 0.b endofopt */
        s_wrpkt();
        ssh_state = SSH_STATE_INTERMED;
        do { crReturnV; } while (!ispkt);
        if (pktin.type != 14 && pktin.type != 15) {
            fatalbox("Protocol confusion");
        } else if (pktin.type == 15) {
            c_write("Server refused to allocate pty\r\n", 32);
        }
    }
Exemple #7
0
/* SET EMAIL <new address> */
static void ns_cmd_set_email(sourceinfo_t *si, int parc, char *parv[])
{
	char *email = parv[0];
	metadata_t *md;

	if (!email)
	{
		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "EMAIL");
		command_fail(si, fault_needmoreparams, _("Syntax: SET EMAIL <new e-mail>"));
		return;
	}

	if (si->smu->flags & MU_WAITAUTH)
	{
		command_fail(si, fault_noprivs, _("Please verify your original registration before changing your e-mail address."));
		return;
	}

	if (!strcasecmp(si->smu->email, email))
	{
		md = metadata_find(si->smu, "private:verify:emailchg:newemail");
		if (md != NULL)
		{
			command_success_nodata(si, _("The email address change to \2%s\2 has been cancelled."), md->value);
			metadata_delete(si->smu, "private:verify:emailchg:key");
			metadata_delete(si->smu, "private:verify:emailchg:newemail");
			metadata_delete(si->smu, "private:verify:emailchg:timestamp");
		}
		else
			command_fail(si, fault_nochange, _("The email address for account \2%s\2 is already set to \2%s\2."), entity(si->smu)->name, si->smu->email);
		return;
	}

	if (!validemail(email))
	{
		command_fail(si, fault_badparams, _("\2%s\2 is not a valid email address."), email);
		return;
	}

	if (me.auth == AUTH_EMAIL)
	{
		unsigned long key = makekey();

		metadata_add(si->smu, "private:verify:emailchg:key", number_to_string(key));
		metadata_add(si->smu, "private:verify:emailchg:newemail", email);
		metadata_add(si->smu, "private:verify:emailchg:timestamp", number_to_string(CURRTIME));

		if (!sendemail(si->su != NULL ? si->su : si->service->me, EMAIL_SETEMAIL, si->smu, number_to_string(key)))
		{
			command_fail(si, fault_emailfail, _("Sending email failed, sorry! Your email address is unchanged."));
			metadata_delete(si->smu, "private:verify:emailchg:key");
			metadata_delete(si->smu, "private:verify:emailchg:newemail");
			metadata_delete(si->smu, "private:verify:emailchg:timestamp");
			return;
		}

		logcommand(si, CMDLOG_SET, "SET:EMAIL: \2%s\2 (\2%s\2 -> \2%s\2) (awaiting verification)", entity(si->smu)->name, si->smu->email, email);
		command_success_nodata(si, _("An email containing email changing instructions has been sent to \2%s\2."), email);
		command_success_nodata(si, _("Your email address will not be changed until you follow these instructions."));

		return;
	}

	myuser_set_email(si->smu, email);

	logcommand(si, CMDLOG_SET, "SET:EMAIL: \2%s\2 (\2%s\2 -> \2%s\2)", entity(si->smu)->name, si->smu->email, email);
	command_success_nodata(si, _("The email address for account \2%s\2 has been changed to \2%s\2."), entity(si->smu)->name, si->smu->email);
}
Exemple #8
0
int
main(int argc, char *argv[])
{
	extern char *optarg;		/* argument to option if any */
	int i;				/* counter in a for loop */
	char *p;			/* used to obtain the key */
	DES_cblock msgbuf;		/* I/O buffer */
	int kflag;			/* command-line encryption key */

	setproctitle("-");		/* Hide command-line arguments */

	/* initialize the initialization vector */
	MEMZERO(ivec, 8);

	/* process the argument list */
	kflag = 0;
	while ((i = getopt(argc, argv, "abdF:f:k:m:o:pv:")) != -1)
		switch(i) {
		case 'a':		/* key is ASCII */
			keybase = KEY_ASCII;
			break;
		case 'b':		/* use ECB mode */
			alg = ALG_ECB;
			break;
		case 'd':		/* decrypt */
			mode = MODE_DECRYPT;
			break;
		case 'F':		/* use alternative CFB mode */
			alg = ALG_CFBA;
			if ((fbbits = setbits(optarg, 7)) > 56 || fbbits == 0)
				errx(1, "-F: number must be 1-56 inclusive");
			else if (fbbits == -1)
				errx(1, "-F: number must be a multiple of 7");
			break;
		case 'f':		/* use CFB mode */
			alg = ALG_CFB;
			if ((fbbits = setbits(optarg, 8)) > 64 || fbbits == 0)
				errx(1, "-f: number must be 1-64 inclusive");
			else if (fbbits == -1)
				errx(1, "-f: number must be a multiple of 8");
			break;
		case 'k':		/* encryption key */
			kflag = 1;
			cvtkey(msgbuf, optarg);
			break;
		case 'm':		/* number of bits for MACing */
			mode = MODE_AUTHENTICATE;
			if ((macbits = setbits(optarg, 1)) > 64)
				errx(1, "-m: number must be 0-64 inclusive");
			break;
		case 'o':		/* use OFB mode */
			alg = ALG_OFB;
			if ((fbbits = setbits(optarg, 8)) > 64 || fbbits == 0)
				errx(1, "-o: number must be 1-64 inclusive");
			else if (fbbits == -1)
				errx(1, "-o: number must be a multiple of 8");
			break;
		case 'p':		/* preserve parity bits */
			pflag = 1;
			break;
		case 'v':		/* set initialization vector */
			cvtkey(ivec, optarg);
			break;
		default:		/* error */
			usage();
		}

	if (!kflag) {
		/*
		 * if the key's not ASCII, assume it is
		 */
		keybase = KEY_ASCII;
		/*
		 * get the key
		 */
		p = getpass("Enter key: ");
		/*
		 * copy it, nul-padded, into the key area
		 */
		cvtkey(msgbuf, p);
	}

	makekey(&msgbuf);
	inverse = (alg == ALG_CBC || alg == ALG_ECB) && mode == MODE_DECRYPT;

	switch(alg) {
	case ALG_CBC:
		switch(mode) {
		case MODE_AUTHENTICATE:	/* authenticate using CBC mode */
			cbcauth();
			break;
		case MODE_DECRYPT:	/* decrypt using CBC mode */
			cbcdec();
			break;
		case MODE_ENCRYPT:	/* encrypt using CBC mode */
			cbcenc();
			break;
		}
		break;
	case ALG_CFB:
		switch(mode) {
		case MODE_AUTHENTICATE:	/* authenticate using CFB mode */
			cfbauth();
			break;
		case MODE_DECRYPT:	/* decrypt using CFB mode */
			cfbdec();
			break;
		case MODE_ENCRYPT:	/* encrypt using CFB mode */
			cfbenc();
			break;
		}
		break;
	case ALG_CFBA:
		switch(mode) {
		case MODE_AUTHENTICATE:	/* authenticate using CFBA mode */
			errx(1, "can't authenticate with CFBA mode");
			break;
		case MODE_DECRYPT:	/* decrypt using CFBA mode */
			cfbadec();
			break;
		case MODE_ENCRYPT:	/* encrypt using CFBA mode */
			cfbaenc();
			break;
		}
		break;
	case ALG_ECB:
		switch(mode) {
		case MODE_AUTHENTICATE:	/* authenticate using ECB mode */
			errx(1, "can't authenticate with ECB mode");
			break;
		case MODE_DECRYPT:	/* decrypt using ECB mode */
			ecbdec();
			break;
		case MODE_ENCRYPT:	/* encrypt using ECB mode */
			ecbenc();
			break;
		}
		break;
	case ALG_OFB:
		switch(mode) {
		case MODE_AUTHENTICATE:	/* authenticate using OFB mode */
			errx(1, "can't authenticate with OFB mode");
			break;
		case MODE_DECRYPT:	/* decrypt using OFB mode */
			ofbdec();
			break;
		case MODE_ENCRYPT:	/* encrypt using OFB mode */
			ofbenc();
			break;
		}
		break;
	}
	return (0);
}
Exemple #9
0
void GEN::GenRoot(char* data1, int topk)
{
	int si_last, i, len, paircnt, key;
	int left, right;
	char lc[MaxTokenLen+1], rc[MaxTokenLen+1];
	char c;
	int pu;
	float p, pCurrent;
	char data[MAXWORDLEN];
	char temp[MAXSTR];
	
	int chk_bool; // Daniel 의 chk_seg 위한 변수
	chk_bool = 0;

	genstack.initstack();
	
#if DEBUG
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
	
	strcpy(input_data, data1);	// backup for answerlist
	len = strlen(data1);
	data[0]=LEFTENDCHAR;
	strcpy(&data[1], data1);
	data[len+1]=RIGHTENDCHAR;
	data[len+2]='\0';
	
	si_last = len + 2;
	
	initanswer();
	
	// segment

	while ((pv=genstack.popstack()) != NULL)
	{
		genstack.copy(pvTemp, pv);					// copy stack V element
		
		if (pv->si == si_last) {
			genvar(pv);
			continue;
		}
		
		// try for new pu from a new character
		
		genstack.copy(&u, pvTemp);					// u for working V variable
		u.li = u.si;
		lc[0] = data[u.li];					// left context
		lc[1] = '\0';
		left = GEN_PU.getindex(lc);


		u.si += 1;
		c = data[u.si];
		pu_str[0]=c;						// one character pu
		pu_str[1]='\0';
		
		u.ri = u.si+1;						// right context
		rc[0] = data[u.ri];
		rc[1] = '\0';
		right = GEN_PU.getindex(rc);

		if ( ( u.pu = GEN_PU.getindex(pu_str)) != -1 )
		{
			u.di += 1;
			u.seg[u.di]=u.pu;
			u.nilgen = 0;		// reset (false) null-to-pu gen flag
			genstack.pushstack(&u);		// add original
			pu = u.pu;
			pCurrent = u.p;
			u.pPre = u.p;
			key = makekey(left, pu, right);

			paircnt = GEN_IVT.lookup(key);
			for( i = 0; i < paircnt; i++ ) {
				GEN_IVT.get_post(temp);
				GEN_IVT.cnt_offset();
				sscanf(temp, "%d %f", &u.pu, &p);

				u.seg[u.di] = u.pu;
				u.p = pCurrent + p + pooseg(u.seg, u.di);
				genstack.pushstack(&u);
			}

		}
		
		// try for null pu
		
		genstack.copy(&u, pvTemp);
		
		if (u.nilgen == 0) {		// avoid duplicated null-to-pu gen
			
			u.di += 1;
			
			u.li = u.si;
			lc[0] = data[u.li];		// left context
			lc[1] = '\0';
			left = GEN_PU.getindex(lc);

			pu = NULLCODE;			// null pu
			u.ri = u.li+1;
			rc[0] = data[u.ri];		// right context
			rc[1] = '\0';
			right = GEN_PU.getindex(rc);

			pCurrent = u.p;
			u.pPre = u.p;
			key = makekey(left, pu, right);

			paircnt = GEN_IVT.lookup(key);
			for (i = 0 ; i < paircnt ; i++) { 
				GEN_IVT.get_post(temp);
				GEN_IVT.cnt_offset();
				sscanf(temp, "%d %f", &u.pu, &p);

				u.seg[u.di] = u.pu;
				u.p=pCurrent + p + pooseg(u.seg, u.di);
				u.nilgen = 1;		// set (true) null-to-pu gen flag
				genstack.pushstack(&u);
			}
			
			
		} // end if (u.nilgen == 0)
		
		// try for concated pu (old-pu + new character)
		
		genstack.copy(&u, pvTemp);
		
		if (u.pu >= 0) { // only try for the valid pu
			
			u.si += 1;
			c = data[u.si];
			strcpy(pu_str, GEN_PU.getstring(u.pu));

			len=strlen(pu_str);
			pu_str[len]=c;					// new concated pu
			pu_str[len+1]='\0';
			
			lc[0] = data[u.li];				// left context
			lc[1] = '\0';
			left = GEN_PU.getindex(lc);

			u.ri = u.si+1;
			rc[0] = data[u.ri];				// right context
			rc[1] = '\0';
			right = GEN_PU.getindex(rc);

			if ( (u.pu = GEN_PU.getindex(pu_str)) != -1)
			{				
				u.seg[u.di]=u.pu;
				u.nilgen = 0;			// reset (false) null-to-pu gen flag
				
				// Daniel 의 chk_Seg 삽입
				chk_bool = chkseg(&u);
				if(chk_bool == 0)
					genstack.pushstack(&u);
				
				pu = u.pu;
				
				key = makekey(left, pu, right);

				paircnt = GEN_IVT.lookup(key);
				for (i = 0 ; i < paircnt ; i++) { 
					GEN_IVT.get_post(temp);
					GEN_IVT.cnt_offset();
					sscanf(temp, "%d %f", &u.pu, &p);

					u.seg[u.di]=u.pu;
					u.p=pCurrent + p + pooseg(u.seg, u.di);
					genstack.pushstack(&u);
				}
			}
		}	// if (u.pu >= 0) 
		
	} // while
	
	if( ans_max > MAXGEN ) ans_max = MAXGEN;
	for (i=1; i<=ans_max && i < topk ; i++) { // 2012. 8. 28. Daniel lee
		gen_node.EnQ(answerlist[i].str, answerlist[i].p);	
	}
	genstack.emptystack();
}