home *** CD-ROM | disk | FTP | other *** search
/ CD-X 1 / cdx_01.iso / shareuti / secdev13 / source / login.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-02  |  4.0 KB  |  159 lines

  1. /* This file is a part of SecureDevice 1.3
  2.    Copyright (C) 1994 by Max Loewenthal and Arthur Helwig
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2 of the License, or
  6.    (at your option) any later version.
  7.  
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <conio.h>
  21. #include <bios.h>
  22. #include <dos.h>
  23. #include <string.h>
  24. #include <ctype.h>
  25. #include "md5.h"
  26. #include "usuals.h"
  27. #include "globals.h"
  28.  
  29. void invgets(char *input);   /* Get without displaying, allow backspace */
  30.  
  31. #define KEYLEN  KeySize/2    /* length of key schedule in 16-bit words */
  32. #define MinorName "LOGIN"
  33. #define MinorVer "1.01"
  34.  
  35. void invgets(char *input)
  36. { unsigned i=0;
  37.   char c;
  38.   while(i<(MaxPwdLen-1))
  39.     { c=getch();
  40.       if(c=='\x0d')
  41.         { printf("\n");
  42.           *input='\0';
  43.           return;
  44.         }
  45.       if(c=='\b')
  46.         { if(i>0)
  47.            { i--;
  48.              input--;
  49.              printf("\b \b");
  50.            }
  51.         }
  52.       else
  53.        { printf("*");
  54.          *input++=c;
  55.          i++;
  56.        }
  57.     }
  58.   }
  59.  
  60. void md5key(unsigned char signature[16],char *pass1)
  61. { MD5_CTX md5buf;
  62.  
  63.   MD5Init(&md5buf);
  64.   MD5Update(&md5buf,pass1,strlen(pass1));
  65.   MD5Final(signature,&md5buf);
  66. }
  67.  
  68. /*      Compute IDEA encryption subkeys Z */
  69. void en_key_idea(word16 *userkey, word16 *Z)
  70. { unsigned i,j;
  71.   word16 *Y=Z;
  72.     /*
  73.      * shifts
  74.      */
  75.   for (j=0; j<8; j++)
  76.     Z[j] = *userkey++;
  77.  
  78.   for (i=0; j<KEYLEN; j++)
  79.     { i++;
  80.       Z[i+7] = Z[i & 7] << 9 | Z[i+1 & 7] >> 7;
  81.       Z += i & 8;
  82.       i &= 7;
  83.     }
  84.   for(i=0;i<KEYLEN;i++)
  85.     Y[i]^=0x0dae;
  86. }        /* en_key_idea */
  87.  
  88. void main(int argc,char *argv[])
  89. { unsigned char key[16],passphrase[MaxPwdLen];
  90.   word16 expkey[KEYLEN];
  91.   int i,nofdrivers;
  92.   unsigned char Driveletter='\0';
  93.   char DriveOK=0;
  94.   union REGS regs;
  95.   struct SREGS segregs;
  96.  
  97.   printf("%s %s's %s %s\n",MajorName,MajorVer,MinorName,MinorVer);
  98.   printf("Written by %s\n",AuthorName);
  99.  
  100.   regs.x.ax = 0xE209;
  101.   regs.x.dx = 0;
  102.   int86x(0x2F, ®s, ®s, &segregs);
  103.   if(regs.x.ax != 0x1DEA)
  104.     { printf("SECDEV.SYS not loaded\n");
  105.       exit(1);
  106.     }
  107.   nofdrivers=regs.x.dx;
  108.  
  109.   if(argc>1)
  110.     Driveletter=toupper(*argv[1]);
  111.  
  112.   if(Driveletter)
  113.       for(i=0;i<nofdrivers && !DriveOK;i++)
  114.         { regs.x.ax = 0xE201;            /* Get information */
  115.           regs.x.dx = i;
  116.           int86x(0x2F, ®s, ®s, &segregs);
  117.  
  118.           DriveOK = ((Driveletter-'A') >= regs.h.dl) &&
  119.                     ((Driveletter-'A') < regs.h.dl+regs.h.al);
  120.         } else
  121.         { regs.x.ax = 0xE201;
  122.           regs.x.dx = 0;     /* Use 1st driver in mem */
  123.           int86x(0x2F, ®s, ®s, &segregs);
  124.  
  125.           DriveOK=1;
  126.           Driveletter=regs.h.dl+'A';
  127.         }
  128.   if (!DriveOK)
  129.     { printf("Drive %c: is not an encrypted drive\n",Driveletter);
  130.       exit(1);
  131.     }
  132.  
  133.   if(argc>2)
  134.     { printf("\nLogging in to drive %c:\n",Driveletter);
  135.       for(i=0;argv[2][i];i++)
  136.         { passphrase[i]=argv[2][i];
  137.           argv[2][i]='\0';
  138.         }
  139.       passphrase[i]='\0';
  140.     } else
  141.     { printf("\nEnter passphrase for drive %c: ",Driveletter);
  142.       invgets(passphrase);
  143.     }
  144.  
  145.   md5key(key,passphrase);
  146.   burn(passphrase);
  147.   en_key_idea((word16 *) key,expkey);
  148.  
  149.   regs.x.ax = 0xE200;
  150.   regs.h.dl = Driveletter-'A';
  151.   regs.x.si = FP_OFF(expkey);
  152.   segregs.ds = FP_SEG(expkey);
  153.   int86x(0x2F, ®s, ®s, &segregs);
  154.  
  155.   burn(expkey);
  156.  
  157.   exit(0);
  158. }
  159.