Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
MD5.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_MD5_h_
5#define _Stroika_Foundation_Cryptography_Digest_MD5_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Cryptography/Digest/Digester.h"
10#include "Stroika/Foundation/Cryptography/Digest/ResultTypes.h"
11
12/**
13 * \file
14 *
15 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
16 *
17 */
18
19namespace Stroika::Foundation::Cryptography::Digest::Algorithm {
20
21 /**
22 * Algorithm 'type tag' indicating this particular algorithm.
23 */
24 struct MD5 {};
25
26 /**
27 * Traits for the MD5 algorithm.
28 */
29 template <>
31 using ReturnType = Result128BitType;
32 };
33
34 /**
35 * \brief Windowing digester (code to do the digest algorithm) for the MD5 algorithm.
36 */
37 template <>
38 class DigesterAlgorithm<MD5> : public IDigestAlgorithm<DigesterDefaultTraitsForAlgorithm<MD5>::ReturnType> {
39 public:
41
42 public:
44 DigesterAlgorithm (const DigesterAlgorithm& src) = default;
45
46 public:
47 nonvirtual DigesterAlgorithm& operator= (const DigesterAlgorithm& rhs) = default;
48
49 public:
50 virtual void Write (const byte* start, const byte* end) override;
51
52 public:
53 virtual ReturnType Complete () override;
54
55 private:
56 using UINT4 = uint32_t;
57 struct MD5_CTX {
58 UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
59 UINT4 buf[4]; /* scratch buffer */
60 unsigned char in[64]; /* input buffer */
61 unsigned char digest[16]; /* actual digest after MD5Final call */
62 };
63 MD5_CTX fCtx_{};
64#if qStroika_Foundation_Debug_AssertionsChecked
65 bool fCompleted_{false};
66#endif
67
68 private:
69 // public: //tmphack til we get rid of other class
70 static void MD5Init_ (MD5_CTX* mdContext);
71
72 static void MD5Update_ (MD5_CTX* mdContext, const unsigned char* inBuf, unsigned int inLen);
73 static void MD5Final_ (MD5_CTX* mdContext);
74 static void Transform (UINT4* buf, UINT4* in);
75 };
76
77}
78
79/*
80 ********************************************************************************
81 ***************************** Implementation Details ***************************
82 ********************************************************************************
83 */
84#include "MD5.inl"
85
86#endif /*_Stroika_Foundation_Cryptography_Digest_MD5_h_*/
DigesterAlgorithm is specialized for each algorithm; generally don't use this directly,...
Definition Algorithm.h:55