Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
CipherAlgorithm.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_OpenSSL_CipherAlgorithm_h_
5#define _Stroika_Foundation_Cryptography_OpenSSL_CipherAlgorithm_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#if qStroika_HasComponent_OpenSSL
10#include <openssl/evp.h>
11#endif
12
14#include "Stroika/Foundation/Common/Common.h"
15#include "Stroika/Foundation/Common/Property.h"
16#include "Stroika/Foundation/Execution/Exceptions.h"
17#include "Stroika/Foundation/Execution/LazyInitialized.h"
18#include "Stroika/Foundation/Memory/Common.h"
19
20/**
21 * \file
22 *
23 */
24
25#if qStroika_HasComponent_OpenSSL
26namespace Stroika::Foundation::Cryptography::Providers::OpenSSL {
27
28 using Characters::String;
29
30 /**
31 * \brief object oriented wrapper on OpenSSL cipher algorithms (const EVP_CIPHER*)
32 */
33 class CipherAlgorithm {
34 public:
35 /**
36 */
37 CipherAlgorithm (const ::EVP_CIPHER* cipher);
38 CipherAlgorithm (const CipherAlgorithm& src);
39
40 public:
41 nonvirtual CipherAlgorithm& operator= (const CipherAlgorithm& src);
42
43 public:
44 /**
45 * Wrapper on CipherAlgorithm
46 *
47 * @see https://linux.die.net/man/3/evp_get_cipherbyname
48 */
49 static CipherAlgorithm GetByName (const String& cipherName);
50 static optional<CipherAlgorithm> GetByNameQuietly (const String& cipherName);
51
52 public:
53 nonvirtual operator const ::EVP_CIPHER* () const;
54
55 public:
56 /**
57 */
58 Common::ReadOnlyProperty<String> name;
59
60 public:
61 nonvirtual auto operator<=> (const CipherAlgorithm& rhs) const;
62 nonvirtual bool operator== (const CipherAlgorithm& rhs) const;
63
64 public:
65 /**
66 */
67 nonvirtual size_t KeyLength () const;
68
69 public:
70 /**
71 */
72 nonvirtual size_t IVLength () const;
73
74 public:
75 /**
76 */
77 nonvirtual String ToString () const;
78
79 private:
80 const ::EVP_CIPHER* fCipher_;
81 };
82
83 /**
84 * @see https://wiki.openssl.org/index.php/OpenSSL_3.0 section 9.3.2
85 */
86 namespace CipherAlgorithms {
87 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_128_CBC;
88 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_128_ECB;
89 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_128_OFB;
90 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_128_CFB1;
91 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_128_CFB8;
92 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_128_CFB128;
93 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_192_CBC;
94 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_192_ECB;
95 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_192_OFB;
96 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_192_CFB1;
97 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_192_CFB8;
98 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_192_CFB128;
99 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_256_CBC;
100 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_256_ECB;
101 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_256_OFB;
102 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_256_CFB1;
103 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_256_CFB8;
104 extern const Execution::LazyInitialized<CipherAlgorithm> kAES_256_CFB128;
105
106 /*
107 * NB: In OpenSSL v3, the algorithms:
108 * o eBlowfish
109 * o eRC2,
110 * o eRC4,
111 * o (and others listed in https://wiki.openssl.org/index.php/OpenSSL_3.0 but we never supported them before)
112 * are only available in the LEGACY provider, and it is not recommended to use, so dont make that easy
113 * from Stroika. By default just assume default provider is in use.
114 * @see http://stroika-bugs.sophists.com/browse/STK-735
115 *
116 * @todo mark these below as deprecated...
117 */
118 extern const Execution::LazyInitialized<CipherAlgorithm> kBlowfish_CBC;
119 extern const Execution::LazyInitialized<CipherAlgorithm> kBlowfish_ECB;
120 extern const Execution::LazyInitialized<CipherAlgorithm> kBlowfish_CFB;
121 extern const Execution::LazyInitialized<CipherAlgorithm> kBlowfish_OFB;
122 extern const Execution::LazyInitialized<CipherAlgorithm> kBlowfish;
123 extern const Execution::LazyInitialized<CipherAlgorithm> kRC2_CBC;
124 extern const Execution::LazyInitialized<CipherAlgorithm> kRC2_ECB;
125 extern const Execution::LazyInitialized<CipherAlgorithm> kRC2_CFB;
126 extern const Execution::LazyInitialized<CipherAlgorithm> kRC2_OFB;
127 extern const Execution::LazyInitialized<CipherAlgorithm> kRC4;
128 }
129
130}
131#endif
132
133/*
134 ********************************************************************************
135 ***************************** Implementation Details ***************************
136 ********************************************************************************
137 */
138#include "CipherAlgorithm.inl"
139
140#endif /*_Stroika_Foundation_Cryptography_OpenSSL_CipherAlgorithm_h_*/
STRING_TYPE ToString(FLOAT_TYPE f, const ToStringOptions &options={})