Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTCrypto.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTCrypto.hpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 #ifndef OPENTXS_CORE_CRYPTO_OTCRYPTO_HPP
134 #define OPENTXS_CORE_CRYPTO_OTCRYPTO_HPP
135 
136 #include "../OTPayload.hpp"
137 #include "../OTString.hpp"
138 #include "../util/Assert.hpp"
139 
140 #include <mutex>
141 
142 #include <set>
143 
144 namespace opentxs
145 {
146 
147 class OTAsymmetricKey;
148 class OTData;
149 class OTIdentifier;
150 class OTPassword;
151 class OTPasswordData;
152 class OTPayload;
153 class OTPseudonym;
154 class OTSettings;
156 
157 typedef std::multimap<std::string, OTAsymmetricKey*> mapOfAsymmetricKeys;
158 
160 {
161 private:
162  static bool GetSetAll();
163 
164  static bool GetSetValue(OTSettings& config, std::string strKeyName,
165  int32_t nDefaultValue, const int32_t*& out_nValue);
166 
167  static const int32_t& GetValue(const int32_t*& pValue);
168 
169  static const int32_t* sp_nIterationCount;
170  static const int32_t* sp_nSymmetricSaltSize;
171  static const int32_t* sp_nSymmetricKeySize;
172  static const int32_t* sp_nSymmetricKeySizeMax;
173  static const int32_t* sp_nSymmetricIvSize;
174  static const int32_t* sp_nSymmetricBufferSize;
175  static const int32_t* sp_nPublicKeysize;
176  static const int32_t* sp_nPublicKeysizeMax;
177  static const int32_t* sp_nDigest1Size;
178  static const int32_t* sp_nDigest2Size;
179 
180 public:
181  EXPORT static uint32_t IterationCount();
182  EXPORT static uint32_t SymmetricSaltSize();
183  EXPORT static uint32_t SymmetricKeySize();
184  EXPORT static uint32_t SymmetricKeySizeMax();
185  EXPORT static uint32_t SymmetricIvSize();
186  EXPORT static uint32_t SymmetricBufferSize();
187  EXPORT static uint32_t PublicKeysize();
188  EXPORT static uint32_t PublicKeysizeMax();
189  EXPORT static uint32_t Digest1Size();
190  EXPORT static uint32_t Digest2Size();
191 };
192 
193 // Sometimes I want to decrypt into an OTPassword (for encrypted symmetric
194 // keys being decrypted) and sometimes I want to decrypt into an OTPayload
195 // (For most other types of data.) This class allows me to do it either way
196 // without duplicating the static Decrypt() function, by wrapping both
197 // types.
198 //
200 {
201 private:
202  OTPassword* m_pPassword;
203  OTPayload* m_pPayload;
204 
206 
207 public:
208  EXPORT ~OTCrypto_Decrypt_Output();
209 
211 
212  EXPORT OTCrypto_Decrypt_Output(OTPassword& thePassword);
213  EXPORT OTCrypto_Decrypt_Output(OTPayload& thePayload);
214 
215  EXPORT void swap(OTCrypto_Decrypt_Output& other);
216 
217  EXPORT OTCrypto_Decrypt_Output& operator=(
218  OTCrypto_Decrypt_Output other); // passed by value.
219 
220  EXPORT bool Concatenate(const void* pAppendData,
221  uint32_t lAppendSize) const;
222 
223  EXPORT void Release(); // Someday make this virtual, if we ever subclass it.
224  EXPORT void Release_Envelope_Decrypt_Output() const;
225 };
226 
227 // OT CRYPTO -- ABSTRACT INTERFACE
228 //
229 // We are now officially at the point where we can easily swap crypto libs!
230 // Just make a subclass of OTCrypto (copy an existing subclass such as
231 // OTCrypto_OpenSSL)
232 class OTCrypto
233 {
234 private:
235  static int32_t s_nCount; // Instance count, should never exceed 1.
236 protected:
237  OTCrypto();
238 
239  virtual void Init_Override() const;
240  virtual void Cleanup_Override() const;
241 
242 public:
243  virtual ~OTCrypto();
244  // InstantiateBinarySecret
245  // (To instantiate a text secret, just do this: OTPassword thePass;)
246  //
247  virtual OTPassword* InstantiateBinarySecret() const = 0;
248  // GET PASSPHRASE FROM CONSOLE
249  //
250  EXPORT bool GetPasswordFromConsole(OTPassword& theOutput,
251  bool bRepeat = false) const;
252  EXPORT bool GetPasswordFromConsoleLowLevel(OTPassword& theOutput,
253  const char* szPrompt) const;
254  // RANDOM NUMBERS
255  //
256  virtual bool RandomizeMemory(uint8_t* szDestination,
257  uint32_t nNewSize) const = 0;
258  // HASHING
259  //
260  virtual bool CalculateDigest(const OTString& strInput,
261  const OTString& strHashAlgorithm,
262  OTIdentifier& theOutput) const = 0;
263  virtual bool CalculateDigest(const OTData& dataInput,
264  const OTString& strHashAlgorithm,
265  OTIdentifier& theOutput) const = 0;
266  // BASE 62 ENCODING (for IDs)
267  //
268  bool IsBase62(const std::string& str) const;
269 
270  virtual void SetIDFromBase62String(const OTString& strInput,
271  OTIdentifier& theOutput) const = 0;
272  virtual void SetBase62StringFromID(const OTIdentifier& theInput,
273  OTString& strOutput) const = 0;
274  // BASE 64 ENCODING
275  //
276  virtual bool Base64Encode(const OTData& theInput, OTString& strOutput,
277  bool bLineBreaks = true) const;
278  virtual bool Base64Decode(const OTString& strInput, OTData& theOutput,
279  bool bLineBreaks = true) const;
280 
281  // Lower-level version:
282  // Caller is responsible to delete. Todo: return a unqiue pointer.
283  virtual char* Base64Encode(const uint8_t* input, int32_t in_len,
284  bool bLineBreaks) const = 0; // NOTE: the
285  // 'int32_t' here is
286  // very worrying to
287  // me. The
288  // reason it's here is because that's what OpenSSL uses. So
289  // we may need to find another way of doing it, so we can use
290  // a safer parameter here than what it currently is. Todo
291  // security.
292  virtual uint8_t* Base64Decode(const char* input, size_t* out_len,
293  bool bLineBreaks) const = 0;
294  // KEY DERIVATION
295  //
296  // DeriveKey derives a 128-bit symmetric key from a passphrase.
297  //
298  // The OTPassword* returned is the actual derived key. (The result.)
299  //
300  // However, you would not use it directly for symmetric-key crypto, but
301  // instead you'd use the OTSymmetricKey class. This is because you still
302  // need an object to manage everything about the symmetric key. It stores
303  // the salt and the iteration count, as well as ONLY the ENCRYPTED version
304  // of the symmetric key, which is a completely random number and is only
305  // decrypted briefly for specific operations. The derived key (below) is
306  // what we use for briefly decrypting that actual (random) symmetric key.
307  //
308  // Therefore this function is mainly used INSIDE OTSymmetricKey as part of
309  // its internal operations.
310  //
311  // userPassword argument contains the user's password which is used to
312  // derive the key. Presumably you already obtained this passphrase...
313  // Then the derived key is returned, or nullptr if failure. CALLER
314  // IS RESPONSIBLE TO DELETE!
315  // Todo: return a smart pointer here.
316  //
317  virtual OTPassword* DeriveKey(
318  const OTPassword& userPassword, const OTPayload& dataSalt,
319  uint32_t uIterations,
320  const OTPayload& dataCheckHash = OTPayload()) const = 0;
321 
322  virtual OTPassword* DeriveNewKey(const OTPassword& userPassword,
323  const OTPayload& dataSalt,
324  uint32_t uIterations,
325  OTPayload& dataCheckHash) const = 0;
326 
327  // ENCRYPT / DECRYPT
328  //
329  // Symmetric (secret key) encryption / decryption
330  //
331  virtual bool Encrypt(
332  const OTPassword& theRawSymmetricKey, // The symmetric key, in clear
333  // form.
334  const char* szInput, // This is the Plaintext.
335  uint32_t lInputLength,
336  const OTPayload& theIV, // (We assume this IV is already generated and
337  // passed in.)
338  OTPayload& theEncryptedOutput) const = 0; // OUTPUT. (Ciphertext.)
339 
340  virtual bool Decrypt(const OTPassword& theRawSymmetricKey, // The symmetric
341  // key, in clear
342  // form.
343  const char* szInput, // This is the Ciphertext.
344  uint32_t lInputLength,
345  const OTPayload& theIV, // (We assume this IV is
346  // already generated and passed
347  // in.)
348  OTCrypto_Decrypt_Output theDecryptedOutput)
349  const = 0; // OUTPUT. (Recovered plaintext.) You can pass OTPassword& OR
350  // OTPayload& here (either will work.)
351  // SEAL / OPEN (RSA envelopes...)
352  //
353  // Asymmetric (public key) encryption / decryption
354  //
355  virtual bool Seal(mapOfAsymmetricKeys& RecipPubKeys,
356  const OTString& theInput, OTData& dataOutput) const = 0;
357 
358  virtual bool Open(OTData& dataInput, const OTPseudonym& theRecipient,
359  OTString& theOutput,
360  const OTPasswordData* pPWData = nullptr) const = 0;
361  // SIGN / VERIFY
362  //
363  // Sign or verify using the Asymmetric Key itself.
364  //
365  virtual bool SignContract(const OTString& strContractUnsigned,
366  const OTAsymmetricKey& theKey,
367  OTSignature& theSignature, // output
368  const OTString& strHashType,
369  const OTPasswordData* pPWData = nullptr) = 0;
370 
371  virtual bool VerifySignature(
372  const OTString& strContractToVerify, const OTAsymmetricKey& theKey,
373  const OTSignature& theSignature, const OTString& strHashType,
374  const OTPasswordData* pPWData = nullptr) const = 0;
375  // Sign or verify using the contents of a Certfile.
376  //
377  virtual bool SignContract(const OTString& strContractUnsigned,
378  const OTString& strSigHashType,
379  const std::string& strCertFileContents,
380  OTSignature& theSignature, // output
381  const OTPasswordData* pPWData = nullptr) = 0;
382 
383  virtual bool VerifySignature(
384  const OTString& strContractToVerify, const OTString& strSigHashType,
385  const std::string& strCertFileContents, const OTSignature& theSignature,
386  const OTPasswordData* pPWData = nullptr) const = 0;
387  EXPORT static OTCrypto* It();
388 
389  EXPORT void Init() const;
390  EXPORT void Cleanup() const;
391 };
392 
393 // OTCrypto (above) is the abstract base class which is used as an
394 // interface by the rest of OT.
395 //
396 // Whereas OTCrypto_OpenSSL (below) is the actual implementation, written using
397 // the OpenSSL library. Theoretically, a new implementation could someday be
398 // "swapped in" -- for example, using GPG or NaCl or Crypto++, etc.
399 
400 #if defined(OT_CRYPTO_USING_GPG)
401 
402 // Someday }:-) OTCrypto_GPG
403 
404 #elif defined(OT_CRYPTO_USING_OPENSSL)
405 
407 {
408  friend class OTCrypto;
409 
410 protected:
412  virtual void Init_Override() const;
413  virtual void Cleanup_Override() const;
414 
417 
418 public:
419  static std::mutex* s_arrayMutex;
420  // (To instantiate a text secret, just do this: OTPassword thePass;)
421  virtual OTPassword* InstantiateBinarySecret() const;
422  // RANDOM NUMBERS
423  virtual bool RandomizeMemory(uint8_t* szDestination,
424  uint32_t nNewSize) const;
425  // HASHING
426  virtual bool CalculateDigest(const OTString& strInput,
427  const OTString& strHashAlgorithm,
428  OTIdentifier& theOutput) const;
429  virtual bool CalculateDigest(const OTData& dataInput,
430  const OTString& strHashAlgorithm,
431  OTIdentifier& theOutput) const;
432  // BASE 62 ENCODING (for IDs)
433  virtual void SetIDFromBase62String(const OTString& strInput,
434  OTIdentifier& theOutput) const;
435  virtual void SetBase62StringFromID(const OTIdentifier& theInput,
436  OTString& strOutput) const;
437  // BASE 64 ENCODING
438  // Lower-level version:
439  // Caller is responsible to delete. Todo: return a unqiue pointer.
440  virtual char* Base64Encode(const uint8_t* input, int32_t in_len,
441  bool bLineBreaks) const; // todo security
442  // ('int32_t')
443  virtual uint8_t* Base64Decode(const char* input, size_t* out_len,
444  bool bLineBreaks) const;
445  // KEY DERIVATION
446  // userPassword argument contains the user's password which is used to
447  // derive the key. Presumably you already obtained this passphrase...
448  // Then the derived key is returned, or nullptr if failure. CALLER
449  // IS RESPONSIBLE TO DELETE!
450  // Todo: return a smart pointer here.
451  //
452  virtual OTPassword* DeriveKey(
453  const OTPassword& userPassword, const OTPayload& dataSalt,
454  uint32_t uIterations,
455  const OTPayload& dataCheckHash = OTPayload()) const;
456 
457  virtual OTPassword* DeriveNewKey(const OTPassword& userPassword,
458  const OTPayload& dataSalt,
459  uint32_t uIterations,
460  OTPayload& dataCheckHash) const;
461  // ENCRYPT / DECRYPT
462  // Symmetric (secret key) encryption / decryption
463  virtual bool Encrypt(
464  const OTPassword& theRawSymmetricKey, // The symmetric key, in clear
465  // form.
466  const char* szInput, // This is the Plaintext.
467  uint32_t lInputLength,
468  const OTPayload& theIV, // (We assume this IV is already generated and
469  // passed in.)
470  OTPayload& theEncryptedOutput) const; // OUTPUT. (Ciphertext.)
471 
472  virtual bool Decrypt(const OTPassword& theRawSymmetricKey, // The symmetric
473  // key, in clear
474  // form.
475  const char* szInput, // This is the Ciphertext.
476  uint32_t lInputLength,
477  const OTPayload& theIV, // (We assume this IV is
478  // already generated and passed
479  // in.)
480  OTCrypto_Decrypt_Output theDecryptedOutput)
481  const; // OUTPUT. (Recovered plaintext.) You can pass OTPassword& OR
482  // OTPayload& here (either will work.)
483  // SEAL / OPEN
484  // Asymmetric (public key) encryption / decryption
485  virtual bool Seal(mapOfAsymmetricKeys& RecipPubKeys,
486  const OTString& theInput, OTData& dataOutput) const;
487 
488  virtual bool Open(OTData& dataInput, const OTPseudonym& theRecipient,
489  OTString& theOutput,
490  const OTPasswordData* pPWData = nullptr) const;
491  // SIGN / VERIFY
492  // Sign or verify using the Asymmetric Key itself.
493  virtual bool SignContract(const OTString& strContractUnsigned,
494  const OTAsymmetricKey& theKey,
495  OTSignature& theSignature, // output
496  const OTString& strHashType,
497  const OTPasswordData* pPWData = nullptr);
498 
499  virtual bool VerifySignature(const OTString& strContractToVerify,
500  const OTAsymmetricKey& theKey,
501  const OTSignature& theSignature,
502  const OTString& strHashType,
503  const OTPasswordData* pPWData = nullptr) const;
504  // Sign or verify using the contents of a Certfile.
505  virtual bool SignContract(const OTString& strContractUnsigned,
506  const OTString& strSigHashType,
507  const std::string& strCertFileContents,
508  OTSignature& theSignature, // output
509  const OTPasswordData* pPWData = nullptr);
510 
511  virtual bool VerifySignature(const OTString& strContractToVerify,
512  const OTString& strSigHashType,
513  const std::string& strCertFileContents,
514  const OTSignature& theSignature,
515  const OTPasswordData* pPWData = nullptr) const;
516  void thread_setup() const;
517  void thread_cleanup() const;
518 
519  virtual ~OTCrypto_OpenSSL();
520 };
521 
522 #else // Apparently NO crypto engine is defined!
523 
524 // Perhaps error out here...
525 
526 #endif // if defined (OT_CRYPTO_USING_OPENSSL), elif defined
527  // (OT_CRYPTO_USING_GPG), else, endif.
528 
529 /*
530  ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-5v2/pkcs5v2_1.pdf
531 
532  4.2 Iteration count
533 
534  An iteration count has traditionally served the purpose of increasing
535  the cost of producing keys from a password, thereby also increasing
536  the difficulty of attack. For the methods in this document, a minimum
537  of 1000 iterations is recommended. This will increase the cost of
538  exhaustive search for passwords significantly, without a noticeable
539  impact in the cost of deriving individual keys.
540 
541  Time the KDF on your systems and see how many iterations are practical
542  without signficant resource impact on legitimate use cases. If it is
543  practical to make the count configurable, do so, otherwise hard-code
544  a sensible value that is at least 1000.
545 
546  The iteration count is a multiplier on the CPU cost of brute-force
547  dictionary attacks. If you are not sure that users are choosing "strong"
548  passwords (they rarely do), you want to make dictionary attacks difficult
549  by making individual password->key calculations sufficiently slow thereby
550  limiting the throughput of brute-force attacks.
551 
552  If no legitimate system is computing multiple password-based keys per
553  second, you could set the iteration count to consume 10-100ms of CPU
554  on 2008 processors, this is likely much more than 1000 iterations.
555  At a guess 1000 iterations will be O(1ms) per key on a typical modern CPU.
556  This is based on "openssl speed sha1" reporting:
557 
558  type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
559  sha1 18701.67k 49726.06k 104600.90k 141349.84k 157502.27k
560 
561  or about 10^6 16-byte SHA1 ops per second, doing 1000 iterations of HMAC
562  is approximately 2000 SHA1 ops and so should take about 2ms. In many
563  applications 10,000 or even 100,000 may be practical provided no
564  legitimate "actor" needs to perform password->key comptutations at
565  a moderately high rate.
566 
567  */
568 
569 /*
570  int32_t PKCS5_PBKDF2_HMAC_SHA1 (
571  const void* password,
572  size_t password_len,
573 
574  const void* salt,
575  size_t salt_len,
576 
577  uint64_t iter,
578 
579  size_t keylen,
580  void* key
581 )
582 */
583 
584 } // namespace opentxs
585 
586 #endif // OPENTXS_CORE_CRYPTO_OTCRYPTO_HPP
static EXPORT OTCrypto * It()
Definition: OTCrypto.cpp:630
virtual void Cleanup_Override() const
Definition: OTCrypto.cpp:704
virtual bool CalculateDigest(const OTString &strInput, const OTString &strHashAlgorithm, OTIdentifier &theOutput) const
Definition: OTCrypto.cpp:1659
static EXPORT uint32_t SymmetricIvSize()
Definition: OTCrypto.cpp:391
virtual bool SignContract(const OTString &strContractUnsigned, const OTAsymmetricKey &theKey, OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr)=0
virtual bool RandomizeMemory(uint8_t *szDestination, uint32_t nNewSize) const =0
virtual bool Encrypt(const OTPassword &theRawSymmetricKey, const char *szInput, uint32_t lInputLength, const OTPayload &theIV, OTPayload &theEncryptedOutput) const =0
virtual OTPassword * InstantiateBinarySecret() const =0
static EXPORT uint32_t IterationCount()
Definition: OTCrypto.cpp:375
EXPORT bool GetPasswordFromConsole(OTPassword &theOutput, bool bRepeat=false) const
Definition: OTCrypto.cpp:587
virtual void SetIDFromBase62String(const OTString &strInput, OTIdentifier &theOutput) const
Definition: OTCrypto.cpp:1351
virtual bool Decrypt(const OTPassword &theRawSymmetricKey, const char *szInput, uint32_t lInputLength, const OTPayload &theIV, OTCrypto_Decrypt_Output theDecryptedOutput) const
Definition: OTCrypto.cpp:2318
virtual bool SignContract(const OTString &strContractUnsigned, const OTAsymmetricKey &theKey, OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr)
Definition: OTCrypto.cpp:4770
virtual void Init_Override() const
Definition: OTCrypto.cpp:1814
virtual OTPassword * DeriveNewKey(const OTPassword &userPassword, const OTPayload &dataSalt, uint32_t uIterations, OTPayload &dataCheckHash) const
Definition: OTCrypto.cpp:1524
EXPORT bool Concatenate(const void *pAppendData, uint32_t lAppendSize) const
Definition: OTCrypto.cpp:855
virtual bool VerifySignature(const OTString &strContractToVerify, const OTAsymmetricKey &theKey, const OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr) const =0
virtual OTPassword * InstantiateBinarySecret() const
Definition: OTCrypto.cpp:1756
virtual bool RandomizeMemory(uint8_t *szDestination, uint32_t nNewSize) const
Definition: OTCrypto.cpp:1457
static EXPORT uint32_t SymmetricSaltSize()
Definition: OTCrypto.cpp:379
void thread_setup() const
Definition: OTCrypto.cpp:1773
static EXPORT uint32_t SymmetricKeySizeMax()
Definition: OTCrypto.cpp:387
EXPORT bool GetPasswordFromConsoleLowLevel(OTPassword &theOutput, const char *szPrompt) const
Definition: OTCrypto.cpp:488
static EXPORT uint32_t Digest1Size()
Definition: OTCrypto.cpp:407
virtual uint8_t * Base64Decode(const char *input, size_t *out_len, bool bLineBreaks) const
Definition: OTCrypto.cpp:1337
virtual bool Encrypt(const OTPassword &theRawSymmetricKey, const char *szInput, uint32_t lInputLength, const OTPayload &theIV, OTPayload &theEncryptedOutput) const
Definition: OTCrypto.cpp:2195
virtual void Cleanup_Override() const
Definition: OTCrypto.cpp:2122
static std::mutex * s_arrayMutex
Definition: OTCrypto.hpp:419
static EXPORT uint32_t SymmetricBufferSize()
Definition: OTCrypto.cpp:395
bool IsBase62(const std::string &str) const
Definition: OTCrypto.cpp:427
virtual bool Base64Encode(const OTData &theInput, OTString &strOutput, bool bLineBreaks=true) const
Definition: OTCrypto.cpp:710
EXPORT void swap(OTCrypto_Decrypt_Output &other)
Definition: OTCrypto.cpp:813
std::multimap< std::string, OTAsymmetricKey * > mapOfAsymmetricKeys
Definition: OTCrypto.hpp:155
OTCrypto_OpenSSLdp * dp
Definition: OTCrypto.hpp:415
virtual bool Seal(mapOfAsymmetricKeys &RecipPubKeys, const OTString &theInput, OTData &dataOutput) const
Definition: OTCrypto.cpp:2454
virtual bool Seal(mapOfAsymmetricKeys &RecipPubKeys, const OTString &theInput, OTData &dataOutput) const =0
static EXPORT uint32_t PublicKeysizeMax()
Definition: OTCrypto.cpp:403
virtual bool Open(OTData &dataInput, const OTPseudonym &theRecipient, OTString &theOutput, const OTPasswordData *pPWData=nullptr) const =0
EXPORT void Init() const
Definition: OTCrypto.cpp:646
virtual bool CalculateDigest(const OTString &strInput, const OTString &strHashAlgorithm, OTIdentifier &theOutput) const =0
EXPORT OTCrypto_Decrypt_Output & operator=(OTCrypto_Decrypt_Output other)
Definition: OTCrypto.cpp:826
void thread_cleanup() const
Definition: OTCrypto.cpp:1803
static EXPORT uint32_t Digest2Size()
Definition: OTCrypto.cpp:411
virtual bool Decrypt(const OTPassword &theRawSymmetricKey, const char *szInput, uint32_t lInputLength, const OTPayload &theIV, OTCrypto_Decrypt_Output theDecryptedOutput) const =0
EXPORT void Release_Envelope_Decrypt_Output() const
Definition: OTCrypto.cpp:848
static EXPORT uint32_t PublicKeysize()
Definition: OTCrypto.cpp:399
EXPORT void Cleanup() const
Definition: OTCrypto.cpp:678
virtual bool Base64Decode(const OTString &strInput, OTData &theOutput, bool bLineBreaks=true) const
Definition: OTCrypto.cpp:740
virtual void SetBase62StringFromID(const OTIdentifier &theInput, OTString &strOutput) const
Definition: OTCrypto.cpp:1422
virtual void Init_Override() const
Definition: OTCrypto.cpp:697
virtual char * Base64Encode(const uint8_t *input, int32_t in_len, bool bLineBreaks) const
Definition: OTCrypto.cpp:1330
virtual bool VerifySignature(const OTString &strContractToVerify, const OTAsymmetricKey &theKey, const OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr) const
Definition: OTCrypto.cpp:4796
virtual bool Open(OTData &dataInput, const OTPseudonym &theRecipient, OTString &theOutput, const OTPasswordData *pPWData=nullptr) const
Definition: OTCrypto.cpp:3007
virtual void SetBase62StringFromID(const OTIdentifier &theInput, OTString &strOutput) const =0
virtual OTPassword * DeriveNewKey(const OTPassword &userPassword, const OTPayload &dataSalt, uint32_t uIterations, OTPayload &dataCheckHash) const =0
virtual OTPassword * DeriveKey(const OTPassword &userPassword, const OTPayload &dataSalt, uint32_t uIterations, const OTPayload &dataCheckHash=OTPayload()) const =0
virtual void SetIDFromBase62String(const OTString &strInput, OTIdentifier &theOutput) const =0
virtual ~OTCrypto()
Definition: OTCrypto.cpp:423
virtual OTPassword * DeriveKey(const OTPassword &userPassword, const OTPayload &dataSalt, uint32_t uIterations, const OTPayload &dataCheckHash=OTPayload()) const
Definition: OTCrypto.cpp:1514
static EXPORT uint32_t SymmetricKeySize()
Definition: OTCrypto.cpp:383