acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
crypto.h
1#pragma once
2
3
5
6
7namespace crypto
8{
9
10
11 class rsa;
12
13
14 class initializer;
15
16
17 class CLASS_DECL_ACME crypto :
18 virtual public ::object
19 {
20 public:
21
22
23 // salt here may be dangerous for the universe
24
25 ::pointer<::crypto::initializer> m_pinitializer;
26
27
28 crypto();
29 ~crypto() override;
30
31
32 virtual void defer_initialize();
33
34
35 virtual ::pointer<::crypto::hasher_algorithm>create_hasher_algorithm(enum_hash ehash);
36 virtual ::pointer<::crypto::hasher>create_hasher(enum_hash ehash);
37
38
39 virtual void encrypt(memory& storageEncrypt, const block & blockDecrypt, const block & blockKey) = 0;
40 virtual void decrypt(memory& storageDecrypt, const block & blockEncrypt, const block & blockKey) = 0;
41
42
43 //virtual void encrypt(memory & blockEncrypt, const block & blockDecrypt, const ::scoped_string & scopedstrSalt);
44 //virtual void decrypt(memory & blockDecrypt, const block & blockEncrypt, const ::scoped_string & scopedstrSalt);
45 //virtual void encrypt(memory & storageEncrypt, const ::scoped_string & scopedstrDecrypt, const ::scoped_string & scopedstrSalt);
46 //virtual void decrypt(string & strDecrypt, const memory & storageEncrypt, const ::scoped_string & scopedstrSalt);
47
48
49 virtual ::i32 key(memory & storage);
50
51 virtual string strkey();
52 virtual void encrypt(string & str, const block & blockDecrypt, const block & blockKey);
53 virtual void decrypt(string & str, const block & blockEncrypt, const block & blockKey);
54
55
56 virtual ::i32 get_md5_digest_length() const;
57 virtual ::i32 get_sha1_digest_length() const;
58 virtual ::i32 get_sha256_digest_length() const;
59 virtual ::i32 get_nessie_digest_length() const;
60
61
62 //virtual ::u32 crc32(::u32 dwPrevious, const ::scoped_string & scopedstr) = 0;
63 //virtual string md5(const ::scoped_string & scopedstr);
64 //virtual string sha1(const ::scoped_string & scopedstr);
65 //virtual string nessie(const ::scoped_string & scopedstr);
66
67 virtual string md5(const block & block);
68 virtual string sha1(const block & block);
69 virtual string nessie(const block & block);
70
71 virtual ::i32 get_hash_digest_length(enum_hash) const = 0;
72
73 virtual void hash(memory& memOut, const block & blockIn, enum_hash ehash);
74
75
76 virtual void md5(memory & memMd5, const block& block);
77 virtual void sha1(memory & memSha1, const block& block);
78 virtual void sha256(memory & memSha256, const block& block);
79 virtual void nessie(memory & memNessie, const block& block);
80
81 // result is 20-::u8 digest
82 virtual void hmac(void * result,const memory & memMessage,const memory & key) = 0;
83 virtual void hmac(void * result,const ::scoped_string & scopedstrMessage,const ::scoped_string & scopedstrKey) = 0;
84
85 virtual void file_set(::payload payloadFile,const ::scoped_string & scopedstrData,const ::scoped_string & scopedstrSalt, ::platform::application * papp);
86 virtual void file_get(::payload payloadFile,string & str,const ::scoped_string & scopedstrSalt, ::platform::application * papp);
87
88 // get a ___new salt - 8 hexadecimal characters long
89 // current PHP installations should not exceed 8 characters
90 // on dechex( mt_rand() )
91 // but we future proof it anyway with substr()
92 virtual string v5_get_password_salt();
93 // calculate the hash from a salt and a password
94 virtual string v5_get_password_hash(const ::scoped_string & scopedstrSalt,const ::scoped_string & scopedstrPassword,::i32 iOrder = 0);
95 virtual string v5_get_passhash(const ::scoped_string & scopedstrSalt,const ::scoped_string & scopedstrPassword,::i32 iMaxOrder = 0);
96 virtual bool v5_compare_password(const ::scoped_string & scopedstrPassword,const ::scoped_string & scopedstrHash,::i32 iOrder = 0);
97 // if iOrder == 0 password is plain
98 // if iOrder == 1 password is the first hash
99 // if iOrder == (n > 0) password is the nth hash
100 virtual bool v5_validate_plain_password(const ::scoped_string & scopedstrPassword);
101 virtual string v5_get_password_hash(const ::scoped_string & scopedstrPassword,::i32 iOrder = 0);
102
103 virtual ::file::path get_crypt_key_file_path();
104 virtual ::memory defer_get_cryptkey();
105
106
107 virtual ::pointer<rsa>create_rsa_key(const ::scoped_string & scopedstrRsa);
108
109 virtual ::pointer<rsa>generate_rsa_key();
110
111 virtual ::pointer<rsa>read_priv_pem(const ::scoped_string & scopedstrFile);
112
113 virtual ::pointer<rsa>read_pub_pem(const ::scoped_string & scopedstrFile);
114
115
116 //void err_load_rsa_strings();
117
118
119 //void err_load_crypto_strings();
120
121
122 virtual string spa_login_crypt(const ::scoped_string & scopedstr,const ::scoped_string & scopedstrRsa);
123 virtual string spa_login_decrypt(const ::scoped_string & scopedstr,const ::scoped_string & scopedstrRsa);
124
125 virtual string spa_auth_crypt(const ::scoped_string & scopedstr,rsa * prsa);
126 virtual string spa_auth_decrypt(const ::scoped_string & scopedstr,rsa * prsa);
127 virtual string spa_auth_decrypt(const ::scoped_string & scopedstr,const ::scoped_string & scopedstrRsa);
128
129 virtual string txt_encrypt(const ::scoped_string & scopedstr,rsa * prsa);
130 virtual string txt_decrypt(const ::scoped_string & scopedstr,rsa * prsa);
131
132 //virtual void np_make_zigbert_rsa(const ::scoped_string & scopedstrDir, const ::scoped_string & scopedstrSignerPath, const ::scoped_string & scopedstrKeyPath, const ::scoped_string & scopedstrOthersPath, const ::scoped_string & scopedstrSignature);
133
134
135
136
137
138 };
139
140
141} // namespace crypto
142
143
144
145
146
147
148CLASS_DECL_ACME void stunCalculateIntegrity_longterm(char_pointer hmac, const_char_pointer input, ::i32 length, const_char_pointer username, const_char_pointer realm, const_char_pointer password);
149
150CLASS_DECL_ACME void stunCalculateIntegrity_shortterm(char_pointer hmac, const_char_pointer input, ::i32 length, const_char_pointer key);
151
152
153CLASS_DECL_ACME void hmac_evp_sha1_1234(::u8 * hmac, ::u32 * hmacSize, const ::u8 * buf, size_t bufLen);
Definition initializer.h:18
Definition rsa.h:13
Definition memory.h:33
Definition application.h:65
Definition block.h:46