1 // TODO key loading, generating, saving
5 #include <openssl/bn.h>
6 #include <openssl/aes.h>
7 #include <openssl/rsa.h>
8 #include <openssl/dh.h>
9 #include <openssl/pem.h>
20 static void crypto_rsaaes_clear(crypto_t *crypto)
22 crypto_data_t *cd = crypto->data;
30 RSA_Free(cd->my_private);
32 RSA_Free(cd->other_public);
34 memset(crypto, 0, sizeof(*crypto));
38 void crypto_rsaaes_initwithclientkey(crypto_t *crypto, const char *data)
40 crypto_rsaaes_clear(crypto);
41 // initialize my own key
42 crypto->my_private = ...; // TODO
44 crypto->other_public = RSA_new();
45 BN_hex2bn(&crypto->other_public->n, data);
46 BN_hex2bn(&crypto->other_public->e, "10001"); // 65537 (RSA standard pubkey)
48 crypto->dh = DH_generate_parameters(512, 2, NULL, NULL); // TODO cache this
49 DH_generate_key(crypto->dh);
52 size_t crypto_rsaaes_buildserverkey(crypto_t *crypto, void *data, size_t len)
55 // generate reply with my_private's pubkey, DH parameters, and the my DH public key encrypted to other_public
60 void crypto_rsaaes_handleserverkey(crypto_t *crypto, const void *data, size_t len)
63 // read and decrypt DH data
66 size_t crypto_rsaaes_buildclientkey(crypto_t *crypto, void *data, size_t len)
68 // generate DH public and private data
69 // encrypt DH public data and generate reply with it
75 void crypto_rsaaes_handleclientkey(crypto_t *crypto, const void *data, size_t len)
77 // read and decrypt DH data
82 const void *crypto_encryptpacket(crypto_t *crypto, const void *data_src, size_t len_src, void *data_dst, size_t *len_dst, size_t len)
84 // if crypto active, encrypt with AES
90 const void *crypto_decryptpacket(crypto_t *crypto, const void *data_src, size_t len_src, void *data_dst, size_t *len_dst, size_t len)
92 // if crypto active, decrypt with AES
98 const char *crypto_rsaaes_pubkey = "";
100 // TODO key loading, generating, saving