| 296 | } |
| 297 | |
| 298 | bool sha512(const BYTE *data, int datalen, BYTE *sum) |
| 299 | { |
| 300 | EVP_MD_CTX *mdctx = NULL; |
| 301 | bool ret = true; |
| 302 | |
| 303 | try { |
| 304 | |
| 305 | if (EVP_MD_size(EVP_sha512()) != 64) |
| 306 | handleErrors(); |
| 307 | |
| 308 | if ((mdctx = EVP_MD_CTX_create()) == NULL) |
| 309 | handleErrors(); |
| 310 | |
| 311 | if (1 != EVP_DigestInit_ex(mdctx, EVP_sha512(), NULL)) |
| 312 | handleErrors(); |
| 313 | |
| 314 | if (1 != EVP_DigestUpdate(mdctx, data, datalen)) |
| 315 | handleErrors(); |
| 316 | |
| 317 | unsigned int len; |
| 318 | if (1 != EVP_DigestFinal_ex(mdctx, sum, &len)) |
| 319 | handleErrors(); |
| 320 | |
| 321 | if (len != 64) |
| 322 | handleErrors(); |
| 323 | |
| 324 | } catch (...) { |
| 325 | ret = false; |
| 326 | } |
| 327 | |
| 328 | if (mdctx) |
| 329 | EVP_MD_CTX_destroy(mdctx); |
| 330 | |
| 331 | return ret; |
| 332 | |
| 333 | } |
| 334 | |
| 335 | bool encrypt_string_gcm(const wstring& str, const BYTE *key, string& base64_out) |
| 336 | { |