Back to index

courier  0.68.2
Typedefs | Functions
random128.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef unsigned char random128binbuf [16]

Functions

const char * random128 ()
const char * random128_alpha ()
void random128_binary (random128binbuf *)

Typedef Documentation

typedef unsigned char random128binbuf[16]

Definition at line 33 of file random128.h.


Function Documentation

const char* random128 ( )

Definition at line 29 of file random128.c.

{
static char randombuf[sizeof(MD5_DIGEST)*2+1];

#ifdef RANDOM
       {
       int    fd=open(RANDOM, O_RDONLY);
       char   buf2[sizeof(MD5_DIGEST)];
       int    i;

              if (fd >= 0)
              {
                     if (read(fd, buf2, sizeof(buf2)) == sizeof(buf2))
                     {
                            for (i=0; i<sizeof(buf2); i++)
                                   sprintf(randombuf+i*2,
                                          "%02X",
                                          (int)(unsigned char)buf2[i]);
                            close(fd);
                            return (randombuf);
                     }
                     close(fd);
              }
       }
#endif

       /* /dev/urandom not available or broken?  Create some noise */

       {
       int pipefd[2];
       int s;
       char   buf[512];
       struct MD5_CONTEXT context;
       MD5_DIGEST    digest;
       int    n;
       time_t t;
       pid_t  p, p2;
       unsigned long l;

              time(&t);
              p=getpid();

              if (pipe(pipefd))    return (0);
              while ((p=fork()) == -1)
              {
                     sleep (5);
              }
              if (p == 0)
              {
                     dup2(pipefd[1], 1);
                     dup2(pipefd[1], 2);
                     close(pipefd[0]);
                     close(pipefd[1]);

#ifdef W
                     while ((p=fork()) == -1)
                     {
                            sleep (5);
                     }
                     if (p == 0)
                     {
                            execl(W, W, (char *)0);
                            perror(W);
                            _exit(0);
                     }
                     while (wait(&s) >= 0)
                            ;
#endif

                     execl(PS, PS, PS_OPTIONS, (char *)0);
                     perror(PS);
                     _exit(0);
              }
              close(pipefd[1]);
              md5_context_init(&context);
              md5_context_hashstream(&context, &t, sizeof(t));
              md5_context_hashstream(&context, &p, sizeof(p));
              l=sizeof(t)+sizeof(p);

              while ((n=read(pipefd[0], buf, sizeof(buf))) > 0)
              {
                     md5_context_hashstream(&context, buf, n);
                     l += n;
              }
              md5_context_endstream(&context, l);
              md5_context_digest(&context, digest);
              close(pipefd[0]);
              while ((p2=wait(&s)) >= 0 && p != p2)
                     ;

              for (n=0; n<sizeof(digest); n++)
                     sprintf(randombuf+n*2,
                            "%02X", (int)(unsigned char)digest[n]);
       }

       return (randombuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* random128_alpha ( )

Definition at line 18 of file random128alpha.c.

{
static char randombuf[ 128 / 8 * 2 + 1];
char *p;

       strcpy(randombuf, random128());

       for (p=randombuf; *p; p++)
              if ( isdigit((int)(unsigned char)*p))
                     *p= "GHIJKLMNOP"[ *p - '0' ];
       return (randombuf);
}

Here is the call graph for this function:

Definition at line 29 of file random128binary.c.

{
       char randombuf[ 128 / 8 * 2 + 1];
       int i;

       strcpy(randombuf, random128());

       for (i=0; i<128/8; i++)
              (*bytes)[i]=(nyb(randombuf[i*2]) << 4) | nyb(randombuf[i*2+1]);
}

Here is the call graph for this function:

Here is the caller graph for this function: