/work/toxencryptsave/toxencryptsave.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2026 The TokTok team. |
3 | | * Copyright © 2013 Tox project. |
4 | | */ |
5 | | |
6 | | /** |
7 | | * Batch encryption functions. |
8 | | */ |
9 | | #include "toxencryptsave.h" |
10 | | |
11 | | #include <sodium.h> |
12 | | |
13 | | #include <stdlib.h> |
14 | | #include <string.h> |
15 | | |
16 | | #include "../toxcore/ccompat.h" |
17 | | #include "../toxcore/crypto_core.h" |
18 | | #include "../toxcore/mem.h" |
19 | | #include "../toxcore/os_memory.h" |
20 | | #include "../toxcore/os_random.h" |
21 | | #include "../toxcore/rng.h" |
22 | | #include "defines.h" |
23 | | |
24 | | static_assert(TOX_PASS_SALT_LENGTH == crypto_pwhash_scryptsalsa208sha256_SALTBYTES, |
25 | | "TOX_PASS_SALT_LENGTH is assumed to be equal to crypto_pwhash_scryptsalsa208sha256_SALTBYTES"); |
26 | | static_assert(TOX_PASS_KEY_LENGTH == CRYPTO_SHARED_KEY_SIZE, |
27 | | "TOX_PASS_KEY_LENGTH is assumed to be equal to CRYPTO_SHARED_KEY_SIZE"); |
28 | | static_assert(TOX_PASS_ENCRYPTION_EXTRA_LENGTH == (crypto_box_MACBYTES + crypto_box_NONCEBYTES + |
29 | | crypto_pwhash_scryptsalsa208sha256_SALTBYTES + TOX_ENC_SAVE_MAGIC_LENGTH), |
30 | | "TOX_PASS_ENCRYPTION_EXTRA_LENGTH is assumed to be equal to (crypto_box_MACBYTES + crypto_box_NONCEBYTES + crypto_pwhash_scryptsalsa208sha256_SALTBYTES + TOX_ENC_SAVE_MAGIC_LENGTH)"); |
31 | | |
32 | | #define SET_ERROR_PARAMETER(param, x) \ |
33 | 29 | do { \ |
34 | 29 | if (param != nullptr) { \ |
35 | 23 | *param = x; \ |
36 | 23 | } \ |
37 | 29 | } while (0) |
38 | | |
39 | | uint32_t tox_pass_salt_length(void) |
40 | 0 | { |
41 | 0 | return TOX_PASS_SALT_LENGTH; |
42 | 0 | } |
43 | | uint32_t tox_pass_key_length(void) |
44 | 0 | { |
45 | 0 | return TOX_PASS_KEY_LENGTH; |
46 | 0 | } |
47 | | uint32_t tox_pass_encryption_extra_length(void) |
48 | 0 | { |
49 | 0 | return TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
50 | 0 | } |
51 | | |
52 | | struct Tox_Pass_Key { |
53 | | uint8_t salt[TOX_PASS_SALT_LENGTH]; |
54 | | uint8_t key[TOX_PASS_KEY_LENGTH]; |
55 | | }; |
56 | | |
57 | | void tox_pass_key_free(Tox_Pass_Key *_Nullable key) |
58 | 13 | { |
59 | 13 | if (key == nullptr) { |
60 | 0 | return; |
61 | 0 | } |
62 | | |
63 | | /* wipe sensitive state */ |
64 | 13 | crypto_memzero(key->salt, TOX_PASS_SALT_LENGTH); |
65 | 13 | crypto_memzero(key->key, TOX_PASS_KEY_LENGTH); |
66 | 13 | free(key); |
67 | 13 | } |
68 | | |
69 | | /* Clients should consider alerting their users that, unlike plain data, if even one bit |
70 | | * becomes corrupted, the data will be entirely unrecoverable. |
71 | | * Ditto if they forget their password, there is no way to recover the data. |
72 | | */ |
73 | | |
74 | | /** |
75 | | * Retrieves the salt used to encrypt the given data. |
76 | | * |
77 | | * The retrieved salt can then be passed to tox_pass_key_derive_with_salt to |
78 | | * produce the same key as was previously used. Any data encrypted with this |
79 | | * module can be used as input. |
80 | | * |
81 | | * The cipher text must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in |
82 | | * length. |
83 | | * The salt must be TOX_PASS_SALT_LENGTH bytes in length. |
84 | | * If the passed byte arrays are smaller than required, the behaviour is |
85 | | * undefined. |
86 | | * |
87 | | * If the cipher text pointer or the salt is NULL, this function returns false. |
88 | | * |
89 | | * Success does not say anything about the validity of the data, only that |
90 | | * data of the appropriate size was copied. |
91 | | * |
92 | | * @param ciphertext The encrypted data; at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes are read. |
93 | | * @param salt An array of exactly TOX_PASS_SALT_LENGTH bytes to write the salt to. |
94 | | * |
95 | | * @return true on success. |
96 | | */ |
97 | | bool tox_get_salt( |
98 | | const uint8_t ciphertext[TOX_PASS_ENCRYPTION_EXTRA_LENGTH], |
99 | | Tox_Pass_Salt salt, Tox_Err_Get_Salt *_Nullable error) |
100 | 1 | { |
101 | 1 | if (ciphertext == nullptr || salt == nullptr) { |
102 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_NULL); |
103 | 0 | return false; |
104 | 0 | } |
105 | | |
106 | 1 | if (memcmp(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { |
107 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_BAD_FORMAT); |
108 | 0 | return false; |
109 | 0 | } |
110 | | |
111 | 1 | ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; |
112 | 1 | memcpy(salt, ciphertext, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); |
113 | 1 | SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_OK); |
114 | 1 | return true; |
115 | 1 | } |
116 | | |
117 | | /** |
118 | | * Generates a secret symmetric key from the given passphrase. |
119 | | * |
120 | | * Be sure to not compromise the key! Only keep it in memory, do not write |
121 | | * it to disk. |
122 | | * |
123 | | * Note that this function is not deterministic; to derive the same key from |
124 | | * a password, you also must know the random salt that was used. A |
125 | | * deterministic version of this function is `tox_pass_key_derive_with_salt`. |
126 | | * |
127 | | * @param passphrase The user-provided password. Can be empty. |
128 | | * @param passphrase_len The length of the password. |
129 | | * |
130 | | * @return new symmetric key on success, NULL on failure. |
131 | | */ |
132 | | Tox_Pass_Key *_Nullable tox_pass_key_derive( |
133 | | const uint8_t passphrase[], size_t passphrase_len, |
134 | | Tox_Err_Key_Derivation *_Nullable error) |
135 | 6 | { |
136 | 6 | const Random *rng = os_random(); |
137 | | |
138 | 6 | if (rng == nullptr) { |
139 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_FAILED); |
140 | 0 | return nullptr; |
141 | 0 | } |
142 | | |
143 | 6 | uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; |
144 | 6 | random_bytes(rng, salt, sizeof(salt)); |
145 | 6 | return tox_pass_key_derive_with_salt(passphrase, passphrase_len, salt, error); |
146 | 6 | } |
147 | | |
148 | | /** |
149 | | * Same as above, except use the given salt for deterministic key derivation. |
150 | | * |
151 | | * @param passphrase The user-provided password. Can be empty. |
152 | | * @param passphrase_len The length of the password. |
153 | | * @param salt An array of exactly TOX_PASS_SALT_LENGTH bytes. |
154 | | * |
155 | | * @return new symmetric key on success, NULL on failure. |
156 | | */ |
157 | | Tox_Pass_Key *_Nullable tox_pass_key_derive_with_salt( |
158 | | const uint8_t passphrase[], size_t passphrase_len, |
159 | | const Tox_Pass_Salt salt, Tox_Err_Key_Derivation *_Nullable error) |
160 | 13 | { |
161 | 13 | if (salt == nullptr || (passphrase == nullptr && passphrase_len != 0)) { |
162 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); |
163 | 0 | return nullptr; |
164 | 0 | } |
165 | | |
166 | 13 | uint8_t passkey[crypto_hash_sha256_BYTES]; |
167 | 13 | crypto_hash_sha256(passkey, passphrase, passphrase_len); |
168 | | |
169 | 13 | uint8_t key[CRYPTO_SHARED_KEY_SIZE]; |
170 | | |
171 | | // Derive a key from the password |
172 | | // http://doc.libsodium.org/key_derivation/README.html |
173 | | // note that, according to the documentation, a generic pwhash interface will be created |
174 | | // once the pwhash competition (https://password-hashing.net/) is over */ |
175 | 13 | if (crypto_pwhash_scryptsalsa208sha256( |
176 | 13 | key, sizeof(key), (char *)passkey, sizeof(passkey), salt, |
177 | 13 | crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 2, /* slightly stronger */ |
178 | 13 | crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) != 0) { |
179 | | /* out of memory most likely */ |
180 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_FAILED); |
181 | 0 | return nullptr; |
182 | 0 | } |
183 | | |
184 | 13 | crypto_memzero(passkey, crypto_hash_sha256_BYTES); /* wipe plaintext pw */ |
185 | | |
186 | 13 | Tox_Pass_Key *out_key = (Tox_Pass_Key *)calloc(1, sizeof(Tox_Pass_Key)); |
187 | | |
188 | 13 | if (out_key == nullptr) { |
189 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_FAILED); |
190 | 0 | return nullptr; |
191 | 0 | } |
192 | | |
193 | 13 | memcpy(out_key->salt, salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); |
194 | 13 | memcpy(out_key->key, key, CRYPTO_SHARED_KEY_SIZE); |
195 | 13 | SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_OK); |
196 | 13 | return out_key; |
197 | 13 | } |
198 | | |
199 | | /** |
200 | | * Encrypt a plain text with a key produced by tox_pass_key_derive or |
201 | | * tox_pass_key_derive_with_salt. |
202 | | * |
203 | | * The output array must be at least |
204 | | * `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. |
205 | | * |
206 | | * @param plaintext A byte array of length `plaintext_len`. |
207 | | * @param plaintext_len The length of the plain text array. Bigger than 0. |
208 | | * @param ciphertext The cipher text array to write the encrypted data to. |
209 | | * |
210 | | * @return true on success. |
211 | | */ |
212 | | bool tox_pass_key_encrypt(const Tox_Pass_Key *_Nonnull key, const uint8_t plaintext[], size_t plaintext_len, |
213 | | uint8_t ciphertext[], Tox_Err_Encryption *_Nullable error) |
214 | 6 | { |
215 | 6 | const Memory *mem = os_memory(); |
216 | 6 | const Random *rng = os_random(); |
217 | | |
218 | 6 | if (mem == nullptr || rng == nullptr) { |
219 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_FAILED); |
220 | 0 | return false; |
221 | 0 | } |
222 | | |
223 | 6 | if (plaintext_len == 0 || plaintext == nullptr || key == nullptr || ciphertext == nullptr) { |
224 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_NULL); |
225 | 0 | return false; |
226 | 0 | } |
227 | | |
228 | | // the output data consists of, in order: |
229 | | // salt, nonce, mac, enc_data |
230 | | // where the mac is automatically prepended by the encrypt() |
231 | | // the salt+nonce is called the prefix |
232 | | // I'm not sure what else I'm supposed to do with the salt and nonce, since we |
233 | | // need them to decrypt the data |
234 | | |
235 | | /* first add the magic number */ |
236 | 6 | memcpy(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH); |
237 | 6 | ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; |
238 | | |
239 | | /* then add the rest prefix */ |
240 | 6 | memcpy(ciphertext, key->salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); |
241 | 6 | ciphertext += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; |
242 | | |
243 | 6 | uint8_t nonce[crypto_box_NONCEBYTES]; |
244 | 6 | random_nonce(rng, nonce); |
245 | 6 | memcpy(ciphertext, nonce, crypto_box_NONCEBYTES); |
246 | 6 | ciphertext += crypto_box_NONCEBYTES; |
247 | | |
248 | | /* now encrypt */ |
249 | 6 | const int32_t encrypted_len = encrypt_data_symmetric((const Memory * _Nonnull)mem, key->key, nonce, plaintext, plaintext_len, ciphertext); |
250 | 6 | if (encrypted_len < 0 || (size_t)encrypted_len != plaintext_len + crypto_box_MACBYTES) { |
251 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_FAILED); |
252 | 0 | return false; |
253 | 0 | } |
254 | | |
255 | 6 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_OK); |
256 | 6 | return true; |
257 | 6 | } |
258 | | |
259 | | /** |
260 | | * Encrypts the given data with the given passphrase. |
261 | | * |
262 | | * The output array must be at least |
263 | | * `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. This delegates |
264 | | * to tox_pass_key_derive and tox_pass_key_encrypt. |
265 | | * |
266 | | * @param plaintext A byte array of length `plaintext_len`. |
267 | | * @param plaintext_len The length of the plain text array. Bigger than 0. |
268 | | * @param passphrase The user-provided password. Can be empty. |
269 | | * @param passphrase_len The length of the password. |
270 | | * @param ciphertext The cipher text array to write the encrypted data to. |
271 | | * |
272 | | * @return true on success. |
273 | | */ |
274 | | bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uint8_t passphrase[], size_t passphrase_len, |
275 | | uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *_Nullable error) |
276 | 4 | { |
277 | 4 | Tox_Err_Key_Derivation err; |
278 | 4 | Tox_Pass_Key *key = tox_pass_key_derive(passphrase, passphrase_len, &err); |
279 | | |
280 | 4 | if (key == nullptr) { |
281 | 0 | if (err == TOX_ERR_KEY_DERIVATION_NULL) { |
282 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_NULL); |
283 | 0 | } else if (err == TOX_ERR_KEY_DERIVATION_FAILED) { |
284 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_KEY_DERIVATION_FAILED); |
285 | 0 | } |
286 | |
|
287 | 0 | return false; |
288 | 0 | } |
289 | | |
290 | 4 | const bool result = tox_pass_key_encrypt(key, plaintext, plaintext_len, ciphertext, error); |
291 | 4 | tox_pass_key_free(key); |
292 | 4 | return result; |
293 | 4 | } |
294 | | |
295 | | /** |
296 | | * This is the inverse of tox_pass_key_encrypt, also using only keys produced by |
297 | | * tox_pass_key_derive or tox_pass_key_derive_with_salt. |
298 | | * |
299 | | * @param ciphertext A byte array of length `ciphertext_len`. |
300 | | * @param ciphertext_len The length of the cipher text array. At least |
301 | | * TOX_PASS_ENCRYPTION_EXTRA_LENGTH. |
302 | | * @param plaintext The plain text array to write the decrypted data to. |
303 | | * |
304 | | * @return true on success. |
305 | | */ |
306 | | bool tox_pass_key_decrypt(const Tox_Pass_Key *_Nonnull key, const uint8_t ciphertext[], size_t ciphertext_len, |
307 | | uint8_t plaintext[], Tox_Err_Decryption *_Nullable error) |
308 | 8 | { |
309 | 8 | const Memory *mem = os_memory(); |
310 | | |
311 | 8 | if (mem == nullptr) { |
312 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_FAILED); |
313 | 0 | return false; |
314 | 0 | } |
315 | | |
316 | 8 | if (ciphertext_len <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { |
317 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); |
318 | 0 | return false; |
319 | 0 | } |
320 | | |
321 | 8 | if (ciphertext == nullptr || key == nullptr || plaintext == nullptr) { |
322 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_NULL); |
323 | 0 | return false; |
324 | 0 | } |
325 | | |
326 | 8 | if (memcmp(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { |
327 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); |
328 | 0 | return false; |
329 | 0 | } |
330 | | |
331 | 8 | ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; |
332 | 8 | ciphertext += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; // salt only affects key derivation |
333 | | |
334 | 8 | const size_t decrypt_length = ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
335 | | |
336 | 8 | uint8_t nonce[crypto_box_NONCEBYTES]; |
337 | 8 | memcpy(nonce, ciphertext, crypto_box_NONCEBYTES); |
338 | 8 | ciphertext += crypto_box_NONCEBYTES; |
339 | | |
340 | | /* decrypt the ciphertext */ |
341 | 8 | const int32_t decrypted_len = decrypt_data_symmetric((const Memory * _Nonnull)mem, key->key, nonce, ciphertext, decrypt_length + crypto_box_MACBYTES, plaintext); |
342 | 8 | if (decrypted_len < 0 || (size_t)decrypted_len != decrypt_length) { |
343 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_FAILED); |
344 | 0 | return false; |
345 | 0 | } |
346 | | |
347 | 8 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_OK); |
348 | 8 | return true; |
349 | 8 | } |
350 | | |
351 | | /** |
352 | | * Decrypts the given data with the given passphrase. |
353 | | * |
354 | | * The output array must be at least |
355 | | * `ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. This |
356 | | * delegates to tox_pass_key_decrypt. |
357 | | * |
358 | | * @param ciphertext A byte array of length `ciphertext_len`. |
359 | | * @param ciphertext_len The length of the cipher text array. At least |
360 | | * TOX_PASS_ENCRYPTION_EXTRA_LENGTH. |
361 | | * @param passphrase The user-provided password. Can be empty. |
362 | | * @param passphrase_len The length of the password. |
363 | | * @param plaintext The plain text array to write the decrypted data to. |
364 | | * |
365 | | * @return true on success. |
366 | | */ |
367 | | bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const uint8_t passphrase[], |
368 | | size_t passphrase_len, uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *_Nullable error) |
369 | 7 | { |
370 | 7 | if (ciphertext_len <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { |
371 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); |
372 | 0 | return false; |
373 | 0 | } |
374 | | |
375 | 7 | if (ciphertext == nullptr || passphrase == nullptr || plaintext == nullptr) { |
376 | 1 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_NULL); |
377 | 1 | return false; |
378 | 1 | } |
379 | | |
380 | 6 | if (memcmp(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) != 0) { |
381 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_BAD_FORMAT); |
382 | 0 | return false; |
383 | 0 | } |
384 | | |
385 | 6 | uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; |
386 | 6 | memcpy(salt, ciphertext + TOX_ENC_SAVE_MAGIC_LENGTH, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); |
387 | | |
388 | | /* derive the key */ |
389 | 6 | Tox_Pass_Key *key = tox_pass_key_derive_with_salt(passphrase, passphrase_len, salt, nullptr); |
390 | | |
391 | 6 | if (key == nullptr) { |
392 | | /* out of memory most likely */ |
393 | 0 | SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_KEY_DERIVATION_FAILED); |
394 | 0 | return false; |
395 | 0 | } |
396 | | |
397 | 6 | const bool result = tox_pass_key_decrypt(key, ciphertext, ciphertext_len, plaintext, error); |
398 | 6 | tox_pass_key_free(key); |
399 | 6 | return result; |
400 | 6 | } |
401 | | |
402 | | /** |
403 | | * Determines whether or not the given data is encrypted by this module. |
404 | | * |
405 | | * It does this check by verifying that the magic number is the one put in |
406 | | * place by the encryption functions. |
407 | | * |
408 | | * The data must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length. |
409 | | * If the passed byte array is smaller than required, the behaviour is |
410 | | * undefined. |
411 | | * |
412 | | * If the data pointer is NULL, the behaviour is undefined |
413 | | * |
414 | | * @param data The data to check; at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes are read. |
415 | | * |
416 | | * @return true if the data is encrypted by this module. |
417 | | */ |
418 | | bool tox_is_data_encrypted(const uint8_t data[TOX_PASS_ENCRYPTION_EXTRA_LENGTH]) |
419 | 2 | { |
420 | 2 | return memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0; |
421 | 2 | } |
422 | | |
423 | | const char *_Nonnull tox_err_key_derivation_to_string(Tox_Err_Key_Derivation error) |
424 | 0 | { |
425 | 0 | switch (error) { |
426 | 0 | case TOX_ERR_KEY_DERIVATION_OK: |
427 | 0 | return "TOX_ERR_KEY_DERIVATION_OK"; |
428 | 0 | case TOX_ERR_KEY_DERIVATION_NULL: |
429 | 0 | return "TOX_ERR_KEY_DERIVATION_NULL"; |
430 | 0 | case TOX_ERR_KEY_DERIVATION_FAILED: |
431 | 0 | return "TOX_ERR_KEY_DERIVATION_FAILED"; |
432 | 0 | } |
433 | 0 | return "<invalid Tox_Err_Key_Derivation>"; |
434 | 0 | } |
435 | | |
436 | | const char *_Nonnull tox_err_encryption_to_string(Tox_Err_Encryption error) |
437 | 0 | { |
438 | 0 | switch (error) { |
439 | 0 | case TOX_ERR_ENCRYPTION_OK: |
440 | 0 | return "TOX_ERR_ENCRYPTION_OK"; |
441 | 0 | case TOX_ERR_ENCRYPTION_NULL: |
442 | 0 | return "TOX_ERR_ENCRYPTION_NULL"; |
443 | 0 | case TOX_ERR_ENCRYPTION_KEY_DERIVATION_FAILED: |
444 | 0 | return "TOX_ERR_ENCRYPTION_KEY_DERIVATION_FAILED"; |
445 | 0 | case TOX_ERR_ENCRYPTION_FAILED: |
446 | 0 | return "TOX_ERR_ENCRYPTION_FAILED"; |
447 | 0 | } |
448 | 0 | return "<invalid Tox_Err_Encryption>"; |
449 | 0 | } |
450 | | |
451 | | const char *_Nonnull tox_err_decryption_to_string(Tox_Err_Decryption error) |
452 | 0 | { |
453 | 0 | switch (error) { |
454 | 0 | case TOX_ERR_DECRYPTION_OK: |
455 | 0 | return "TOX_ERR_DECRYPTION_OK"; |
456 | 0 | case TOX_ERR_DECRYPTION_NULL: |
457 | 0 | return "TOX_ERR_DECRYPTION_NULL"; |
458 | 0 | case TOX_ERR_DECRYPTION_INVALID_LENGTH: |
459 | 0 | return "TOX_ERR_DECRYPTION_INVALID_LENGTH"; |
460 | 0 | case TOX_ERR_DECRYPTION_BAD_FORMAT: |
461 | 0 | return "TOX_ERR_DECRYPTION_BAD_FORMAT"; |
462 | 0 | case TOX_ERR_DECRYPTION_KEY_DERIVATION_FAILED: |
463 | 0 | return "TOX_ERR_DECRYPTION_KEY_DERIVATION_FAILED"; |
464 | 0 | case TOX_ERR_DECRYPTION_FAILED: |
465 | 0 | return "TOX_ERR_DECRYPTION_FAILED"; |
466 | 0 | } |
467 | 0 | return "<invalid Tox_Err_Decryption>"; |
468 | 0 | } |
469 | | |
470 | | const char *_Nonnull tox_err_get_salt_to_string(Tox_Err_Get_Salt error) |
471 | 0 | { |
472 | 0 | switch (error) { |
473 | 0 | case TOX_ERR_GET_SALT_OK: |
474 | 0 | return "TOX_ERR_GET_SALT_OK"; |
475 | 0 | case TOX_ERR_GET_SALT_NULL: |
476 | 0 | return "TOX_ERR_GET_SALT_NULL"; |
477 | 0 | case TOX_ERR_GET_SALT_BAD_FORMAT: |
478 | 0 | return "TOX_ERR_GET_SALT_BAD_FORMAT"; |
479 | 0 | } |
480 | 0 | return "<invalid Tox_Err_Get_Salt>"; |
481 | 0 | } |