37 |
|
|
38 |
#ifdef ENCRYPTION |
#ifdef ENCRYPTION |
39 |
# ifdef AUTHENTICATION |
# ifdef AUTHENTICATION |
40 |
# ifdef DES_ENCRYPTION |
# if defined (DES_ENCRYPTION) || defined (SHISHI) |
41 |
|
#ifdef SHISHI |
42 |
|
#include <shishi.h> |
43 |
|
extern Shishi * shishi_handle; |
44 |
|
#endif |
45 |
#include <arpa/telnet.h> |
#include <arpa/telnet.h> |
46 |
#include <stdio.h> |
#include <stdio.h> |
47 |
#ifdef HAVE_STDLIB_H |
#ifdef HAVE_STDLIB_H |
78 |
Block str_output; |
Block str_output; |
79 |
Block str_feed; |
Block str_feed; |
80 |
Block str_iv; |
Block str_iv; |
81 |
Block str_ikey; |
Block str_ikey; |
82 |
Schedule str_sched; |
Schedule str_sched; |
83 |
int str_index; |
int str_index; |
84 |
int str_flagshift; |
int str_flagshift; |
123 |
void fb64_stream_key P((Block, struct stinfo *)); |
void fb64_stream_key P((Block, struct stinfo *)); |
124 |
int fb64_keyid P((int, unsigned char *, int *, struct fb *)); |
int fb64_keyid P((int, unsigned char *, int *, struct fb *)); |
125 |
|
|
126 |
void |
#ifdef SHISHI |
127 |
|
void shishi_des_ecb_encrypt (Shishi * h, const char key[8], const char * in, char * out) |
128 |
|
{ |
129 |
|
char * tmp; |
130 |
|
|
131 |
|
shishi_des (h, 0, key, NULL, NULL, in, 8, &tmp); |
132 |
|
memcpy (out, tmp, 8); |
133 |
|
free (tmp); |
134 |
|
} |
135 |
|
#endif |
136 |
|
|
137 |
|
void |
138 |
cfb64_init(server) |
cfb64_init(server) |
139 |
int server; |
int server; |
140 |
{ |
{ |
230 |
/* |
/* |
231 |
* Create a random feed and send it over. |
* Create a random feed and send it over. |
232 |
*/ |
*/ |
233 |
|
#ifdef SHISHI |
234 |
|
if (shishi_randomize (shishi_handle, 0, |
235 |
|
fbp->temp_feed, 8) != SHISHI_OK) |
236 |
|
return(FAILED); |
237 |
|
|
238 |
|
#else |
239 |
des_new_random_key(fbp->temp_feed); |
des_new_random_key(fbp->temp_feed); |
240 |
des_ecb_encrypt(fbp->temp_feed, fbp->temp_feed, |
des_ecb_encrypt(fbp->temp_feed, fbp->temp_feed, |
241 |
fbp->krbdes_sched, 1); |
fbp->krbdes_sched, 1); |
242 |
|
#endif |
243 |
p = fbp->fb_feed + 3; |
p = fbp->fb_feed + 3; |
244 |
*p++ = ENCRYPT_IS; |
*p++ = ENCRYPT_IS; |
245 |
p++; |
p++; |
439 |
{ |
{ |
440 |
|
|
441 |
if (!key || key->type != SK_DES) { |
if (!key || key->type != SK_DES) { |
442 |
|
/* FIXME: Support RFC 2952 approach instead of giving up here. */ |
443 |
if (encrypt_debug_mode) |
if (encrypt_debug_mode) |
444 |
printf("Can't set krbdes's session key (%d != %d)\r\n", |
printf("Can't set krbdes's session key (%d != %d)\r\n", |
445 |
key ? key->type : -1, SK_DES); |
key ? key->type : -1, SK_DES); |
451 |
fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]); |
fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]); |
452 |
|
|
453 |
if (fbp->once == 0) { |
if (fbp->once == 0) { |
454 |
|
#ifndef SHISHI |
455 |
des_set_random_generator_seed(fbp->krbdes_key); |
des_set_random_generator_seed(fbp->krbdes_key); |
456 |
|
#endif |
457 |
fbp->once = 1; |
fbp->once = 1; |
458 |
} |
} |
459 |
|
#ifndef SHISHI |
460 |
des_key_sched(fbp->krbdes_key, fbp->krbdes_sched); |
des_key_sched(fbp->krbdes_key, fbp->krbdes_sched); |
461 |
|
#endif |
462 |
/* |
/* |
463 |
* Now look to see if krbdes_start() was was waiting for |
* Now look to see if krbdes_start() was was waiting for |
464 |
* the key to show up. If so, go ahead an call it now |
* the key to show up. If so, go ahead an call it now |
579 |
memmove((void *)stp->str_iv, (void *)seed, sizeof(Block)); |
memmove((void *)stp->str_iv, (void *)seed, sizeof(Block)); |
580 |
memmove((void *)stp->str_output, (void *)seed, sizeof(Block)); |
memmove((void *)stp->str_output, (void *)seed, sizeof(Block)); |
581 |
|
|
582 |
|
#ifndef SHISHI |
583 |
des_key_sched(stp->str_ikey, stp->str_sched); |
des_key_sched(stp->str_ikey, stp->str_sched); |
584 |
|
#endif |
585 |
|
|
586 |
stp->str_index = sizeof(Block); |
stp->str_index = sizeof(Block); |
587 |
} |
} |
592 |
register struct stinfo *stp; |
register struct stinfo *stp; |
593 |
{ |
{ |
594 |
memmove((void *)stp->str_ikey, (void *)key, sizeof(Block)); |
memmove((void *)stp->str_ikey, (void *)key, sizeof(Block)); |
595 |
|
#ifndef SHISHI |
596 |
des_key_sched(key, stp->str_sched); |
des_key_sched(key, stp->str_sched); |
597 |
|
#endif |
598 |
memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block)); |
memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block)); |
599 |
|
|
600 |
stp->str_index = sizeof(Block); |
stp->str_index = sizeof(Block); |
634 |
while (c-- > 0) { |
while (c-- > 0) { |
635 |
if (index == sizeof(Block)) { |
if (index == sizeof(Block)) { |
636 |
Block b; |
Block b; |
637 |
|
#ifdef SHISHI |
638 |
|
shishi_des_ecb_encrypt (shishi_handle, fb[CFB].krbdes_key, |
639 |
|
stp->str_output, b); |
640 |
|
#else |
641 |
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1); |
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1); |
642 |
|
#endif |
643 |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
644 |
index = 0; |
index = 0; |
645 |
} |
} |
673 |
index = stp->str_index++; |
index = stp->str_index++; |
674 |
if (index == sizeof(Block)) { |
if (index == sizeof(Block)) { |
675 |
Block b; |
Block b; |
676 |
|
#ifdef SHISHI |
677 |
|
shishi_des_ecb_encrypt (shishi_handle, fb[CFB].krbdes_key, |
678 |
|
stp->str_output, b); |
679 |
|
#else |
680 |
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1); |
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1); |
681 |
|
#endif |
682 |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
683 |
stp->str_index = 1; /* Next time will be 1 */ |
stp->str_index = 1; /* Next time will be 1 */ |
684 |
index = 0; /* But now use 0 */ |
index = 0; /* But now use 0 */ |
720 |
while (c-- > 0) { |
while (c-- > 0) { |
721 |
if (index == sizeof(Block)) { |
if (index == sizeof(Block)) { |
722 |
Block b; |
Block b; |
723 |
|
#ifdef SHISHI |
724 |
|
shishi_des_ecb_encrypt (shishi_handle, fb[OFB].krbdes_key, |
725 |
|
stp->str_feed, b); |
726 |
|
#else |
727 |
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1); |
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1); |
728 |
|
#endif |
729 |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
730 |
index = 0; |
index = 0; |
731 |
} |
} |
756 |
index = stp->str_index++; |
index = stp->str_index++; |
757 |
if (index == sizeof(Block)) { |
if (index == sizeof(Block)) { |
758 |
Block b; |
Block b; |
759 |
|
#ifdef SHISHI |
760 |
|
shishi_des_ecb_encrypt (shishi_handle, fb[OFB].krbdes_key, |
761 |
|
stp->str_feed, b); |
762 |
|
#else |
763 |
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1); |
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1); |
764 |
|
#endif |
765 |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
memmove((void *)stp->str_feed, (void *)b, sizeof(Block)); |
766 |
stp->str_index = 1; /* Next time will be 1 */ |
stp->str_index = 1; /* Next time will be 1 */ |
767 |
index = 0; /* But now use 0 */ |
index = 0; /* But now use 0 */ |