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

Function sha256

libcppcryptfs/crypt/crypt.cpp:256–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254
255
256bool sha256(const BYTE *data, int datalen, BYTE *sum)
257{
258 EVP_MD_CTX *mdctx = NULL;
259 bool ret = true;
260
261 try {
262
263 if (EVP_MD_size(EVP_sha256()) != 32)
264 handleErrors();
265
266 if ((mdctx = EVP_MD_CTX_create()) == NULL)
267 handleErrors();
268
269 if (1 != EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL))
270 handleErrors();
271
272 if (1 != EVP_DigestUpdate(mdctx, data, datalen))
273 handleErrors();
274
275 unsigned int len;
276 if (1 != EVP_DigestFinal_ex(mdctx, sum, &len))
277 handleErrors();
278
279 if (len != 32)
280 handleErrors();
281
282 } catch (...) {
283 ret = false;
284 }
285
286 if (mdctx)
287 EVP_MD_CTX_destroy(mdctx);
288
289 return ret;
290
291}
292
293bool sha256(const string& str, BYTE* sum)
294{

Callers 4

GetPathHashFunction · 0.85
init_serialMethod · 0.85
derive_path_ivFunction · 0.85
encrypt_filenameFunction · 0.85

Calls 1

handleErrorsFunction · 0.85

Tested by

no test coverage detected