/[inetutils]/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.5 by alainm, Thu Jul 6 04:21:08 2000 UTC revision 1.6 by gray, Tue Oct 11 11:18:51 2005 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 417  fb64_session(key, server, fbp) Line 439  fb64_session(key, server, fbp)
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);
# Line 428  fb64_session(key, server, fbp) Line 451  fb64_session(key, server, fbp)
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
# Line 552  fb64_stream_iv(seed, stp) Line 579  fb64_stream_iv(seed, stp)
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  }  }
# Line 563  fb64_stream_key(key, stp) Line 592  fb64_stream_key(key, stp)
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);
# Line 604  cfb64_encrypt(s, c) Line 634  cfb64_encrypt(s, c)
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                  }                  }
# Line 638  cfb64_decrypt(data) Line 673  cfb64_decrypt(data)
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 */
# Line 680  ofb64_encrypt(s, c) Line 720  ofb64_encrypt(s, c)
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                  }                  }
# Line 711  ofb64_decrypt(data) Line 756  ofb64_decrypt(data)
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 */

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

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