GetRandomIV:
PUBLIC
PROC
RETURNS [iv:
IV] = {
Ideally, this should use a true random number generator
prevSeed: Block ← randomSeed;
pulse1: POINTER TO LONG CARDINAL = LOOPHOLE[@randomSeed[0]];
pulse2: POINTER TO LONG CARDINAL = LOOPHOLE[@randomSeed[2]];
seedKey: POINTER TO Key = LOOPHOLE[@randomSeed];
pulse1^ ← pulse1^ + BasicTime.GetClockPulses[];
XOR32[pulse2^, BasicTime.GetClockPulses[], pulse2];
CorrectParity[seedKey];
CryptData[keyP: seedKey, nBlks: 1,
from: LOOPHOLE[LONG[@prevSeed], Blocks],
to: LOOPHOLE[LONG[@iv], Blocks],
direction: encrypt, mode: ecb, seedP: NIL];
};
parityTable:
PACKED
ARRAY [0..127]
OF [0..1] ← [
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
];
}.