dustman31 / sha-3 Goto Github PK
View Code? Open in Web Editor NEWC++ implementation of SHA-3 hash.
C++ implementation of SHA-3 hash.
This is a C++ implementation of the SHA-3 family of hash functions, based on the documentation found at http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf Download binaries at: http://www.danielhorne.co.uk/Projects/SHA-3/SHA3.html Usage: sha3sum [command]* file* where command is an optional parameter that can set either the algorithm, as there is a slight difference between the bare keccak function and the SHA-3 variant. Algorithm -a=s : Set algorithm to SHA-3 (default). -a=k : Set algotithm to Keccak. -a=h : Set algorithm to SHAKE Size -w=224 : Set width to 224 bits. -w=256 : Set width to 256 bits. -w=384 : Set width to 384 bits. -w=512 : Set width to 512 bits (default). Digest size (SHAKE) -d=number : Set the SHAKE digest size. Should be less than or equal to the hash size. Should be multiple of 8 Only relevant for SHAKE - For SHA-3 and keccak, digest size is equal to sponge size. Output format -o=b : Base 64 encoded. -o=h : hexadecimal (default) Any number of files can be specified. Files will be processed with the most recently specified options - for example: sha3sum test.txt -a=k -w=384 test.txt -a=s -w=256 text.txt will hash "test.txt" three times - First with 512-bit SHA-3, then with 384-bit keccak, then finally with 256-bit SHA-3. The intent with this implementation is to make a performant implementation in pure C++, following modern idioms: Favouring inline functions over macros, leaning on the compiler's optimiser instead of resorting to inline assembly, for example. ToDo: - Add command option to set the chunk size for reading. - Attempt formal proof of important aspects of this implementation. Bugs: - Any bugs, please either add them to the github repo (https://github.com/DuSTman31/SHA-3/issues), or e-mail me at [email protected] (remove "-"s). - Will document the design and verification on www.danielhorne.co.uk when I get round to it.
My Code:
Input ”A“
Debug(Correct):
421a35a60054e5f383b6137e43d44e998f496748cc77258240ccfaa8730b51f40cf47c1bc09c728a8cd4f096731298d51463f15af89543fed478053346260c38
Release:
fff33bdfffbfdbffb5712b45afaa596feaf59e440bf66b0f18948e4cc9ebc144e7c9f0a0aa3c8fc7375e2a4fc8add620f28210b2cb87f1d040448b62fbe7392a
'Keccak.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\kernel32.dll'
The thread 0x1184 has exited with code 0 (0x0).
The program '[8172] Keccak.exe' has exited with code 0 (0x0).
What version you use VS ?
Or how I can solve this problem ?
Bjorn Nilsson pointed out the following:
In the doFile function, the keccakUpdate call looks different for the three hash types:
For hashType 0: keccakUpdate((uint8_t*)buf, 0, bytesRead, st);
For hashType 1: keccakUpdate((uint8_t*)buf, 0, bufferSize, st);
For hashType 2: keccakUpdate((uint8_t*)buf, 0, bufferSize, st);Is the difference bytesRead vs bufferSize intentional? It seems to me the code might feed uninitialized buffer for hashType 1 and 2 if bytesRead<bufferSize.
This is correct - it should have been bytesRead. This was likely missed when I converted the project from reading the whole file at once. I have pushed the fix, and encourage users to update to this version.
fairly self explanatory. I have used the boost/beast implementation, which has a very open (but bespoke) licence here
Its complete junk.
1)state->length isnt a uint64_t count.
2)A is a 25 uint64
3)'for' really terrible
Do you have a favourite unit testing framework? I can hopefully get the time to write a couple of simple tests. I note you are developing in visual studio- therefore maybe one of https://docs.microsoft.com/en-us/visualstudio/test/writing-unit-tests-for-c-cpp?view=vs-2019
The code looks like it computes the digest properly, but sha3Digest truncates the output to 24 bytes (192 bits), because math is 64-bit. The last 4 bytes are missing from the result.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.