Skip to content

Instantly share code, notes, and snippets.

@Mc01
Last active February 9, 2024 14:17
Show Gist options
  • Save Mc01/ee6ec6cccf374e7fb22a821b03df99db to your computer and use it in GitHub Desktop.
Save Mc01/ee6ec6cccf374e7fb22a821b03df99db to your computer and use it in GitHub Desktop.
Naming convention
pragma solidity 0.8.21;
library InputOutput {
function _finalize(
Context memory _context, // - input argument
uint64[4] memory _output_ // - input argument and also output of the function
) internal view {
// tx.members
uint256 now_ = block.timestamp; // local var
// add any uncounted bytes
_context.t += _context.c;
// compress with finalization flag
_compress(_context, true);
// flip little to big endian and store in output buffer
for (uint256 i = 0; i < _context.digestSize / 8; i++) {
_output_[i] = _getWords(_context.h[i]);
}
// properly pad output if it doesn't fill a full word
if (_context.digestSize < 32) {
_output_[_context.digestSize / 8] = _shiftRight(
_toLittleEndian(_context.h[_context.digestSize / 8]),
64 - 8 * (_context.digestSize % 8)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment