Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SuperFastHash.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Cryptography_Digest_SuperFastHash_h_
5#define _Stroika_Foundation_Cryptography_Digest_SuperFastHash_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <cstdint>
10
11#include "Stroika/Foundation/Cryptography/Digest/Digester.h"
12
13/**
14 * \file
15 *
16 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
17 *
18 * @see http://www.azillionmonkeys.com/qed/hash.html
19 *
20 * TODO:
21 * @todo See if we need to wrap this whole file in #ifndef for some 'license' issue, since I'm not sure
22 * this associated license is OK...
23 *
24 */
25
26namespace Stroika::Foundation::Cryptography::Digest::Algorithm {
27
28 /**
29 * Algorithm 'type tag' indicating this particular algorithm.
30 */
31 struct SuperFastHash {};
32
33 /**
34 * Traits for the SuperFastHash algorithm.
35 */
36 template <>
38 using ReturnType = uint32_t;
39 };
40
41 /*
42 * \brief Windowing digester (code to do the digest algorithm) for the SuperFastHash algorithm.
43 *
44 * Implementation based on text from http://www.azillionmonkeys.com/qed/hash.html on 2014-07-28
45 *
46 * NOTE - I tried to implement in a way that could be windowed, just reading it bits at a time,
47 * but the trouble is that the initial value of the hash is the length, and since the BinaryInputStream
48 * isn't necessarily seekable, we cannot compute its length.
49 *
50 * \note HOWEVER, being Windowed is very important, and being 'result-compatible' with the code in http://www.azillionmonkeys.com/qed/hash.html isn't.
51 * So instead, I start with a value of 0.
52 *
53 */
54 template <>
55 class DigesterAlgorithm<SuperFastHash> : public IDigestAlgorithm<DigesterDefaultTraitsForAlgorithm<SuperFastHash>::ReturnType> {
56 public:
58
59 public:
60 DigesterAlgorithm () = default;
61 DigesterAlgorithm (const DigesterAlgorithm& src) = default;
62
63 public:
64 nonvirtual DigesterAlgorithm& operator= (const DigesterAlgorithm& rhs) = default;
65
66 public:
67 virtual void Write (const byte* start, const byte* end) override;
68
69 public:
70 virtual ReturnType Complete () override;
71
72 private:
73 uint32_t fHash_{0}; // original algorithm set this to len, but we cannot and be windowed
74 unsigned int fRemainder_{};
75 array<byte, 3> fFinalBytes_{};
76#if qStroika_Foundation_Debug_AssertionsChecked
77 bool fCompleted_{false};
78#endif
79 };
80
81}
82
83/*
84 ********************************************************************************
85 ***************************** Implementation Details ***************************
86 ********************************************************************************
87 */
88#include "SuperFastHash.inl"
89
90#endif /*_Stroika_Foundation_Cryptography_Digest_SuperFastHash_h_*/
DigesterAlgorithm is specialized for each algorithm; generally don't use this directly,...
Definition Algorithm.h:55