/[shishi]/inetutils/libtelnet/enc_des.c
ViewVC logotype

Diff of /inetutils/libtelnet/enc_des.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jas, Fri Sep 12 16:22:49 2003 UTC revision 1.2 by npo, Fri Sep 26 15:16:56 2003 UTC
# Line 37  static char sccsid[] = "@(#)enc_des.c  8. Line 37  static char sccsid[] = "@(#)enc_des.c  8.
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
# Line 74  struct fb { Line 78  struct fb {
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;
# Line 119  static void fb64_session P((Session_Key Line 123  static void fb64_session P((Session_Key
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  {  {
# Line 215  fb64_start(fbp, dir, server) Line 230  fb64_start(fbp, dir, server)
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++;
# Line 428  fb64_session(key, server, fbp) Line 450  fb64_session(key, server, fbp)
450          fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]);          fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]);
451    
452          if (fbp->once == 0) {          if (fbp->once == 0) {
453    #ifndef SHISHI
454                  des_set_random_generator_seed(fbp->krbdes_key);                  des_set_random_generator_seed(fbp->krbdes_key);
455    #endif
456                  fbp->once = 1;                  fbp->once = 1;
457          }          }
458    #ifndef SHISHI
459          des_key_sched(fbp->krbdes_key, fbp->krbdes_sched);          des_key_sched(fbp->krbdes_key, fbp->krbdes_sched);
460    #endif
461          /*          /*
462           * Now look to see if krbdes_start() was was waiting for           * Now look to see if krbdes_start() was was waiting for
463           * 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
# Line 552  fb64_stream_iv(seed, stp) Line 578  fb64_stream_iv(seed, stp)
578          memmove((void *)stp->str_iv, (void *)seed, sizeof(Block));          memmove((void *)stp->str_iv, (void *)seed, sizeof(Block));
579          memmove((void *)stp->str_output, (void *)seed, sizeof(Block));          memmove((void *)stp->str_output, (void *)seed, sizeof(Block));
580    
581    #ifndef SHISHI
582          des_key_sched(stp->str_ikey, stp->str_sched);          des_key_sched(stp->str_ikey, stp->str_sched);
583    #endif
584    
585          stp->str_index = sizeof(Block);          stp->str_index = sizeof(Block);
586  }  }
# Line 563  fb64_stream_key(key, stp) Line 591  fb64_stream_key(key, stp)
591          register struct stinfo *stp;          register struct stinfo *stp;
592  {  {
593          memmove((void *)stp->str_ikey, (void *)key, sizeof(Block));          memmove((void *)stp->str_ikey, (void *)key, sizeof(Block));
594    #ifndef SHISHI
595          des_key_sched(key, stp->str_sched);          des_key_sched(key, stp->str_sched);
596    #endif
597          memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block));          memmove((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block));
598    
599          stp->str_index = sizeof(Block);          stp->str_index = sizeof(Block);
# Line 604  cfb64_encrypt(s, c) Line 633  cfb64_encrypt(s, c)
633          while (c-- > 0) {          while (c-- > 0) {
634                  if (index == sizeof(Block)) {                  if (index == sizeof(Block)) {
635                          Block b;                          Block b;
636    #ifdef SHISHI
637                            shishi_des_ecb_encrypt (shishi_handle, fb[CFB].krbdes_key,
638                                                    stp->str_output, b);
639    #else
640                          des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);                          des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);
641    #endif
642                          memmove((void *)stp->str_feed, (void *)b, sizeof(Block));                          memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
643                          index = 0;                          index = 0;
644                  }                  }
# Line 638  cfb64_decrypt(data) Line 672  cfb64_decrypt(data)
672          index = stp->str_index++;          index = stp->str_index++;
673          if (index == sizeof(Block)) {          if (index == sizeof(Block)) {
674                  Block b;                  Block b;
675    #ifdef SHISHI
676                    shishi_des_ecb_encrypt (shishi_handle, fb[CFB].krbdes_key,
677                                            stp->str_output, b);
678    #else
679                  des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);                  des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);
680    #endif
681                  memmove((void *)stp->str_feed, (void *)b, sizeof(Block));                  memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
682                  stp->str_index = 1;     /* Next time will be 1 */                  stp->str_index = 1;     /* Next time will be 1 */
683                  index = 0;              /* But now use 0 */                  index = 0;              /* But now use 0 */
# Line 680  ofb64_encrypt(s, c) Line 719  ofb64_encrypt(s, c)
719          while (c-- > 0) {          while (c-- > 0) {
720                  if (index == sizeof(Block)) {                  if (index == sizeof(Block)) {
721                          Block b;                          Block b;
722    #ifdef SHISHI
723                            shishi_des_ecb_encrypt (shishi_handle, fb[OFB].krbdes_key,
724                                                    stp->str_feed, b);
725    #else
726                          des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);                          des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);
727    #endif
728                          memmove((void *)stp->str_feed, (void *)b, sizeof(Block));                          memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
729                          index = 0;                          index = 0;
730                  }                  }
# Line 711  ofb64_decrypt(data) Line 755  ofb64_decrypt(data)
755          index = stp->str_index++;          index = stp->str_index++;
756          if (index == sizeof(Block)) {          if (index == sizeof(Block)) {
757                  Block b;                  Block b;
758    #ifdef SHISHI
759                    shishi_des_ecb_encrypt (shishi_handle, fb[OFB].krbdes_key,
760                                            stp->str_feed, b);
761    #else
762                  des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);                  des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);
763    #endif
764                  memmove((void *)stp->str_feed, (void *)b, sizeof(Block));                  memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
765                  stp->str_index = 1;     /* Next time will be 1 */                  stp->str_index = 1;     /* Next time will be 1 */
766                  index = 0;              /* But now use 0 */                  index = 0;              /* But now use 0 */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26