internal override IArgon2PseudoRands GenerateState(Argon2Lane[] lanes, int segmentLength, int pass, int lane, int slice) { var rands = new ulong[segmentLength]; var ulongRaw = new ulong[384]; var inputBlock = new Argon2Memory(ulongRaw, 0); var addressBlock = new Argon2Memory(ulongRaw, 128); var tmpBlock = new Argon2Memory(ulongRaw, 256); inputBlock[0] = (ulong)pass; inputBlock[1] = (ulong)lane; inputBlock[2] = (ulong)slice; inputBlock[3] = (ulong)MemorySize; inputBlock[4] = (ulong)Iterations; inputBlock[5] = (ulong)Type; for (var i = 0; i < segmentLength; i++) { var ival = i % 128; if (ival == 0) { inputBlock[6]++; tmpBlock.Set(0); addressBlock.Set(0); Compress(tmpBlock, inputBlock, _zeroBlock); Compress(addressBlock, tmpBlock, _zeroBlock); } rands[i] = addressBlock[ival]; } return(new PseudoRands(rands)); }
public void Expose(Argon2Memory memory) { if (memory != null) { Expose(new Argon2Memory.Stream(memory)); } }
internal unsafe static void Compress(Argon2Memory dest, Argon2Memory refb, Argon2Memory prev) { var tmpblock = stackalloc ulong[dest.Length]; for (var n = 0; n < 128; ++n) { tmpblock[n] = refb[n] ^ prev[n]; dest[n] ^= tmpblock[n]; } for (var i = 0; i < 8; ++i) { ModifiedBlake2.DoRoundColumns(tmpblock, i); } for (var i = 0; i < 8; ++i) { ModifiedBlake2.DoRoundRows(tmpblock, i); } for (var n = 0; n < 128; ++n) { dest[n] ^= tmpblock[n]; } }
private static void DebugWrite(Argon2Memory mem) { DebugWrite(mem.ToArray()); }
public Stream(Argon2Memory memory) { _data = GCHandle.Alloc(memory._data, GCHandleType.Pinned); base.Initialize((byte *)_data.AddrOfPinnedObject() + (memory._offset * 8), 1024, 1024, FileAccess.Read); }