SSP21-CPP
Crypto.h
1 
2 #ifndef SSP21_CRYTPTO_H
3 #define SSP21_CRYTPTO_H
4 
5 #include "ssp21/crypto/ICryptoBackend.h"
6 
7 #include <memory>
8 
9 namespace ssp21
10 {
11  /**
12  * Assumming for the time being that a static backend is fine
13  * to keep dependency injection simple.
14  */
16  {
17 
18  static std::shared_ptr<ICryptoBackend> backend;
19 
20  public:
21 
22  // --- Inject a backend. Callable only once ---
23 
24  static bool initialize(const std::shared_ptr<ICryptoBackend>& backend);
25 
26  // --- proxy functions that invoke the static backend, enforcing preconditions ---
27 
28  static void zero_memory(const wseq32_t& data);
29 
30  static void gen_random(const wseq32_t& dest);
31 
32  static bool secure_equals(const seq32_t& lhs, const seq32_t& rhs);
33 
34  static void hash_sha256(
35  const std::initializer_list<seq32_t>& data,
36  SecureBuffer& output
37  );
38 
39  static void hmac_sha256(
40  const seq32_t& key,
41  const std::initializer_list<seq32_t>& data,
42  SecureBuffer& output
43  );
44 
45  static void gen_keypair_x25519(KeyPair& pair);
46 
47  static void dh_x25519(
48  const PrivateKey& priv_key,
49  const seq32_t& pub_key,
50  DHOutput& output,
51  std::error_code& ec
52  );
53 
54  static void hkdf_sha256(
55  const seq32_t& salt,
56  const std::initializer_list<seq32_t>& input_key_material,
57  SymmetricKey& key1,
58  SymmetricKey& key2
59  );
60 
61  static void gen_keypair_ed25519(KeyPair& pair);
62 
63  static void sign_ed25519(const seq32_t& input, const seq32_t& private_key, DSAOutput& output, std::error_code& ec);
64 
65  static bool verify_ed25519(const seq32_t& message, const seq32_t& signature, const seq32_t& public_key);
66 
67  };
68 }
69 
70 #endif
SSP21-cpp main namespace.
Definition: BufferTypes.h:12