Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(31566)

Unified Diff: Modules/_sha3/kcp/SnP-Relaned.h

Issue 16113: Add SHA-3 (Keccak) support
Patch Set: Created 3 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Modules/_sha3/kcp/PlSnP-Fallback.inc ('k') | Modules/_sha3/README.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
new file mode 100644
index 0000000000000000000000000000000000000000..086e635ff8f6f35cf431d2f5c1b84030c7343323
--- /dev/null
+++ b/Modules/_sha3/kcp/SnP-Relaned.h
@@ -0,0 +1,134 @@
+/*
+Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
+Joan Daemen, Michaƫl Peeters, Gilles Van Assche and Ronny Van Keer, hereby
+denoted as "the implementer".
+
+For more information, feedback or questions, please refer to our websites:
+http://keccak.noekeon.org/
+http://keyak.noekeon.org/
+http://ketje.noekeon.org/
+
+To the extent possible under law, the implementer has waived all copyright
+and related or neighboring rights to the source code in this file.
+http://creativecommons.org/publicdomain/zero/1.0/
+*/
+
+#ifndef _SnP_Relaned_h_
+#define _SnP_Relaned_h_
+
+#define SnP_AddBytes(state, data, offset, length, SnP_AddLanes, SnP_AddBytesInLane, SnP_laneLengthInBytes) \
+ { \
+ if ((offset) == 0) { \
+ SnP_AddLanes(state, data, (length)/SnP_laneLengthInBytes); \
+ SnP_AddBytesInLane(state, \
+ (length)/SnP_laneLengthInBytes, \
+ (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
+ 0, \
+ (length)%SnP_laneLengthInBytes); \
+ } \
+ else { \
+ unsigned int _sizeLeft = (length); \
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
+ const unsigned char *_curData = (data); \
+ while(_sizeLeft > 0) { \
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
+ if (_bytesInLane > _sizeLeft) \
+ _bytesInLane = _sizeLeft; \
+ SnP_AddBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
+ _sizeLeft -= _bytesInLane; \
+ _lanePosition++; \
+ _offsetInLane = 0; \
+ _curData += _bytesInLane; \
+ } \
+ } \
+ }
+
+#define SnP_OverwriteBytes(state, data, offset, length, SnP_OverwriteLanes, SnP_OverwriteBytesInLane, SnP_laneLengthInBytes) \
+ { \
+ if ((offset) == 0) { \
+ SnP_OverwriteLanes(state, data, (length)/SnP_laneLengthInBytes); \
+ SnP_OverwriteBytesInLane(state, \
+ (length)/SnP_laneLengthInBytes, \
+ (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
+ 0, \
+ (length)%SnP_laneLengthInBytes); \
+ } \
+ else { \
+ unsigned int _sizeLeft = (length); \
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
+ const unsigned char *_curData = (data); \
+ while(_sizeLeft > 0) { \
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
+ if (_bytesInLane > _sizeLeft) \
+ _bytesInLane = _sizeLeft; \
+ SnP_OverwriteBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
+ _sizeLeft -= _bytesInLane; \
+ _lanePosition++; \
+ _offsetInLane = 0; \
+ _curData += _bytesInLane; \
+ } \
+ } \
+ }
+
+#define SnP_ExtractBytes(state, data, offset, length, SnP_ExtractLanes, SnP_ExtractBytesInLane, SnP_laneLengthInBytes) \
+ { \
+ if ((offset) == 0) { \
+ SnP_ExtractLanes(state, data, (length)/SnP_laneLengthInBytes); \
+ SnP_ExtractBytesInLane(state, \
+ (length)/SnP_laneLengthInBytes, \
+ (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
+ 0, \
+ (length)%SnP_laneLengthInBytes); \
+ } \
+ else { \
+ unsigned int _sizeLeft = (length); \
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
+ unsigned char *_curData = (data); \
+ while(_sizeLeft > 0) { \
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
+ if (_bytesInLane > _sizeLeft) \
+ _bytesInLane = _sizeLeft; \
+ SnP_ExtractBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
+ _sizeLeft -= _bytesInLane; \
+ _lanePosition++; \
+ _offsetInLane = 0; \
+ _curData += _bytesInLane; \
+ } \
+ } \
+ }
+
+#define SnP_ExtractAndAddBytes(state, input, output, offset, length, SnP_ExtractAndAddLanes, SnP_ExtractAndAddBytesInLane, SnP_laneLengthInBytes) \
+ { \
+ if ((offset) == 0) { \
+ SnP_ExtractAndAddLanes(state, input, output, (length)/SnP_laneLengthInBytes); \
+ SnP_ExtractAndAddBytesInLane(state, \
+ (length)/SnP_laneLengthInBytes, \
+ (input)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
+ (output)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
+ 0, \
+ (length)%SnP_laneLengthInBytes); \
+ } \
+ else { \
+ unsigned int _sizeLeft = (length); \
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
+ const unsigned char *_curInput = (input); \
+ unsigned char *_curOutput = (output); \
+ while(_sizeLeft > 0) { \
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
+ if (_bytesInLane > _sizeLeft) \
+ _bytesInLane = _sizeLeft; \
+ SnP_ExtractAndAddBytesInLane(state, _lanePosition, _curInput, _curOutput, _offsetInLane, _bytesInLane); \
+ _sizeLeft -= _bytesInLane; \
+ _lanePosition++; \
+ _offsetInLane = 0; \
+ _curInput += _bytesInLane; \
+ _curOutput += _bytesInLane; \
+ } \
+ } \
+ }
+
+#endif
« no previous file with comments | « Modules/_sha3/kcp/PlSnP-Fallback.inc ('k') | Modules/_sha3/README.txt » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+