private Blake3ChunkState() { _n = Blake3Node.DefaultBlake3Node(); _block = new byte[BlockSizeInBytes]; _blockLen = 0; BytesConsumed = 0; }
private unsafe Blake3Node RootNode() { var result = ChunkState.Node(); var temp = new uint[8]; var trailingZeros64 = TrailingZeros64(Used); var len64 = Len64(Used); fixed(uint *ptrTemp = temp) { int idx; for (idx = trailingZeros64; idx < len64; idx++) { if (!HasSubTreeAtHeight(idx)) { continue; } result.ChainingValue(ptrTemp); result = Blake3Node.ParentNode(Stack[idx], temp, Key, Flags); } } result.Flags |= flagRoot; return(result); }
} // end function Read public static Blake3OutputReader DefaultBlake3OutputReader() { Blake3OutputReader result = new Blake3OutputReader(); result.Block = new byte[BlockSizeInBytes]; result.N = Blake3Node.DefaultBlake3Node(); result.Offset = 0; return(result); } // end function Blake3OutputReader
} // end function Update public static Blake3ChunkState DefaultBlake3ChunkState() { Blake3ChunkState result = new Blake3ChunkState(); result.N = Blake3Node.DefaultBlake3Node(); result.Block = new byte[BlockSizeInBytes]; result.BlockLen = 0; result.BytesConsumed = 0; return(result); } // end function DefaultBlake3ChunkState
public Blake3Node Clone() { Blake3Node result = DefaultBlake3Node(); result.CV = CV.DeepCopy(); result.Block = Block.DeepCopy(); result.Counter = Counter; result.BlockLen = BlockLen; result.Flags = Flags; return(result); } // end function Clone
} // end function G public static Blake3Node DefaultBlake3Node() { Blake3Node result = new Blake3Node(); result.CV = new uint[8]; result.Block = new uint[16]; result.Counter = 0; result.BlockLen = 0; result.Flags = 0; return(result); } // end function DefaultBlake3Node
} // end function DefaultBlake3Node public static Blake3Node CreateBlake3Node(UInt32[] a_CV, UInt32[] a_Block, UInt64 a_Counter, UInt32 a_BlockLen, UInt32 a_Flags) { Blake3Node result = DefaultBlake3Node(); result.CV = a_CV.DeepCopy(); result.Block = a_Block.DeepCopy(); result.Counter = a_Counter; result.BlockLen = a_BlockLen; result.Flags = a_Flags; return(result); } // end function CreateBlake3Node
} // end function HasSubTreeAtHeight // AddChunkChainingValue appends a chunk to the right edge of the Merkle tree. private void AddChunkChainingValue(UInt32[] a_CV) { // seek to first open stack slot, merging subtrees as we go Int32 LIdx = 0; while (HasSubTreeAtHeight(LIdx)) { Blake3Node.ParentNode(Stack[LIdx], a_CV, Key, Flags).ChainingValue(ref a_CV); LIdx++; } Stack[LIdx] = a_CV.DeepCopy(); Used++; } // end function AddChunkChainingValue
// AddChunkChainingValue appends a chunk to the right edge of the Merkle tree. private unsafe void AddChunkChainingValue(uint[] cv) { // seek to first open stack slot, merging subtrees as we go var idx = 0; fixed(uint *cvPtr = cv) { while (HasSubTreeAtHeight(idx)) { Blake3Node.ParentNode(Stack[idx], cv, Key, Flags).ChainingValue(cvPtr); idx++; } } Stack[idx] = ArrayUtils.Clone(cv); Used++; }
} // end function Complete // node returns a node containing the chunkState's current state, with the // ChunkEnd flag set. public unsafe Blake3Node Node() { Blake3Node result = N.Clone(); fixed(byte *blockPtr = Block) { fixed(UInt32 *resultPtr = result.Block) { // pad the remaining space in the block with zeros Utils.Utils.Memset((IntPtr)blockPtr + BlockLen, (byte)0, (Block.Length - BlockLen) * sizeof(byte)); Converters.le32_copy((IntPtr)blockPtr, 0, (IntPtr)resultPtr, 0, BlockSizeInBytes); } } result.BlockLen = (UInt32)BlockLen; result.Flags = result.Flags | flagChunkEnd; return(result); } // end function Node
}; // end struct Blake3OutputReader private Blake3Node RootNode() { Int32 LIdx, LTrailingZeros64, LLen64; Blake3Node result = CS.Node(); UInt32[] LTemp = new UInt32[8]; LTrailingZeros64 = TrailingZeros64(Used); LLen64 = Len64(Used); for (LIdx = LTrailingZeros64; LIdx < LLen64; LIdx++) { if (HasSubTreeAtHeight(LIdx)) { result.ChainingValue(ref LTemp); result = Blake3Node.ParentNode(Stack[LIdx], LTemp, Key, Flags); } } result.Flags = result.Flags | flagRoot; return(result); } // end function RootNode
private Blake3OutputReader() { N = Blake3Node.DefaultBlake3Node(); _block = new byte[BlockSizeInBytes]; Offset = 0; }