Lines Matching +full:p +full:- +full:state

1 /*-
45 #include "key-proto.h"
46 #include "misc-proto.h"
58 #define FAILED -1
67 int state[2]; member
140 fbp->state[0] = fbp->state[1] = FAILED; in fb64_init()
141 fbp->fb_feed[0] = IAC; in fb64_init()
142 fbp->fb_feed[1] = SB; in fb64_init()
143 fbp->fb_feed[2] = TELOPT_ENCRYPT; in fb64_init()
144 fbp->fb_feed[3] = ENCRYPT_IS; in fb64_init()
149 * -1: some error. Negotiation is done, encryption not ready.
171 unsigned char *p; in fb64_start() local
172 int state; in fb64_start() local
181 state = fbp->state[dir-1]; in fb64_start()
182 if (state == FAILED) in fb64_start()
183 state = IN_PROGRESS; in fb64_start()
187 state = fbp->state[dir-1]; in fb64_start()
188 if (state == FAILED) in fb64_start()
189 state = IN_PROGRESS; in fb64_start()
190 else if ((state & NO_SEND_IV) == 0) in fb64_start()
193 if (!VALIDKEY(fbp->krbdes_key)) { in fb64_start()
194 fbp->need_start = 1; in fb64_start()
197 state &= ~NO_SEND_IV; in fb64_start()
198 state |= NO_RECV_IV; in fb64_start()
204 DES_random_key((Block *)fbp->temp_feed); in fb64_start()
205 DES_ecb_encrypt((Block *)fbp->temp_feed, (Block *)fbp->temp_feed, in fb64_start()
206 &fbp->krbdes_sched, 1); in fb64_start()
207 p = fbp->fb_feed + 3; in fb64_start()
208 *p++ = ENCRYPT_IS; in fb64_start()
209 p++; in fb64_start()
210 *p++ = FB64_IV; in fb64_start()
212 if ((*p++ = fbp->temp_feed[x]) == IAC) in fb64_start()
213 *p++ = IAC; in fb64_start()
215 *p++ = IAC; in fb64_start()
216 *p++ = SE; in fb64_start()
217 printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]); in fb64_start()
218 net_write(fbp->fb_feed, p - fbp->fb_feed); in fb64_start()
223 return(fbp->state[dir-1] = state); in fb64_start()
228 * -1: some error. Negotiation is done, encryption not ready.
247 unsigned char *p; in fb64_is() local
248 int state = fbp->state[DIR_DECRYPT-1]; in fb64_is() local
250 if (cnt-- < 1) in fb64_is()
258 state = FAILED; in fb64_is()
268 fb64_stream_iv((void *)data, &fbp->streams[DIR_DECRYPT-1]); in fb64_is()
270 p = fbp->fb_feed + 3; in fb64_is()
271 *p++ = ENCRYPT_REPLY; in fb64_is()
272 p++; in fb64_is()
273 *p++ = FB64_IV_OK; in fb64_is()
274 *p++ = IAC; in fb64_is()
275 *p++ = SE; in fb64_is()
276 printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]); in fb64_is()
277 net_write(fbp->fb_feed, p - fbp->fb_feed); in fb64_is()
279 state = fbp->state[DIR_DECRYPT-1] = IN_PROGRESS; in fb64_is()
284 printf("Unknown option type: %d\r\n", *(data-1)); in fb64_is()
295 p = fbp->fb_feed + 3; in fb64_is()
296 *p++ = ENCRYPT_REPLY; in fb64_is()
297 p++; in fb64_is()
298 *p++ = FB64_IV_BAD; in fb64_is()
299 *p++ = IAC; in fb64_is()
300 *p++ = SE; in fb64_is()
301 printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]); in fb64_is()
302 net_write(fbp->fb_feed, p - fbp->fb_feed); in fb64_is()
306 return(fbp->state[DIR_DECRYPT-1] = state); in fb64_is()
311 * -1: some error. Negotiation is done, encryption not ready.
330 int state = fbp->state[DIR_ENCRYPT-1]; in fb64_reply() local
332 if (cnt-- < 1) in fb64_reply()
337 fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]); in fb64_reply()
338 if (state == FAILED) in fb64_reply()
339 state = IN_PROGRESS; in fb64_reply()
340 state &= ~NO_RECV_IV; in fb64_reply()
345 memset(fbp->temp_feed, 0, sizeof(Block)); in fb64_reply()
346 fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]); in fb64_reply()
347 state = FAILED; in fb64_reply()
352 printf("Unknown option type: %d\r\n", data[-1]); in fb64_reply()
358 state = FAILED; in fb64_reply()
361 return(fbp->state[DIR_ENCRYPT-1] = state); in fb64_reply()
379 if (!key || key->type != SK_DES) { in fb64_session()
382 key ? key->type : -1, SK_DES); in fb64_session()
385 memmove((void *)fbp->krbdes_key, (void *)key->data, sizeof(Block)); in fb64_session()
387 fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_ENCRYPT-1]); in fb64_session()
388 fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]); in fb64_session()
390 DES_key_sched((Block *)fbp->krbdes_key, &fbp->krbdes_sched); in fb64_session()
396 if (fbp->need_start) { in fb64_session()
397 fbp->need_start = 0; in fb64_session()
404 * 0, then mark the state as SUCCESS.
421 int state = fbp->state[dir-1]; in fb64_keyid() local
425 return(state); in fb64_keyid()
428 if (state == FAILED) in fb64_keyid()
429 state = IN_PROGRESS; in fb64_keyid()
431 state &= ~NO_KEYID; in fb64_keyid()
433 return(fbp->state[dir-1] = state); in fb64_keyid()
443 buf[buflen-1] = '\0'; /* make sure it's NULL terminated */ in fb64_printsub()
444 buflen -= 1; in fb64_printsub()
467 buflen--; in fb64_printsub()
471 buflen--; in fb64_printsub()
493 memmove((void *)stp->str_iv, (void *)seed, sizeof(Block)); in fb64_stream_iv()
494 memmove((void *)stp->str_output, (void *)seed, sizeof(Block)); in fb64_stream_iv()
496 DES_key_sched((Block *)stp->str_ikey, &stp->str_sched); in fb64_stream_iv()
498 stp->str_index = sizeof(Block); in fb64_stream_iv()
504 memmove((void *)stp->str_ikey, (void *)key, sizeof(Block)); in fb64_stream_key()
505 DES_key_sched((Block *)key, &stp->str_sched); in fb64_stream_key()
507 memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block)); in fb64_stream_key()
509 stp->str_index = sizeof(Block); in fb64_stream_key()
515 * key --->+-----+
516 * +->| DES |--+
517 * | +-----+ |
519 * INPUT --(--------->(+)+---> DATA
521 * +-------------+
537 struct stinfo *stp = &fb[CFB].streams[DIR_ENCRYPT-1]; in cfb64_encrypt()
540 idx = stp->str_index; in cfb64_encrypt()
541 while (c-- > 0) { in cfb64_encrypt()
544 DES_ecb_encrypt((Block *)stp->str_output, (Block *)b, &stp->str_sched, 1); in cfb64_encrypt()
545 memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); in cfb64_encrypt()
550 *s = stp->str_output[idx] = (stp->str_feed[idx] ^ *s); in cfb64_encrypt()
554 stp->str_index = idx; in cfb64_encrypt()
560 struct stinfo *stp = &fb[CFB].streams[DIR_DECRYPT-1]; in cfb64_decrypt()
563 if (data == -1) { in cfb64_decrypt()
569 if (stp->str_index) in cfb64_decrypt()
570 --stp->str_index; in cfb64_decrypt()
574 idx = stp->str_index++; in cfb64_decrypt()
577 DES_ecb_encrypt((Block *)stp->str_output, (Block *)b, &stp->str_sched, 1); in cfb64_decrypt()
578 memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); in cfb64_decrypt()
579 stp->str_index = 1; /* Next time will be 1 */ in cfb64_decrypt()
584 stp->str_output[idx] = data; in cfb64_decrypt()
585 return(data ^ stp->str_feed[idx]); in cfb64_decrypt()
591 * key --->+-----+
592 * +->| DES |--+
593 * | +-----+ |
594 * +-----------+
596 * INPUT -------->(+) ----> DATA
610 struct stinfo *stp = &fb[OFB].streams[DIR_ENCRYPT-1]; in ofb64_encrypt()
613 idx = stp->str_index; in ofb64_encrypt()
614 while (c-- > 0) { in ofb64_encrypt()
617 DES_ecb_encrypt((Block *)stp->str_feed, (Block *)b, &stp->str_sched, 1); in ofb64_encrypt()
618 memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); in ofb64_encrypt()
621 *s++ ^= stp->str_feed[idx]; in ofb64_encrypt()
624 stp->str_index = idx; in ofb64_encrypt()
630 struct stinfo *stp = &fb[OFB].streams[DIR_DECRYPT-1]; in ofb64_decrypt()
633 if (data == -1) { in ofb64_decrypt()
639 if (stp->str_index) in ofb64_decrypt()
640 --stp->str_index; in ofb64_decrypt()
644 idx = stp->str_index++; in ofb64_decrypt()
647 DES_ecb_encrypt((Block *)stp->str_feed, (Block *)b, &stp->str_sched, 1); in ofb64_decrypt()
648 memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); in ofb64_decrypt()
649 stp->str_index = 1; /* Next time will be 1 */ in ofb64_decrypt()
653 return(data ^ stp->str_feed[idx]); in ofb64_decrypt()