Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KCALLT uint32 debug_prng(void)
- {
- if (DPRNG->LFSR1 == 0) DPRNG->LFSR1 = 0x9D0A31FC;
- if (DPRNG->LFSR2 == 0) DPRNG->LFSR2 = 0xF91D72E9;
- if (DPRNG->LFSR3 == 0) DPRNG->LFSR3 = 0x8B90DF09;
- if (DPRNG->LFSR1_TAPS[7] != 0xFF) {
- /* {29, 26, 18, 17, 14, 8, 0xFF} */
- DPRNG->LFSR1_TAPS[0] = 29; DPRNG->LFSR1_TAPS[1] = 26;
- DPRNG->LFSR1_TAPS[2] = 18; DPRNG->LFSR1_TAPS[3] = 17;
- DPRNG->LFSR1_TAPS[4] = 14; DPRNG->LFSR1_TAPS[5] = 8;
- DPRNG->LFSR1_TAPS[6] = 0xFF;
- }
- if (DPRNG->LFSR2_TAPS[9] != 0xFF) {
- /* {30, 25, 23, 16, 15, 13, 11, 5, 0xFF} */
- DPRNG->LFSR2_TAPS[0] = 30; DPRNG->LFSR2_TAPS[1] = 25;
- DPRNG->LFSR2_TAPS[2] = 23; DPRNG->LFSR2_TAPS[3] = 16;
- DPRNG->LFSR2_TAPS[4] = 15; DPRNG->LFSR2_TAPS[5] = 13;
- DPRNG->LFSR2_TAPS[6] = 11; DPRNG->LFSR2_TAPS[7] = 5;
- DPRNG->LFSR2_TAPS[8] = 0xFF;
- }
- if (DPRNG->LFSR3_TAPS[6] != 0xFF) {
- /* {28, 24, 21, 19, 12, 0xFF} */
- DPRNG->LFSR3_TAPS[0] = 28; DPRNG->LFSR3_TAPS[1] = 24;
- DPRNG->LFSR3_TAPS[2] = 21; DPRNG->LFSR3_TAPS[3] = 19;
- DPRNG->LFSR3_TAPS[4] = 12; DPRNG->LFSR3_TAPS[5] = 0xFF;
- }
- if (DPRNG->MIXLOOPS[3] == 0) {
- /* {5, 7, 3} */
- DPRNG->MIXLOOPS[0] = 5; DPRNG->MIXLOOPS[1] = 7;
- DPRNG->MIXLOOPS[2] = 3;
- }
- uint32 rnd = 0; uint8 bit = 0, fi = 0;
- uint8 *btr = 0, *bLFSR = 0, *bMIX = 0;
- /* SHIFT LFSR1 (XOR) */
- bit = 0; btr = &DPRNG->LFSR1_TAPS[0];
- for (fi = 0; *btr != 0xFF; *btr++, fi++)
- bit = XOR(bit, DPRNG->LFSR1 >> (32 - btr[fi]));
- bit &= 0x1; DPRNG->LFSR1 = (DPRNG->LFSR1 >> 1) | (bit << 15);
- /* SHIFT LFSR2 (XNOR) */
- bit = 0; btr = &DPRNG->LFSR2_TAPS[0];
- for (fi = 0; *btr != 0xFF; *btr++, fi++)
- bit = XNOR(bit, DPRNG->LFSR2 >> (32 - btr[fi]));
- bit &= 0x1; DPRNG->LFSR2 = (DPRNG->LFSR2 >> 1) | (bit << 15);
- /* SHIFT LFSR3 (XNOR) */
- bit = 0; btr = &DPRNG->LFSR3_TAPS[0];
- for (fi = 0; *btr != 0xFF; *btr++, fi++)
- bit = XNOR(bit, DPRNG->LFSR3 >> (32 - btr[fi]));
- bit &= 0x1; DPRNG->LFSR3 = (DPRNG->LFSR3 >> 1) | (bit << 15);
- /* MIX MIX1 (LSHIFT) */
- if (DPRNG->MIX1 == 0) DPRNG->MIX1 = DPRNG->LFSR1;
- bMIX = (uint8*)&DPRNG->MIX1; bLFSR = (uint8*)&DPRNG->LFSR1;
- for (fi = 0; fi < DPRNG->MIXLOOPS[0]; fi++) {
- bMIX[0]^=bLFSR[1]<<11; bMIX[3]+=bLFSR[0]; bMIX[1]+=bMIX[2];
- bMIX[1]^=bLFSR[2]>>2; bMIX[4]+=bLFSR[1]; bMIX[2]+=bMIX[3];
- bMIX[2]^=bLFSR[3]<<8; bMIX[5]+=bLFSR[2]; bMIX[3]+=bMIX[4];
- bMIX[3]^=bLFSR[4]>>16; bMIX[6]+=bLFSR[3]; bMIX[4]+=bMIX[5];
- bMIX[4]^=bLFSR[5]<<10; bMIX[7]+=bLFSR[4]; bMIX[5]+=bMIX[6];
- bMIX[5]^=bLFSR[6]>>4; bMIX[0]+=bLFSR[5]; bMIX[6]+=bMIX[7];
- bMIX[6]^=bLFSR[7]<<8; bMIX[1]+=bLFSR[6]; bMIX[7]+=bMIX[0];
- bMIX[7]^=bLFSR[0]>>9; bMIX[2]+=bLFSR[7]; bMIX[0]+=bMIX[1];
- DPRNG->MIX1 = DPRNG->MIX1 >> 1;
- }
- /* MIX MIX2 (LSHIFT) */
- if (DPRNG->MIX2 == 2) DPRNG->MIX2 = DPRNG->LFSR2;
- bMIX = (uint8*)&DPRNG->MIX2; bLFSR = (uint8*)&DPRNG->LFSR2;
- for (fi = 0; fi < DPRNG->MIXLOOPS[1]; fi++) {
- bMIX[0]^=bLFSR[1]<<11; bMIX[3]+=bLFSR[0]; bMIX[1]+=bLFSR[2];
- bMIX[1]^=bLFSR[2]>>2; bMIX[4]+=bLFSR[1]; bMIX[2]+=bLFSR[3];
- bMIX[2]^=bLFSR[3]<<8; bMIX[5]+=bLFSR[2]; bMIX[3]+=bLFSR[4];
- bMIX[3]^=bLFSR[4]>>16; bMIX[6]+=bLFSR[3]; bMIX[4]+=bLFSR[5];
- bMIX[4]^=bLFSR[5]<<10; bMIX[7]+=bLFSR[4]; bMIX[5]+=bLFSR[6];
- bMIX[5]^=bLFSR[6]>>4; bMIX[0]+=bLFSR[5]; bMIX[6]+=bLFSR[7];
- bMIX[6]^=bLFSR[7]<<8; bMIX[1]+=bLFSR[6]; bMIX[7]+=bLFSR[0];
- bMIX[7]^=bLFSR[0]>>9; bMIX[2]+=bLFSR[7]; bMIX[0]+=bLFSR[1];
- DPRNG->MIX2 = DPRNG->MIX2 >> 1;
- }
- /* MIX MIX3 (RSHIFT) */
- if (DPRNG->MIX3 == 2) DPRNG->MIX3 = DPRNG->LFSR3;
- bMIX = (uint8*)&DPRNG->MIX3; bLFSR = (uint8*)&DPRNG->LFSR3;
- for (fi = 0; fi < DPRNG->MIXLOOPS[2]; fi++) {
- bMIX[0]^=bLFSR[1]<<11; bMIX[3]+=bLFSR[0]; bMIX[1]+=bMIX[2];
- bMIX[1]^=bLFSR[2]>>2; bMIX[4]+=bLFSR[1]; bMIX[2]+=bMIX[3];
- bMIX[2]^=bLFSR[3]<<8; bMIX[5]+=bLFSR[2]; bMIX[3]+=bMIX[4];
- bMIX[3]^=bLFSR[4]>>16; bMIX[6]+=bLFSR[3]; bMIX[4]+=bMIX[5];
- bMIX[4]^=bLFSR[5]<<10; bMIX[7]+=bLFSR[4]; bMIX[5]+=bMIX[6];
- bMIX[5]^=bLFSR[6]>>4; bMIX[0]+=bLFSR[5]; bMIX[6]+=bMIX[7];
- bMIX[6]^=bLFSR[7]<<8; bMIX[1]+=bLFSR[6]; bMIX[7]+=bMIX[0];
- bMIX[7]^=bLFSR[0]>>9; bMIX[2]+=bLFSR[7]; bMIX[0]+=bMIX[1];
- DPRNG->MIX3 = DPRNG->MIX3 << 1;
- }
- /* GET 32 BIT RANDOM VALUE */
- rnd = 0x00000000;
- rnd |= DPRNG->MIX1 & 0x0F000F00;
- rnd |= DPRNG->MIX2 & 0xF0F0F0F0;
- rnd |= DPRNG->MIX3 & 0x000F000F;
- return rnd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement