1 | // |
2 | // Crypto.h |
3 | // |
4 | // Library: Crypto |
5 | // Package: CryptoCore |
6 | // Module: Crypto |
7 | // |
8 | // Basic definitions for the Poco Crypto library. |
9 | // This file must be the first file included by every other Crypto |
10 | // header file. |
11 | // |
12 | // Copyright (c) 2008, Applied Informatics Software Engineering GmbH. |
13 | // and Contributors. |
14 | // |
15 | // SPDX-License-Identifier: BSL-1.0 |
16 | // |
17 | |
18 | |
19 | #ifndef Crypto_Crypto_INCLUDED |
20 | #define Crypto_Crypto_INCLUDED |
21 | |
22 | |
23 | #if defined(__APPLE__) |
24 | // OS X 10.7 deprecates some OpenSSL functions |
25 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
26 | #endif |
27 | |
28 | |
29 | #include "Poco/Foundation.h" |
30 | |
31 | |
32 | enum RSAPaddingMode |
33 | /// The padding mode used for RSA public key encryption. |
34 | { |
35 | RSA_PADDING_PKCS1, |
36 | /// PKCS #1 v1.5 padding. This currently is the most widely used mode. |
37 | |
38 | RSA_PADDING_PKCS1_OAEP, |
39 | /// EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty |
40 | /// encoding parameter. This mode is recommended for all new applications. |
41 | |
42 | RSA_PADDING_SSLV23, |
43 | /// PKCS #1 v1.5 padding with an SSL-specific modification that denotes |
44 | /// that the server is SSL3 capable. |
45 | |
46 | RSA_PADDING_NONE |
47 | /// Raw RSA encryption. This mode should only be used to implement cryptographically |
48 | /// sound padding modes in the application code. Encrypting user data directly with RSA |
49 | /// is insecure. |
50 | }; |
51 | |
52 | |
53 | // |
54 | // The following block is the standard way of creating macros which make exporting |
55 | // from a DLL simpler. All files within this DLL are compiled with the Crypto_EXPORTS |
56 | // symbol defined on the command line. this symbol should not be defined on any project |
57 | // that uses this DLL. This way any other project whose source files include this file see |
58 | // Crypto_API functions as being imported from a DLL, whereas this DLL sees symbols |
59 | // defined with this macro as being exported. |
60 | // |
61 | #if defined(_WIN32) |
62 | #if defined(POCO_DLL) |
63 | #if defined(Crypto_EXPORTS) |
64 | #define Crypto_API __declspec(dllexport) |
65 | #else |
66 | #define Crypto_API __declspec(dllimport) |
67 | #endif |
68 | #else |
69 | #if (POCO_MSVS_VERSION >= 2015) // needed for OpenSSL |
70 | #pragma comment(lib, "legacy_stdio_definitions.lib") |
71 | #pragma comment(lib, "legacy_stdio_wide_specifiers.lib") |
72 | #endif |
73 | #endif |
74 | #endif |
75 | |
76 | |
77 | #if !defined(Crypto_API) |
78 | #if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4) |
79 | #define Crypto_API __attribute__ ((visibility ("default"))) |
80 | #else |
81 | #define Crypto_API |
82 | #endif |
83 | #endif |
84 | |
85 | |
86 | // |
87 | // Automatically link Crypto and OpenSSL libraries. |
88 | // |
89 | #if defined(_MSC_VER) |
90 | #if !defined(POCO_NO_AUTOMATIC_LIBS) |
91 | #if !defined(POCO_EXTERNAL_OPENSSL) |
92 | #pragma comment(lib, "libcrypto.lib") |
93 | #pragma comment(lib, "libssl.lib") |
94 | #endif // POCO_EXTERNAL_OPENSSL |
95 | #if !defined(Crypto_EXPORTS) |
96 | #pragma comment(lib, "PocoCrypto" POCO_LIB_SUFFIX) |
97 | #endif |
98 | #endif // POCO_NO_AUTOMATIC_LIBS |
99 | #endif |
100 | |
101 | |
102 | namespace Poco { |
103 | namespace Crypto { |
104 | |
105 | |
106 | void Crypto_API initializeCrypto(); |
107 | /// Initialize the Crypto library, as well as the underlying OpenSSL |
108 | /// libraries, by calling OpenSSLInitializer::initialize(). |
109 | /// |
110 | /// Should be called before using any class from the Crypto library. |
111 | /// The Crypto library will be initialized automatically, through |
112 | /// OpenSSLInitializer instances held by various Crypto classes |
113 | /// (Cipher, CipherKey, RSAKey, X509Certificate). |
114 | /// However, it is recommended to call initializeCrypto() |
115 | /// in any case at application startup. |
116 | /// |
117 | /// Can be called multiple times; however, for every call to |
118 | /// initializeCrypto(), a matching call to uninitializeCrypto() |
119 | /// must be performed. |
120 | |
121 | |
122 | void Crypto_API uninitializeCrypto(); |
123 | /// Uninitializes the Crypto library by calling |
124 | /// OpenSSLInitializer::uninitialize(). |
125 | |
126 | |
127 | } } // namespace Poco::Crypto |
128 | |
129 | |
130 | #endif // Crypto_Crypto_INCLUDED |
131 | |