encrypt.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. #include "lib/aes-common.h"
  2. #include "lib/md5.h"
  3. #include "lib/pbkdf2-sha1.h"
  4. #include "lib/pbkdf2-sha256.h"
  5. #include <string.h>
  6. #include <stdint.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include "encrypt.h"
  10. #include "common.h"
  11. #include "log.h"
  12. // static uint64_t seq=1;
  13. static int8_t zero_iv[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // this prog use zero iv,you should make sure first block of data contains a random/nonce data
  14. /****
  15. * security of zero_iv + nonce first data block
  16. * https://crypto.stackexchange.com/questions/5421/using-cbc-with-a-fixed-iv-and-a-random-first-plaintext-block
  17. ****/
  18. char normal_key[16 + 100]; // generated from key_string by md5. reserved for compatiblity
  19. const int hmac_key_len = 64; // generate 512bit long keys, use first n chars when needed
  20. const int cipher_key_len = 64;
  21. unsigned char hmac_key_encrypt[hmac_key_len + 100]; // key for hmac
  22. unsigned char hmac_key_decrypt[hmac_key_len + 100]; // key for hmac
  23. unsigned char cipher_key_encrypt[cipher_key_len + 100]; // key for aes etc.
  24. unsigned char cipher_key_decrypt[cipher_key_len + 100]; // key for aes etc.
  25. char gro_xor[256 + 100]; // dirty fix for gro
  26. unordered_map<int, const char *> auth_mode_tostring = {
  27. {auth_none, "none"},
  28. {auth_md5, "md5"},
  29. {auth_crc32, "crc32"},
  30. {auth_simple, "simple"},
  31. {auth_hmac_sha1, "hmac_sha1"},
  32. };
  33. unordered_map<int, const char *> cipher_mode_tostring = {
  34. {cipher_none, "none"},
  35. {cipher_aes128cfb, "aes128cfb"},
  36. {cipher_aes128cbc, "aes128cbc"},
  37. {cipher_xor, "xor"},
  38. };
  39. // TODO aes-gcm
  40. auth_mode_t auth_mode = auth_md5;
  41. cipher_mode_t cipher_mode = cipher_aes128cbc;
  42. int is_hmac_used = 0;
  43. int aes128cfb_old = 0;
  44. // TODO key negotiation and forward secrecy
  45. int my_init_keys(const char *user_passwd, int is_client) {
  46. char tmp[1000] = "";
  47. int len = strlen(user_passwd);
  48. strcat(tmp, user_passwd);
  49. strcat(tmp, "key1");
  50. md5((uint8_t *)tmp, strlen(tmp), (uint8_t *)normal_key);
  51. if (auth_mode == auth_hmac_sha1)
  52. is_hmac_used = 1;
  53. if (is_hmac_used || g_fix_gro || 1) {
  54. unsigned char salt[400] = "";
  55. char salt_text[400] = "udp2raw_salt1";
  56. md5((uint8_t *)(salt_text), strlen(salt_text), salt); // TODO different salt per session
  57. unsigned char pbkdf2_output1[400] = "";
  58. PKCS5_PBKDF2_HMAC_SHA256((uint8_t *)user_passwd, len, salt, 16, 10000, 32, pbkdf2_output1); // TODO argon2 ?
  59. // unsigned char pbkdf2_output2[400]="";
  60. // PKCS5_PBKDF2_HMAC_SHA256(pbkdf2_output1,32,0,0,1, hmac_key_len*2+cipher_key_len*2,pbkdf2_output2); //stretch it
  61. const char *info_hmac_encrypt = "hmac_key server-->client";
  62. const char *info_hmac_decrypt = "hmac_key client-->server";
  63. const char *info_cipher_encrypt = "cipher_key server-->client";
  64. const char *info_cipher_decrypt = "cipher_key client-->server";
  65. if (is_client) {
  66. const char *tmp;
  67. tmp = info_hmac_encrypt;
  68. info_hmac_encrypt = info_hmac_decrypt;
  69. info_hmac_decrypt = tmp;
  70. tmp = info_cipher_encrypt;
  71. info_cipher_encrypt = info_cipher_decrypt;
  72. info_cipher_decrypt = tmp;
  73. } else {
  74. // nop
  75. }
  76. assert(hkdf_sha256_expand(pbkdf2_output1, 32, (unsigned char *)info_cipher_encrypt, strlen(info_cipher_encrypt), cipher_key_encrypt, cipher_key_len) == 0);
  77. assert(hkdf_sha256_expand(pbkdf2_output1, 32, (unsigned char *)info_cipher_decrypt, strlen(info_cipher_decrypt), cipher_key_decrypt, cipher_key_len) == 0);
  78. assert(hkdf_sha256_expand(pbkdf2_output1, 32, (unsigned char *)info_hmac_encrypt, strlen(info_hmac_encrypt), hmac_key_encrypt, hmac_key_len) == 0);
  79. assert(hkdf_sha256_expand(pbkdf2_output1, 32, (unsigned char *)info_hmac_decrypt, strlen(info_hmac_decrypt), hmac_key_decrypt, hmac_key_len) == 0);
  80. const char *gro_info = "gro";
  81. assert(hkdf_sha256_expand(pbkdf2_output1, 32, (unsigned char *)gro_info, strlen(gro_info), (unsigned char *)gro_xor, 256) == 0);
  82. }
  83. print_binary_chars(normal_key, 16);
  84. print_binary_chars((char *)hmac_key_encrypt, hmac_key_len);
  85. print_binary_chars((char *)hmac_key_decrypt, hmac_key_len);
  86. print_binary_chars((char *)cipher_key_encrypt, cipher_key_len);
  87. print_binary_chars((char *)cipher_key_decrypt, cipher_key_len);
  88. return 0;
  89. }
  90. /*
  91. * this function comes from http://www.hackersdelight.org/hdcodetxt/crc.c.txt
  92. */
  93. unsigned int crc32h(unsigned char *message, int len) {
  94. int i, crc;
  95. unsigned int byte, c;
  96. const unsigned int g0 = 0xEDB88320, g1 = g0 >> 1,
  97. g2 = g0 >> 2, g3 = g0 >> 3, g4 = g0 >> 4, g5 = g0 >> 5,
  98. g6 = (g0 >> 6) ^ g0, g7 = ((g0 >> 6) ^ g0) >> 1;
  99. i = 0;
  100. crc = 0xFFFFFFFF;
  101. while (i != len) { // Get next byte.
  102. byte = message[i];
  103. crc = crc ^ byte;
  104. c = ((crc << 31 >> 31) & g7) ^ ((crc << 30 >> 31) & g6) ^
  105. ((crc << 29 >> 31) & g5) ^ ((crc << 28 >> 31) & g4) ^
  106. ((crc << 27 >> 31) & g3) ^ ((crc << 26 >> 31) & g2) ^
  107. ((crc << 25 >> 31) & g1) ^ ((crc << 24 >> 31) & g0);
  108. crc = ((unsigned)crc >> 8) ^ c;
  109. i = i + 1;
  110. }
  111. return ~crc;
  112. }
  113. /*
  114. void sum(const unsigned char *data,int len,unsigned char* res) {
  115. memset(res,0,sizeof(int));
  116. for(int i=0,j=0;i<len;i++,j++)
  117. {
  118. if(j==4) j=0;
  119. res[j]+=data[i];
  120. }
  121. return ;
  122. }*/
  123. void simple_hash(unsigned char *str, int len, unsigned char res[8]) // djb2+ sdbm
  124. {
  125. u32_t hash = 5381;
  126. u32_t hash2 = 0;
  127. int c;
  128. int i = 0;
  129. while (c = *str++, i++ != len) {
  130. // hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
  131. hash = ((hash << 5) + hash) ^ c; /* (hash * 33) ^ c */
  132. hash2 = c + (hash2 << 6) + (hash2 << 16) - hash2;
  133. }
  134. hash = htonl(hash);
  135. hash2 = htonl(hash2);
  136. memcpy(res, &hash, sizeof(hash));
  137. memcpy(res + sizeof(hash), &hash2, sizeof(hash2));
  138. }
  139. int auth_md5_cal(const char *data, char *output, int &len) {
  140. memcpy(output, data, len); // TODO inefficient code
  141. md5((unsigned char *)output, len, (unsigned char *)(output + len));
  142. len += 16;
  143. return 0;
  144. }
  145. int auth_hmac_sha1_cal(const char *data, char *output, int &len) {
  146. mylog(log_trace, "auth_hmac_sha1_cal() is called\n");
  147. memcpy(output, data, len); // TODO inefficient code
  148. sha1_hmac(hmac_key_encrypt, 20, (const unsigned char *)data, len, (unsigned char *)(output + len));
  149. // use key len of 20 instead of hmac_key_len, "extra length would not significantly increase the function strength" (rfc2104)
  150. len += 20;
  151. return 0;
  152. }
  153. int auth_hmac_sha1_verify(const char *data, int &len) {
  154. mylog(log_trace, "auth_hmac_sha1_verify() is called\n");
  155. if (len < 20) {
  156. mylog(log_trace, "auth_hmac_sha1_verify len<20\n");
  157. return -1;
  158. }
  159. char res[20];
  160. sha1_hmac(hmac_key_decrypt, 20, (const unsigned char *)data, len - 20, (unsigned char *)(res));
  161. if (memcmp(res, data + len - 20, 20) != 0) {
  162. mylog(log_trace, "auth_hmac_sha1 check failed\n");
  163. return -2;
  164. }
  165. len -= 20;
  166. return 0;
  167. }
  168. int auth_crc32_cal(const char *data, char *output, int &len) {
  169. memcpy(output, data, len); // TODO inefficient code
  170. unsigned int ret = crc32h((unsigned char *)output, len);
  171. unsigned int ret_n = htonl(ret);
  172. memcpy(output + len, &ret_n, sizeof(unsigned int));
  173. len += sizeof(unsigned int);
  174. return 0;
  175. }
  176. int auth_simple_cal(const char *data, char *output, int &len) {
  177. // char res[4];
  178. memcpy(output, data, len); // TODO inefficient code
  179. simple_hash((unsigned char *)output, len, (unsigned char *)(output + len));
  180. len += 8;
  181. return 0;
  182. }
  183. int auth_simple_verify(const char *data, int &len) {
  184. if (len < 8) return -1;
  185. unsigned char res[8];
  186. len -= 8;
  187. simple_hash((unsigned char *)data, len, res);
  188. if (memcmp(res, data + len, 8) != 0)
  189. return -1;
  190. return 0;
  191. }
  192. int auth_none_cal(const char *data, char *output, int &len) {
  193. memcpy(output, data, len);
  194. return 0;
  195. }
  196. int auth_md5_verify(const char *data, int &len) {
  197. if (len < 16) {
  198. mylog(log_trace, "auth_md5_verify len<16\n");
  199. return -1;
  200. }
  201. char md5_res[16];
  202. md5((unsigned char *)data, len - 16, (unsigned char *)md5_res);
  203. if (memcmp(md5_res, data + len - 16, 16) != 0) {
  204. mylog(log_trace, "auth_md5_verify md5 check failed\n");
  205. return -2;
  206. }
  207. len -= 16;
  208. return 0;
  209. }
  210. int auth_none_verify(const char *data, int &len) {
  211. return 0;
  212. }
  213. int cipher_xor_encrypt(const char *data, char *output, int &len, char *key) {
  214. int i, j;
  215. for (i = 0, j = 0; i < len; i++, j++) {
  216. if (j == 16) j = 0;
  217. output[i] = data[i] ^ key[j];
  218. }
  219. return 0;
  220. }
  221. int cipher_xor_decrypt(const char *data, char *output, int &len, char *key) {
  222. int i, j;
  223. // char tmp[buf_len];
  224. // len=len/16*16+1;
  225. // AES128_CBC_decrypt_buffer((uint8_t *)tmp, (uint8_t *)input, len, (uint8_t *)key, (uint8_t *)iv);
  226. // for(i=0;i<len;i++)
  227. // input[i]=tmp[i];
  228. for (i = 0, j = 0; i < len; i++, j++) {
  229. if (j == 16) j = 0;
  230. output[i] = data[i] ^ key[j];
  231. }
  232. return 0;
  233. }
  234. int padding(char *data, int &data_len, int padding_num) {
  235. int old_len = data_len;
  236. data_len += 1;
  237. if (data_len % padding_num != 0) {
  238. data_len = (data_len / padding_num) * padding_num + padding_num;
  239. }
  240. unsigned char *p = (unsigned char *)&data[data_len - 1];
  241. *p = (data_len - old_len);
  242. return 0;
  243. }
  244. int de_padding(const char *data, int &data_len, int padding_num) {
  245. if (data_len == 0) return -1;
  246. if ((uint8_t)data[data_len - 1] > padding_num) return -1;
  247. data_len -= (uint8_t)data[data_len - 1];
  248. if (data_len < 0) {
  249. return -1;
  250. }
  251. return 0;
  252. }
  253. void aes_ecb_encrypt(const char *data, char *output) {
  254. static int first_time = 1;
  255. char *key = (char *)cipher_key_encrypt;
  256. if (aes_key_optimize) {
  257. if (first_time == 0)
  258. key = 0;
  259. else
  260. first_time = 0;
  261. }
  262. AES_ECB_encrypt_buffer((uint8_t *)data, (uint8_t *)key, (uint8_t *)output);
  263. }
  264. void aes_ecb_encrypt1(char *data) {
  265. char buf[16];
  266. memcpy(buf, data, 16);
  267. aes_ecb_encrypt(buf, data);
  268. }
  269. void aes_ecb_decrypt(const char *data, char *output) {
  270. static int first_time = 1;
  271. char *key = (char *)cipher_key_decrypt;
  272. if (aes_key_optimize) {
  273. if (first_time == 0)
  274. key = 0;
  275. else
  276. first_time = 0;
  277. }
  278. AES_ECB_decrypt_buffer((uint8_t *)data, (uint8_t *)key, (uint8_t *)output);
  279. }
  280. void aes_ecb_decrypt1(char *data) {
  281. char buf[16];
  282. memcpy(buf, data, 16);
  283. aes_ecb_decrypt(buf, data);
  284. }
  285. int cipher_aes128cbc_encrypt(const char *data, char *output, int &len, char *key) {
  286. static int first_time = 1;
  287. char buf[buf_len];
  288. memcpy(buf, data, len); // TODO inefficient code
  289. if (padding(buf, len, 16) < 0) return -1;
  290. if (aes_key_optimize) {
  291. if (first_time == 0)
  292. key = 0;
  293. else
  294. first_time = 0;
  295. }
  296. AES_CBC_encrypt_buffer((unsigned char *)output, (unsigned char *)buf, len, (unsigned char *)key, (unsigned char *)zero_iv);
  297. return 0;
  298. }
  299. int cipher_aes128cfb_encrypt(const char *data, char *output, int &len, char *key) {
  300. static int first_time = 1;
  301. assert(len >= 16);
  302. char buf[buf_len];
  303. memcpy(buf, data, len); // TODO inefficient code
  304. if (aes_key_optimize) {
  305. if (first_time == 0)
  306. key = 0;
  307. else
  308. first_time = 0;
  309. }
  310. if (!aes128cfb_old) {
  311. aes_ecb_encrypt(data, buf); // encrypt the first block
  312. }
  313. AES_CFB_encrypt_buffer((unsigned char *)output, (unsigned char *)buf, len, (unsigned char *)key, (unsigned char *)zero_iv);
  314. return 0;
  315. }
  316. int auth_crc32_verify(const char *data, int &len) {
  317. if (len < int(sizeof(unsigned int))) {
  318. mylog(log_debug, "auth_crc32_verify len<%d\n", int(sizeof(unsigned int)));
  319. return -1;
  320. }
  321. unsigned int ret = crc32h((unsigned char *)data, len - sizeof(unsigned int));
  322. unsigned int ret_n = htonl(ret);
  323. if (memcmp(data + len - sizeof(unsigned int), &ret_n, sizeof(unsigned int)) != 0) {
  324. mylog(log_debug, "auth_crc32_verify memcmp fail\n");
  325. return -1;
  326. }
  327. len -= sizeof(unsigned int);
  328. return 0;
  329. }
  330. int cipher_none_encrypt(const char *data, char *output, int &len, char *key) {
  331. memcpy(output, data, len);
  332. return 0;
  333. }
  334. int cipher_aes128cbc_decrypt(const char *data, char *output, int &len, char *key) {
  335. static int first_time = 1;
  336. if (len % 16 != 0) {
  337. mylog(log_debug, "len%%16!=0\n");
  338. return -1;
  339. }
  340. if (aes_key_optimize) {
  341. if (first_time == 0)
  342. key = 0;
  343. else
  344. first_time = 0;
  345. }
  346. AES_CBC_decrypt_buffer((unsigned char *)output, (unsigned char *)data, len, (unsigned char *)key, (unsigned char *)zero_iv);
  347. if (de_padding(output, len, 16) < 0) return -1;
  348. return 0;
  349. }
  350. int cipher_aes128cfb_decrypt(const char *data, char *output, int &len, char *key) {
  351. static int first_time = 1;
  352. if (len < 16) return -1;
  353. if (aes_key_optimize) {
  354. if (first_time == 0)
  355. key = 0;
  356. else
  357. first_time = 0;
  358. }
  359. AES_CFB_decrypt_buffer((unsigned char *)output, (unsigned char *)data, len, (unsigned char *)key, (unsigned char *)zero_iv);
  360. if (!aes128cfb_old)
  361. aes_ecb_decrypt1(output); // decrypt the first block
  362. // if(de_padding(output,len,16)<0) return -1;
  363. return 0;
  364. }
  365. int cipher_none_decrypt(const char *data, char *output, int &len, char *key) {
  366. memcpy(output, data, len);
  367. return 0;
  368. }
  369. int auth_cal(const char *data, char *output, int &len) {
  370. mylog(log_trace, "auth:%d\n", auth_mode);
  371. switch (auth_mode) {
  372. case auth_crc32:
  373. return auth_crc32_cal(data, output, len);
  374. case auth_md5:
  375. return auth_md5_cal(data, output, len);
  376. case auth_simple:
  377. return auth_simple_cal(data, output, len);
  378. case auth_none:
  379. return auth_none_cal(data, output, len);
  380. case auth_hmac_sha1:
  381. return auth_hmac_sha1_cal(data, output, len);
  382. // default: return auth_md5_cal(data,output,len);//default;
  383. default:
  384. assert(0 == 1);
  385. }
  386. return -1;
  387. }
  388. int auth_verify(const char *data, int &len) {
  389. mylog(log_trace, "auth:%d\n", auth_mode);
  390. switch (auth_mode) {
  391. case auth_crc32:
  392. return auth_crc32_verify(data, len);
  393. case auth_md5:
  394. return auth_md5_verify(data, len);
  395. case auth_simple:
  396. return auth_simple_verify(data, len);
  397. case auth_none:
  398. return auth_none_verify(data, len);
  399. case auth_hmac_sha1:
  400. return auth_hmac_sha1_verify(data, len);
  401. // default: return auth_md5_verify(data,len);//default
  402. default:
  403. assert(0 == 1);
  404. }
  405. return -1;
  406. }
  407. int cipher_encrypt(const char *data, char *output, int &len, char *key) {
  408. mylog(log_trace, "cipher:%d\n", cipher_mode);
  409. switch (cipher_mode) {
  410. case cipher_aes128cbc:
  411. return cipher_aes128cbc_encrypt(data, output, len, key);
  412. case cipher_aes128cfb:
  413. return cipher_aes128cfb_encrypt(data, output, len, key);
  414. case cipher_xor:
  415. return cipher_xor_encrypt(data, output, len, key);
  416. case cipher_none:
  417. return cipher_none_encrypt(data, output, len, key);
  418. // default:return cipher_aes128cbc_encrypt(data,output,len, key);
  419. default:
  420. assert(0 == 1);
  421. }
  422. return -1;
  423. }
  424. int cipher_decrypt(const char *data, char *output, int &len, char *key) {
  425. mylog(log_trace, "cipher:%d\n", cipher_mode);
  426. switch (cipher_mode) {
  427. case cipher_aes128cbc:
  428. return cipher_aes128cbc_decrypt(data, output, len, key);
  429. case cipher_aes128cfb:
  430. return cipher_aes128cfb_decrypt(data, output, len, key);
  431. case cipher_xor:
  432. return cipher_xor_decrypt(data, output, len, key);
  433. case cipher_none:
  434. return cipher_none_decrypt(data, output, len, key);
  435. // default: return cipher_aes128cbc_decrypt(data,output,len,key);
  436. default:
  437. assert(0 == 1);
  438. }
  439. return -1;
  440. }
  441. int encrypt_AE(const char *data, char *output, int &len /*,char * key*/) {
  442. mylog(log_trace, "encrypt_AE is called\n");
  443. char buf[buf_len];
  444. char buf2[buf_len];
  445. memcpy(buf, data, len);
  446. if (cipher_encrypt(buf, buf2, len, (char *)cipher_key_encrypt) != 0) {
  447. mylog(log_debug, "cipher_encrypt failed ");
  448. return -1;
  449. }
  450. if (auth_cal(buf2, output, len) != 0) {
  451. mylog(log_debug, "auth_cal failed ");
  452. return -1;
  453. }
  454. // printf("%d %x %x\n",len,(int)(output[0]),(int)(output[1]));
  455. // print_binary_chars(output,len);
  456. // use encrypt-then-MAC scheme
  457. return 0;
  458. }
  459. int decrypt_AE(const char *data, char *output, int &len /*,char * key*/) {
  460. mylog(log_trace, "decrypt_AE is called\n");
  461. // printf("%d %x %x\n",len,(int)(data[0]),(int)(data[1]));
  462. // print_binary_chars(data,len);
  463. if (auth_verify(data, len) != 0) {
  464. mylog(log_debug, "auth_verify failed\n");
  465. return -1;
  466. }
  467. if (cipher_decrypt(data, output, len, (char *)cipher_key_decrypt) != 0) {
  468. mylog(log_debug, "cipher_decrypt failed \n");
  469. return -1;
  470. }
  471. return 0;
  472. }
  473. int my_encrypt(const char *data, char *output, int &len /*,char * key*/) {
  474. if (len < 0) {
  475. mylog(log_trace, "len<0");
  476. return -1;
  477. }
  478. if (len > max_data_len) {
  479. mylog(log_warn, "len>max_data_len");
  480. return -1;
  481. }
  482. if (is_hmac_used)
  483. return encrypt_AE(data, output, len);
  484. char buf[buf_len];
  485. char buf2[buf_len];
  486. memcpy(buf, data, len);
  487. if (auth_cal(buf, buf2, len) != 0) {
  488. mylog(log_debug, "auth_cal failed ");
  489. return -1;
  490. }
  491. if (cipher_encrypt(buf2, output, len, normal_key) != 0) {
  492. mylog(log_debug, "cipher_encrypt failed ");
  493. return -1;
  494. }
  495. return 0;
  496. }
  497. int my_decrypt(const char *data, char *output, int &len /*,char * key*/) {
  498. if (len < 0) return -1;
  499. if (len > max_data_len) {
  500. mylog(log_warn, "len>max_data_len");
  501. return -1;
  502. }
  503. if (is_hmac_used)
  504. return decrypt_AE(data, output, len);
  505. if (cipher_decrypt(data, output, len, normal_key) != 0) {
  506. mylog(log_debug, "cipher_decrypt failed \n");
  507. return -1;
  508. }
  509. if (auth_verify(output, len) != 0) {
  510. mylog(log_debug, "auth_verify failed\n");
  511. return -1;
  512. }
  513. return 0;
  514. }
  515. int encrypt_AEAD(uint8_t *data, uint8_t *output, int &len, uint8_t *key, uint8_t *header, int hlen) {
  516. // TODO
  517. return -1;
  518. }
  519. int decrypt_AEAD(uint8_t *data, uint8_t *output, int &len, uint8_t *key, uint8_t *header, int hlen) {
  520. // TODO
  521. return -1;
  522. }