Beispiel #1
0
NNT_BEGIN_HEADER_C

# include <openssl/sha.h>

NNT_END_HEADER_C

NNT_BEGIN_CXX

core::data sha1::digest(core::data const& da)
{
    core::data tmp = da.shadow();
    
    SHA_CTX ctx;
    SHA1_Init(&ctx);
    while (tmp.length())
    {
        SHA1_Update(&ctx, tmp.bytes(), tmp.limit(SHA_DIGEST_LENGTH));
        tmp.offset(tmp.limit(SHA_DIGEST_LENGTH));
    }
    
    core::data ret(SHA_DIGEST_LENGTH);
    SHA1_Final((byte*)ret.bytes(), &ctx);
    
    return ret;
}
Beispiel #2
0
core::data sha2::digest384(core::data const& da)
{
    core::data tmp = da.shadow();
    
    SHA512_CTX ctx;
    SHA384_Init(&ctx);
    
    while (tmp.length())
    {
        SHA384_Update(&ctx, tmp.bytes(), tmp.limit(SHA384_DIGEST_LENGTH));
        tmp.offset(tmp.limit(SHA384_DIGEST_LENGTH));
    }
    
    core::data ret(SHA384_DIGEST_LENGTH);
    SHA384_Final((byte*)ret.bytes(), &ctx);
    
    return ret;
}