Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarSha256.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/core/StarSha256.hpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/core/StarSha256.hpp')
-rw-r--r--source/core/StarSha256.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/source/core/StarSha256.hpp b/source/core/StarSha256.hpp
new file mode 100644
index 0000000..6a9abd4
--- /dev/null
+++ b/source/core/StarSha256.hpp
@@ -0,0 +1,44 @@
+#ifndef STAR_SHA_256_HPP
+#define STAR_SHA_256_HPP
+
+#include "StarString.hpp"
+#include "StarByteArray.hpp"
+
+namespace Star {
+
+typedef struct sha_state_struct {
+ uint32_t state[8], length, curlen;
+ uint8_t buf[64];
+} sha_state;
+
+class Sha256Hasher {
+public:
+ Sha256Hasher();
+
+ void push(char const* data, size_t length);
+ void push(String const& data);
+ void push(ByteArray const& data);
+
+ // Produces 32 bytes
+ void compute(char* hashDestination);
+ ByteArray compute();
+
+private:
+ bool m_finished;
+ sha_state m_state;
+};
+
+// Sha256 must, obviously, have 32 bytes available in the destination.
+void sha256(char const* source, size_t length, char* hashDestination);
+
+ByteArray sha256(char const* source, size_t length);
+
+void sha256(ByteArray const& in, ByteArray& out);
+void sha256(String const& in, ByteArray& out);
+
+ByteArray sha256(ByteArray const& in);
+ByteArray sha256(String const& in);
+
+}
+
+#endif