Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Jenkins.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "Jenkins.h"
7
8using std::byte;
9
10using namespace Stroika::Foundation;
11using namespace Stroika::Foundation::Cryptography;
12using namespace Stroika::Foundation::Cryptography::Digest;
13
14namespace {
15 /*
16 * Implementation based on text from http://en.wikipedia.org/wiki/Jenkins_hash_function on 2013-05-30
17 */
18 inline void DoMore_ (uint32_t* hash2Update, const byte* from, const byte* to)
19 {
20 RequireNotNull (hash2Update);
21 uint32_t hash = (*hash2Update);
22 for (const byte* bi = from; bi != to; ++bi) {
23 hash += to_integer<uint8_t> (*bi);
24 hash += (hash << 10);
25 hash ^= (hash >> 6);
26 }
27 (*hash2Update) = hash;
28 }
29 inline void DoEnd_ (uint32_t* hash2Update)
30 {
31 RequireNotNull (hash2Update);
32 uint32_t hash = (*hash2Update);
33 hash += (hash << 3);
34 hash ^= (hash >> 11);
35 hash += (hash << 15);
36 (*hash2Update) = hash;
37 }
38}
39
40/*
41 ********************************************************************************
42 ***************** Algorithm::DigesterAlgorithm<Algorithm::Jenkins> *************
43 ********************************************************************************
44 */
45void Algorithm::DigesterAlgorithm<Algorithm::Jenkins>::Write (const byte* start, const byte* end)
46{
47#if qStroika_Foundation_Debug_AssertionsChecked
48 Require (not fCompleted_);
49#endif
50 DoMore_ (&fData_, start, end);
51}
52
54{
55#if qStroika_Foundation_Debug_AssertionsChecked
56 Require (not fCompleted_);
57 fCompleted_ = true;
58#endif
59 DoEnd_ (&fData_);
60 return fData_;
61}
#define RequireNotNull(p)
Definition Assertions.h:347
DigesterAlgorithm is specialized for each algorithm; generally don't use this directly,...
Definition Algorithm.h:55