| 374 | } |
| 375 | |
| 376 | bool decrypt_string_gcm(const string& base64_in, const BYTE *key, wstring& str) |
| 377 | { |
| 378 | bool rval = true; |
| 379 | |
| 380 | auto context = get_crypt_context(BLOCK_IV_LEN, AES_MODE_GCM); |
| 381 | |
| 382 | if (!context) |
| 383 | return false; |
| 384 | |
| 385 | try { |
| 386 | vector<BYTE> v; |
| 387 | |
| 388 | BYTE adata[8]; |
| 389 | memset(adata, 0, sizeof(adata)); |
| 390 | |
| 391 | if (!base64_decode(&base64_in[0], v, false, true)) |
| 392 | throw(-1); |
| 393 | |
| 394 | vector<char> plaintext(v.size() - BLOCK_IV_LEN - BLOCK_TAG_LEN + 1); |
| 395 | int ptlen = decrypt((const BYTE*)(&v[0] + BLOCK_IV_LEN), (int)v.size() - BLOCK_IV_LEN - BLOCK_TAG_LEN, adata, sizeof(adata), &v[0] + v.size() - BLOCK_TAG_LEN, key, &v[0], (BYTE*)&plaintext[0], context.get()); |
| 396 | |
| 397 | if (ptlen != v.size() - BLOCK_IV_LEN - BLOCK_TAG_LEN) |
| 398 | throw(-1); |
| 399 | |
| 400 | plaintext[ptlen] = '\0'; |
| 401 | |
| 402 | if (!utf8_to_unicode(&plaintext[0], str)) |
| 403 | throw(-1); |
| 404 | |
| 405 | } catch (...) { |
| 406 | rval = false; |
| 407 | } |
| 408 | |
| 409 | return rval; |
| 410 | } |
| 411 | |
| 412 | const char *hkdfInfoEMENames = "EME filename encryption"; |
| 413 | const char *hkdfInfoGCMContent = "AES-GCM file content encryption"; |
no test coverage detected