forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 291
/
Copy pathcreate_minimal_savedata.c
47 lines (37 loc) · 1.82 KB
/
create_minimal_savedata.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* SPDX-License-Identifier: GPL-3.0-or-later
*
* Creates minimal Tox savedata for a given secret key, if provided, or a random key otherwise.
* The data is written to stderr, human-readable key info is written to stdout.
*
* Build: gcc -o create_minimal_savedata create_minimal_savedata.c -lsodium -std=c99
*
* Usage: ./create_minimal_savedata [secret-key] 2>data
*/
#include <stdio.h>
#include <sodium.h>
#include "create_common.h"
int main(const int argc, const char *const argv[])
{
init_sodium();
unsigned char public_key[crypto_box_PUBLICKEYBYTES];
unsigned char secret_key[crypto_box_SECRETKEYBYTES];
handle_args(argc, argv, "Creates minimal Tox savedata", public_key, secret_key);
print_keys(public_key, secret_key);
// (uint32_t) 0x00000000, (uint32_t) STATE_COOKIE_GLOBAL 0x15ed1b1f,
// (uint32_t) crypto_box_PUBLICKEYBYTES+crypto_box_SECRETKEYBYTES+sizeof(uint32_t) 0x00000044,
// (uint16_t) STATE_TYPE_NOSPAMKEYS 0x0001, (uint16_t) STATE_COOKIE_TYPE 0x01ce, (uint32_t) nospam 0x00000000
const char tox_file[] = "\x00\x00\x00\x00\x1f\x1b\xed\x15\x44\x00\x00\x00\x01\x00\xce\x01\x00\x00\x00\x00";
fwrite(tox_file, sizeof(tox_file) - 1, 1, stderr);
fwrite(public_key, sizeof(public_key), 1, stderr);
fwrite(secret_key, sizeof(secret_key), 1, stderr);
unsigned char checksum[2] = {0};
for (size_t i = 0; i < crypto_box_PUBLICKEYBYTES; i ++) {
checksum[i % 2] ^= public_key[i];
}
char checksum_str[sizeof(checksum) * 2 + 1];
bin2hex_toupper(checksum_str, sizeof(checksum_str), checksum, sizeof(checksum));
char public_key_str[crypto_box_PUBLICKEYBYTES * 2 + 1];
bin2hex_toupper(public_key_str, sizeof(public_key_str), public_key, crypto_box_PUBLICKEYBYTES);
fprintf(stdout, "Tox Id: %s00000000%s\n", public_key_str, checksum_str);
return 0;
}