home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / sci / crypt / 3247 < prev    next >
Encoding:
Text File  |  1992-09-15  |  7.7 KB  |  284 lines

  1. Path: sparky!uunet!cs.utexas.edu!torn!cunews!revcan!micor!uuisis!tanda!marc
  2. From: marc@tanda.isis.org (Marc Thibault)
  3. Reply-To: marc@tanda.isis.org
  4. Newsgroups: sci.crypt
  5. Subject: Re: Secure password generation
  6. Message-ID: <256379411DN5.61R@tanda.isis.org>
  7. References: <1992Sep12.020756.17214@morwyn.uucp>
  8. Date: Mon, 14 Sep 92 10:19:15 EDT
  9. Distribution: na
  10. Organization: Thibault & Friends
  11. Lines: 265
  12.  
  13. In article <1992Sep12.020756.17214@morwyn.uucp> 
  14. (Forrie Aldrich) writes: 
  15. > I'm seeking a program/method which will generate pronounceable passwords,
  16. > securely.  Meaning the process by which the actual password is generated
  17. > should be genuinely random enough so an attack at the algorithm (by
  18. > whatever means) would be infeasable.
  19.  
  20.         The C program listed below may be what Forrie is looking for,
  21.         but it needs a cryptographically strong RNG to replace
  22.         qrand().  Maybe one of our experts can post one??
  23.  
  24. ----------------- START CODE -------------------------------------------
  25. /* babble.c
  26.     A program to generate random pronounceable words to be
  27.     used as passwords.
  28.     
  29. Author:     Marc Thibault
  30. Created:    17 January 1988
  31.     
  32. Synopsis:
  33.     BABBLE [text]
  34.  
  35. Description:
  36.     BABBLE, sends 64 random words to STDOUT, each 8 followed by 
  37.     a newline. If the optional [text] argument is provided, the
  38.     argument is used to initialize the random seed. The same argument
  39.     will result in the same words on successive calls.
  40.     
  41.     The word generation is done through a set of arrays which 
  42.     implement a strategy for pronounceability. This improves the 
  43.     mnemonic value of the words without sacrificing randomness
  44.     to any significant degree.
  45.  
  46. Subroutines:
  47.     putns(c)                add character to word
  48.     qrand(a)                random integer between 0 and (a-1)
  49.     putSel(a,b)                add element to word
  50.     selectStrategy ()        random row from strategy matrix
  51.     doSel(n)                add element from set to word
  52.     makeWord()                create random word
  53.     int utime()                return unsigned int function of time
  54.  
  55. /*------------------------------------------------------------------*/
  56.  
  57.  
  58. #include <stdio.h>
  59. #include <string.h>
  60. #include <time.h>
  61. #include <stdlib.h>
  62.  
  63. /*------------------------------------------------------------------*/
  64. /* Global Data Items
  65. /*------------------------------------------------------------------*/
  66.  
  67. char word[16];          /* Babble words will be assembled here      */
  68. int wordCount;          /* Count of characters in word              */
  69.  
  70.                         
  71. /*------------------------------------------------------------------*/
  72. /*            Word Elements                                         */
  73. /*------------------------------------------------------------------*/
  74.  
  75. /* Introductory consonant */
  76. char incon1[] = "bcdfghjklmnpqrstvwzsbbffpptdcst";
  77. char incon2[] = "            u      tlrlrlrrrhhh";
  78.  
  79. /* Middle Consonants      */
  80. char midcon1[] = "bbcdffghjkllmmnpqrrrsssttvnz";
  81. char midcon2[] = " s   f     l m  u mr st t w ";
  82.  
  83.  
  84. /* Ending Consonants      */
  85. char endcon1[] = "bcddfgklmnrssttvz";
  86. char endcon2[] = " k ef       t e y";
  87.  
  88. /* Vowels                 */
  89. char vowels1[] = "aeiouaeieo";
  90. char vowels2[] = "     iaaeo";
  91.  
  92.  
  93.  
  94. /*------------------------------------------------------------------*/
  95. /* put character if not space and wordCount<8                       */
  96. /* Returns 1 if character put, 0 if not                             */
  97. /*------------------------------------------------------------------*/
  98. char blank=32;
  99.  
  100. void putns(c)
  101. char c;
  102.     {
  103.     if ((c != blank)&&(wordCount<8))
  104.     word[wordCount++] = c;
  105.     }
  106.  
  107. /*------------------------------------------------------------------*/
  108. /* Return random number between 0 and argument
  109. /*  This needs a stronger RNG.
  110. /*------------------------------------------------------------------*/
  111.  
  112. int qrand(a)
  113. int a;
  114.     {
  115.     int r;
  116.     r=rand() % a;
  117.     return (r);
  118.     }
  119.  
  120.  
  121. /*------------------------------------------------------------------*/
  122. /* Put from selected array */
  123. /*------------------------------------------------------------------*/
  124.  
  125.  
  126. void putSel(a,b)
  127. char a[], b[];
  128.     {
  129.     int i;
  130.     i=qrand(strlen(a));
  131.     putns(a[i]);
  132.     putns(b[i]);
  133.     }
  134.  
  135.  
  136. /*------------------------------------------------------------------*/
  137. /* Strategy Options
  138. /* Each row is a sequence of choices representing constants
  139. /* or vowels. See doSel for interpretation. The resulting
  140. /* sequence is the template for a babble word. Greater security
  141. /* can be obtained by increasing the size of the template.
  142. /* If number of rows is changed, fix selectStrategy.
  143. /* If number of cols is changed, fix makeWord.
  144. /*------------------------------------------------------------------*/
  145.  
  146. int options[5][5]=
  147.     {
  148.     {1,2,1,4,0},            /* vowel, incon, vowel, endcon */
  149.     {1,3,1,4,0},
  150.     {2,1,3,1,0},
  151.     {2,1,4,1,0},
  152.     {2,1,3,1,4}
  153.     };
  154.  
  155. /*------------------------------------------------------------------*/
  156. /* Return a random row number into options                            */
  157. /*------------------------------------------------------------------*/
  158.  
  159. int selectStrategy ()
  160.     {
  161.     int i;
  162.     i = qrand(5);
  163.     return (i);
  164.     }
  165.  
  166.  
  167. /*------------------------------------------------------------------*/
  168. /* Handle one selection from a strategy
  169. /*------------------------------------------------------------------*/
  170. doSel(n)
  171. int n;
  172.     {
  173.     switch(n)
  174.         {
  175.         case 0:
  176.             break;
  177.         case 1:
  178.             putSel(vowels1,vowels2);
  179.             break;
  180.         case 2:
  181.             putSel(incon1,incon2);
  182.             break;
  183.         case 3:
  184.             putSel(midcon1,midcon2);    
  185.             break;
  186.         case 4:
  187.             putSel(endcon1,endcon2);
  188.             break;
  189.         }
  190.     }
  191.  
  192. /*------------------------------------------------------------------*/
  193. /* Make a word
  194. /* Fill word buffer with 5 option elements from one strategy
  195. /*------------------------------------------------------------------*/
  196.  
  197. void makeWord()
  198.     {
  199.     int s;                      /* strategy selection */
  200.     int i;                      /* strategy element */
  201.     
  202.     s=selectStrategy();            /* get a random strategy */
  203.     wordCount = 0;                /* reset word buffer */
  204.     
  205.     /* get 5 elements from selected strategy */
  206.     for (i=0; i<5; i++)  doSel(options[s][i]);
  207.     
  208.     word[wordCount]=0;            /* terminate with nul */
  209.     }
  210.  
  211. /*------------------------------------------------------------------*/
  212. /* Return daytime function as unsigned int
  213. /*------------------------------------------------------------------*/
  214.  
  215. unsigned int utime()
  216.     {
  217.     return ( (unsigned)(time(NULL)%32768) );
  218.     }
  219.  
  220. /*------------------------------------------------------------------*/
  221. /*                    MAIN PROGRAM                                    */
  222. /*------------------------------------------------------------------*/
  223.  
  224. main(argc,argv)
  225. int argc;
  226. char *argv[];
  227.     {
  228.     unsigned int i;
  229.     int j;
  230.     char *a;                /* arg string for random seed           */
  231.     unsigned int t0;            /* initial time reading
  232.     
  233.     /*--------------------------------------------------------------*/
  234.     /* Initialize Random Seed
  235.     /*  If no argument is provided: use daytime, otherwise
  236.     /*  add up bytes of argument
  237.     /*--------------------------------------------------------------*/
  238.  
  239.     if( argc<2 ) 
  240.         {    
  241.         /* Wait for time to change */
  242.         for (i=utime(); i==utime(););
  243.         
  244.         /* set seed */
  245.         srand(utime());
  246.         }
  247.         
  248.     else
  249.         {
  250.         i=0;
  251.         a=argv[1];
  252.         
  253.         /* add up bytes in argument */
  254.         for (i=0; *a != 0; i += *a++);
  255.         srand(i);
  256.         }    
  257.     
  258.  
  259.     /*--------------------------------------------------------------*/
  260.     /* Send 64 babble words to stdout */
  261.     /*--------------------------------------------------------------*/
  262.     
  263.     for (i=0;i < 8; i++)
  264.         {
  265.         for (j=0; j<8; j++)
  266.             {
  267.             makeWord();
  268.             printf("%s ",word);
  269.             }
  270.         /* CRLF */
  271.         printf("\n");
  272.         }
  273.     
  274.     /*---------------- That's All She Wrote ------------------------*/
  275.     }
  276.  
  277. ---
  278.  
  279.  Marc Thibault        |                              |  Any Warming,
  280.  marc@tanda.isis.org  |  Oxford Mills, Ontario       |  Global or otherwise,
  281.  CIS:71441,2226       |     Canada                   |   appreciated.
  282.  
  283.