static HASH_HashType AlgorithmToHashType(SECAlgorithmID *digestAlgorithms) { SECOidTag tag = SECOID_GetAlgorithmTag(digestAlgorithms); HASH_HashType hash = HASH_GetHashTypeByOidTag(tag); return hash; }
const SECHashObject * HASH_GetHashObjectByOidTag(SECOidTag hashOid) { HASH_HashType ht = HASH_GetHashTypeByOidTag(hashOid); return (ht == HASH_AlgNULL) ? NULL : &SECHashObjects[ht]; }
std::string hash(const std::uint8_t *begin, const std::uint8_t *end) { SECOidTag hashOIDTag = SEC_OID_SHA256; std::array<std::uint8_t, 64> digest; unsigned int len; HASH_HashType hashType = HASH_GetHashTypeByOidTag(hashOIDTag); auto ctx = to_unique(HASH_Create(hashType)); HASH_Begin(ctx.get()); HASH_Update(ctx.get(), reinterpret_cast<const unsigned char *>(begin), end - begin); HASH_End(ctx.get(), reinterpret_cast<unsigned char *>(digest.data()), &len, digest.size()); return std::string(reinterpret_cast<const char *>(digest.data()), len); }