| 1 | /* |
| 2 | ** Copyright 2002 Double Precision, Inc. |
| 3 | ** See COPYING for distribution information. |
| 4 | */ |
| 5 | |
| 6 | #if HAVE_CONFIG_H |
| 7 | #include "config.h" |
| 8 | #endif |
| 9 | |
| 10 | #if HAVE_UNISTD_H |
| 11 | #include <unistd.h> |
| 12 | #endif |
| 13 | #include <ctype.h> |
| 14 | #include <string.h> |
| 15 | #include "random128.h" |
| 16 | |
| 17 | |
| 18 | static int nyb(char c) |
| 19 | { |
| 20 | static const char xdigit[]="0123456789ABCDEF"; |
| 21 | |
| 22 | const char *p=strchr(xdigit, c); |
| 23 | |
| 24 | if (p) |
| 25 | return (p-xdigit); |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | void random128_binary(random128binbuf *bytes) |
| 30 | { |
| 31 | char randombuf[ 128 / 8 * 2 + 1]; |
| 32 | int i; |
| 33 | |
| 34 | strcpy(randombuf, random128()); |
| 35 | |
| 36 | for (i=0; i<128/8; i++) |
| 37 | (*bytes)[i]=(nyb(randombuf[i*2]) << 4) | nyb(randombuf[i*2+1]); |
| 38 | } |