/[shishi]/inetutils/libinetutils/shishi.c
ViewVC logotype

Diff of /inetutils/libinetutils/shishi.c

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

revision 1.5 by npo, Fri Sep 19 19:45:29 2003 UTC revision 1.6 by npo, Wed Sep 24 15:17:58 2003 UTC
# Line 227  void senderror (int s, char type, char * Line 227  void senderror (int s, char type, char *
227  }  }
228    
229  int  int
230  get_auth (int infd, Shishi ** handle, Shishi_key ** enckey, const char **err_msg, int * protoversion)  get_auth (int infd, Shishi ** handle, Shishi_key ** enckey, const char ** err_msg, int * protoversion
231              /*int * cksumtype, char * cksum, int * cksumlen*/)
232  {  {
233    Shishi_key *key;    Shishi_key *key;
234    Shishi_ap *ap;    Shishi_ap *ap;
# Line 397  get_auth (int infd, Shishi ** handle, Sh Line 398  get_auth (int infd, Shishi ** handle, Sh
398        
399  #endif  #endif
400    
401      /* Get authenticator checksum */
402      /*  rc = shishi_authenticator_cksum (*handle, shishi_ap_authenticator (ap), cksumtype, cksum, cksumlen);
403      if (rc != SHISHI_OK)
404        {
405          syslog (LOG_ERR, "Could not get checksum authenticator from AP-REQ: %s\n", shishi_strerror (rc));
406          return 1;
407        }
408      */
409    
410    /* User is authenticated. */    /* User is authenticated. */
411    error = 0;    error = 0;
412    write (infd, &error, sizeof (int));    write (infd, &error, sizeof (int));
# Line 470  readenc (Shishi * h, int sock, char *buf Line 480  readenc (Shishi * h, int sock, char *buf
480  {  {
481    char * out;    char * out;
482    char * outbis;    char * outbis;
   char * iv2;  
483    
484    int rc;    int rc;
485    int val;    int val;
# Line 501  readenc (Shishi * h, int sock, char *buf Line 510  readenc (Shishi * h, int sock, char *buf
510      case SHISHI_AES256_CTS_HMAC_SHA1_96:      case SHISHI_AES256_CTS_HMAC_SHA1_96:
511        dlen += 4 + hashsize + blocksize;        dlen += 4 + hashsize + blocksize;
512        break;        break;
     case SHISHI_DES3_CBC_HMAC_SHA1_KD:  
513      case SHISHI_ARCFOUR_HMAC:      case SHISHI_ARCFOUR_HMAC:
514      case SHISHI_ARCFOUR_HMAC_EXP:      case SHISHI_ARCFOUR_HMAC_EXP:
515        dlen += 2*blocksize - 1;        dlen += 4 + 8 + blocksize -1;
       if (proto == 2)  
         dlen += 4;  
516        dlen /= blocksize;        dlen /= blocksize;
517        dlen *= blocksize;        dlen *= blocksize;
518        dlen += hashsize;        dlen += hashsize;
519        break;        break;
520        case SHISHI_DES3_CBC_HMAC_SHA1_KD:
521          dlen += 4 + 2*blocksize - 1;
522          dlen /= blocksize;
523          dlen *= blocksize;
524          dlen += hashsize;
525          break;
526        case SHISHI_DES_CBC_CRC:
527          dlen += 2*blocksize -1;
528          if (proto == 2)
529            dlen += 4;
530          dlen += hashsize;
531          dlen /= blocksize;
532          dlen *= blocksize;
533          break;
534      default:      default:
535        dlen += blocksize - 1;        dlen += blocksize - 1;
536        if (proto == 2)        if (proto == 2)
# Line 521  readenc (Shishi * h, int sock, char *buf Line 541  readenc (Shishi * h, int sock, char *buf
541        break;        break;
542      }      }
543    
   syslog(LOG_ERR, "vla = %d", dlen);  
544    /* read encrypted data */    /* read encrypted data */
545    outbis = (char *)xmalloc (dlen);    outbis = (char *)xmalloc (dlen);
546    if (outbis == NULL)    if (outbis == NULL)
# Line 553  readenc (Shishi * h, int sock, char *buf Line 572  readenc (Shishi * h, int sock, char *buf
572        val = 0;        val = 0;
573      }      }
574    else    else
575      {      {  
576        rc =        rc =
577          shishi_decrypt_ivupdate (h, enckey, iv->keyusage, iv->iv, iv->ivlen, &iv2, &iv->ivlen, outbis,          shishi_crypto_decrypt (iv->ctx, outbis, dlen, &out, &outlen);
                              dlen, &out, &outlen);  
578        if (rc != SHISHI_OK)        if (rc != SHISHI_OK)
579          {          {
580            printf ("decryption error\n");            printf ("decryption error\n");
581            free (outbis);            free (outbis);
582            return 1;            return 1;
583          }          }
584              
585        /* in KCMDV0.2 first 4 bytes of decrypted data = len of data */        /* in KCMDV0.2 first 4 bytes of decrypted data = len of data */
586        *len = ntohl (*((int *) out));        *len = ntohl (*((int *) out));
587        val = sizeof (int);        val = sizeof (int);
   
       /* update iv */  
       memcpy (iv->iv, iv2, iv->ivlen);  
588      }      }
589    
590    memset (buf, 0, BUFLEN);    memset (buf, 0, BUFLEN);
# Line 590  writeenc (Shishi * h, int sock, char *bu Line 605  writeenc (Shishi * h, int sock, char *bu
605  {  {
606    char *out;    char *out;
607    char *bufbis;    char *bufbis;
608      
   char *iv2;  
   
609    int rc;    int rc;
610    int dlen, outlen;    int dlen, outlen;
611    
   int i;  
   
612    dlen = wlen;    dlen = wlen;
613    dlen = htonl (dlen);    dlen = htonl (dlen);
614    
# Line 607  writeenc (Shishi * h, int sock, char *bu Line 618  writeenc (Shishi * h, int sock, char *bu
618        bufbis = (char *)xmalloc (wlen + sizeof (int));        bufbis = (char *)xmalloc (wlen + sizeof (int));
619        memcpy (bufbis, (char *) &dlen, sizeof (int));        memcpy (bufbis, (char *) &dlen, sizeof (int));
620        memcpy (bufbis + sizeof (int), buf, wlen);        memcpy (bufbis + sizeof (int), buf, wlen);
621          
622        /* encrypt it */        /* encrypt it */
623        rc =        rc =
624          shishi_encrypt_ivupdate (h, enckey, iv->keyusage, iv->iv, iv->ivlen, &iv2, &iv->ivlen, bufbis,          shishi_crypto_encrypt (iv->ctx, bufbis, wlen + sizeof (int), &out, &outlen);
                                  wlen + sizeof (int), &out, &outlen);  
625      }      }
626    else    else
627      {      {
# Line 620  writeenc (Shishi * h, int sock, char *bu Line 630  writeenc (Shishi * h, int sock, char *bu
630            
631        /* data to encrypt = size + data */        /* data to encrypt = size + data */
632        rc =        rc =
633          shishi_encrypt (h, enckey, iv->keyusage, bufbis, wlen, &out, &outlen);              shishi_encrypt (h, enckey, iv->keyusage, bufbis, wlen, &out, &outlen);
634      }      }
635    
636    if (rc != SHISHI_OK)    if (rc != SHISHI_OK)
# Line 639  writeenc (Shishi * h, int sock, char *bu Line 649  writeenc (Shishi * h, int sock, char *bu
649    
650    *len = wlen;    *len = wlen;
651    
   if (proto == 2)  
     {  
       /* update iv */  
       memcpy (iv->iv, iv2, iv->ivlen);  
     }  
   
652    free (out);    free (out);
653    
654    return SHISHI_OK;    return SHISHI_OK;

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