MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / decrypt_string_gcm

Function decrypt_string_gcm

libcppcryptfs/crypt/crypt.cpp:376–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376bool 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
412const char *hkdfInfoEMENames = "EME filename encryption";
413const char *hkdfInfoGCMContent = "AES-GCM file content encryption";

Callers 1

decrypt_keyMethod · 0.85

Calls 6

get_crypt_contextFunction · 0.85
base64_decodeFunction · 0.85
decryptFunction · 0.85
utf8_to_unicodeFunction · 0.85
sizeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected