A fine-tuned implementation of the SHA256 hashing algorithm.
Dependents: EntropySource Wallet_v1
Diff: SHA256.h
- Revision:
- 4:81678751d669
- Parent:
- 3:f19b10394f9c
- Child:
- 5:246096ab9e56
diff -r f19b10394f9c -r 81678751d669 SHA256.h --- a/SHA256.h Mon Jun 20 11:00:20 2011 +0000 +++ b/SHA256.h Mon Jun 20 11:06:11 2011 +0000 @@ -30,31 +30,46 @@ /// @param size The number of bytes to read from data, but see the note. void append(const char* data, int size); - /// Append a single byte. + /// Append a single byte + /// /// Avoid this function if performance is important. + /// + /// @param c The character to be appended. void append(char c) { append(&c, 1); } /// Append a zero terminated string + /// /// The terminating zero itself is not appended. + /// + /// @param str The zero terminated string to be appended. void append(const char* str) { append(str, strlen(str)); } /// Append a std::string + /// + /// @param str The std::string to be appended. void append(const std::string& str) { append(str.data(), str.length()); } /// Append the required padding and compute the final digest - /// Always call this function first before requesting the digest + /// + /// Always call this function first before requesting the digest. /// /// After finalization you must call reset() before you can append again. + /// /// However, you can do this: + /// @code /// SHA256 hash1, hash1and2; /// hash1.append("First part"); /// hash1and2 = hash1; /// hash1.finalize(); /// hash1and2.append("Second part"); /// hash1and2.finalize(); + /// @endcode void finalize(); /// Returns a pointer to the 32 bytes of the digest + /// + /// @returns a pointer to a non-zero-terminated block of + /// 32 bytes containting the digest. const char* digest() { return reinterpret_cast<char*>(hash); } /// Return the digest as a binary std::string @@ -62,12 +77,16 @@ /// Avoid this function if performance is important, /// the std::string constructor will make a copy of the /// digest internally, doing a malloc and memcpy. + /// + /// @returns a std::string containing the digest as raw binary bits. std::string binString() { return std::string(digest(), 32); } /// Return the digest as a hexadecimal std::string /// /// In addition to the note for binaryString, this function /// also does conversion. + /// + /// @returns a std::string containing the digest in hexadecimal ascii. std::string hexString(); private: