|
| 1 | +/* LibTomCrypt, modular cryptographic library -- Tom St Denis |
| 2 | + * |
| 3 | + * LibTomCrypt is a library that provides various cryptographic |
| 4 | + * algorithms in a highly modular and flexible manner. |
| 5 | + * |
| 6 | + * The library is free for all purposes without any express |
| 7 | + * gurantee it works. |
| 8 | + * |
| 9 | + * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org |
| 10 | + */ |
1 | 11 | /* portable way to get secure random bits to feed a PRNG */ |
2 | 12 | #include "mycrypt.h" |
3 | 13 |
|
@@ -35,45 +45,8 @@ static unsigned long rng_nix(unsigned char *buf, unsigned long len, |
35 | 45 |
|
36 | 46 | #endif /* DEVRANDOM */ |
37 | 47 |
|
38 | | -#ifdef SONY_PS2 |
39 | | -#include <eetypes.h> |
40 | | -#include <eeregs.h> |
41 | | -#define min(a,b) ((a) < (b) ? (a) : (b)) |
42 | | -// Very simple/stupid MD5-based RNG that samples "entropy" from various PS2 control registers |
43 | | -static unsigned long rng_ps2(unsigned char *buf, unsigned long len, |
44 | | - void (*callback)(void)) |
45 | | -{ |
46 | | - static unsigned long lastx[2] = { 0xaab7cb4b2fd3b2b9, 0xcec58aff72afe49f }; // md5sum of bits.c |
47 | | - unsigned long j; |
48 | | - unsigned int samples[10]; // number of sample data sources |
49 | | - int l; |
50 | | - hash_state md; |
51 | | - |
52 | | - for (j = 0; j < len; j += sizeof(lastx)) { |
53 | | - md5_init(&md); |
54 | | - samples[0] = *T2_COUNT; |
55 | | - samples[1] = *T3_COUNT; |
56 | | - samples[2] = *IPU_TOP; |
57 | | - samples[3] = *GIF_TAG0; |
58 | | - samples[4] = *GIF_TAG1; |
59 | | - samples[5] = *GIF_TAG2; |
60 | | - samples[6] = *VIF1_CODE; |
61 | | - samples[7] = *VIF0_CODE; |
62 | | - samples[8] = *D0_MADR; |
63 | | - samples[9] = *D1_MADR; |
64 | | - md5_process(&md, (unsigned char *)(&samples[0]), sizeof(samples)); |
65 | | - // include previous round |
66 | | - md5_process(&md, (unsigned char *)(&lastx[0]), sizeof(lastx)); |
67 | | - md5_done(&md, (unsigned char *)(&lastx[0])); |
68 | | - l = min(sizeof(lastx), len-j); |
69 | | - memcpy(buf+j, &lastx[0], l); //min(sizeof(lastx), len-j)); |
70 | | - } |
71 | | - return len; |
72 | | -} |
73 | | -#endif /* SONY_PS2 */ |
74 | | - |
75 | 48 | /* on ANSI C platforms with 100 < CLOCKS_PER_SEC < 10000 */ |
76 | | -#if !defined(SONY_PS2) && defined(CLOCKS_PER_SEC) |
| 49 | +#if defined(CLOCKS_PER_SEC) |
77 | 50 |
|
78 | 51 | #define ANSI_RNG |
79 | 52 |
|
@@ -143,9 +116,7 @@ unsigned long rng_get_bytes(unsigned char *buf, unsigned long len, |
143 | 116 |
|
144 | 117 | _ARGCHK(buf != NULL); |
145 | 118 |
|
146 | | -#ifdef SONY_PS2 |
147 | | - x = rng_ps2(buf, len, callback); if (x != 0) { return x; } |
148 | | -#elif defined(DEVRANDOM) |
| 119 | +#if defined(DEVRANDOM) |
149 | 120 | x = rng_nix(buf, len, callback); if (x != 0) { return x; } |
150 | 121 | #endif |
151 | 122 | #ifdef WIN32 |
|
0 commit comments