Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sha2.cpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67f2dc199d308121e55a0e16a7dfa78b4feee876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "coding/sha2.hpp"
#include "coding/hex.hpp"

#include "base/macros.hpp"

#include "3party/tomcrypt/src/headers/tomcrypt.h"

namespace sha2
{
  string digest256(char const * data, size_t dataSize, bool returnAsHexString)
  {
    hash_state md;
    unsigned char out[256/8] = { 0 };
    if (CRYPT_OK == sha256_init(&md)
        && CRYPT_OK == sha256_process(&md, reinterpret_cast<unsigned char const *>(data), dataSize)
        && CRYPT_OK == sha256_done(&md, out))
    {
      if (returnAsHexString)
        return ToHex(string(reinterpret_cast<char const *>(out), ARRAY_SIZE(out)));
      else
        return string(reinterpret_cast<char const *>(out), ARRAY_SIZE(out));
    }
    return string();
  }
}