Back to index

courier  0.68.2
random128binary.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2002 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #if    HAVE_CONFIG_H
00007 #include      "config.h"
00008 #endif
00009 
00010 #if    HAVE_UNISTD_H
00011 #include      <unistd.h>
00012 #endif
00013 #include      <ctype.h>
00014 #include      <string.h>
00015 #include      "random128.h"
00016 
00017 
00018 static int nyb(char c)
00019 {
00020        static const char xdigit[]="0123456789ABCDEF";
00021 
00022        const char *p=strchr(xdigit, c);
00023 
00024        if (p)
00025               return (p-xdigit);
00026        return 0;
00027 }
00028 
00029 void random128_binary(random128binbuf *bytes)
00030 {
00031        char randombuf[ 128 / 8 * 2 + 1];
00032        int i;
00033 
00034        strcpy(randombuf, random128());
00035 
00036        for (i=0; i<128/8; i++)
00037               (*bytes)[i]=(nyb(randombuf[i*2]) << 4) | nyb(randombuf[i*2+1]);
00038 }