menu

Algorithm

SHA-256 Is a set of cryptographic hash functions designed by the National Security Agency (NSA). SHA stands for Secure Hash Algorithm. Cryptographic hash functions are mathematical operations run on digital data; by comparing the computed “hash” (the output from execution of the algorithm) to a known and expected hash value, a person can determine the data’s integrity. For example, computing the hash of a downloaded file and comparing the result to a previously published hash result can show whether the download has been modified or tampered with. A key aspect of cryptographic hash functions is their collision resistance: nobody should be able to find two different input values that result in the same hash output. SHA-256 is used as part of the process of authenticating Debian GNU/Linux software packages and in the DKIM message signing standard._variables.scss.


template
inline uint256 Hash(const T1 pbegin, const T1 pend)
{
    static unsigned char pblank[1];
    uint256 hash1;
    SHA256((pbegin == pend ? pblank : (unsigned char*)&pbegin;[0]), (pend - pbegin) * sizeof(pbegin[0]), (unsigned char*)&hash1;);
    uint256 hash2;
    SHA256((unsigned char*)&hash1;, sizeof(hash1), (unsigned char*)&hash2;);
    return hash2;
}
class CHashWriter
{
private:
    SHA256_CTX ctx;
public:
    int nType;
    int nVersion;
    void Init() {
        SHA256_Init(&ctx;);
    }
    CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {
        Init();
    }
    CHashWriter& write(const char *pch, size_t size) {
        SHA256_Update(&ctx;, pch, size);
        return (*this);
    }
    // invalidates the object
    uint256 GetHash() {
        uint256 hash1;
        SHA256_Final((unsigned char*)&hash1;, &ctx;);
        uint256 hash2;
        SHA256((unsigned char*)&hash1;, sizeof(hash1), (unsigned char*)&hash2;);
        return hash2;
    }
    template
    CHashWriter& operator<<(const T& obj) {
        // Serialize to this stream
        ::Serialize(*this, obj, nType, nVersion);
        return (*this);
    }
};
template
inline uint256 Hash(const T1 p1begin, const T1 p1end,
                    const T2 p2begin, const T2 p2end)
{
    static unsigned char pblank[1];
    uint256 hash1;
    SHA256_CTX ctx;
    SHA256_Init(&ctx;);
    SHA256_Update(&ctx;, (p1begin == p1end ? pblank : (unsigned char*)&p1begin;[0]), (p1end - p1begin) * sizeof(p1begin[0]));
    SHA256_Update(&ctx;, (p2begin == p2end ? pblank : (unsigned char*)&p2begin;[0]), (p2end - p2begin) * sizeof(p2begin[0]));
    SHA256_Final((unsigned char*)&hash1;, &ctx;);
    uint256 hash2;
    SHA256((unsigned char*)&hash1;, sizeof(hash1), (unsigned char*)&hash2;);
    return hash2;
}
template
inline uint256 Hash(const T1 p1begin, const T1 p1end,
                    const T2 p2begin, const T2 p2end,
                    const T3 p3begin, const T3 p3end)
{
    static unsigned char pblank[1];
    uint256 hash1;
    SHA256_CTX ctx;
    SHA256_Init(&ctx;);
    SHA256_Update(&ctx;, (p1begin == p1end ? pblank : (unsigned char*)&p1begin;[0]), (p1end - p1begin) * sizeof(p1begin[0]));
    SHA256_Update(&ctx;, (p2begin == p2end ? pblank : (unsigned char*)&p2begin;[0]), (p2end - p2begin) * sizeof(p2begin[0]));
    SHA256_Update(&ctx;, (p3begin == p3end ? pblank : (unsigned char*)&p3begin;[0]), (p3end - p3begin) * sizeof(p3begin[0]));
    SHA256_Final((unsigned char*)&hash1;, &ctx;);
    uint256 hash2;
    SHA256((unsigned char*)&hash1;, sizeof(hash1), (unsigned char*)&hash2;);
    return hash2;
}
template
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
{
    CHashWriter ss(nType, nVersion);
    ss << obj;
    return ss.GetHash();
}
template
inline uint160 Hash160(const T1 pbegin, const T1 pend)
{
    static unsigned char pblank[1];
    uint256 hash1;
    SHA256((pbegin == pend ? pblank : (unsigned char*)&pbegin;[0]), (pend - pbegin) * sizeof(pbegin[0]), (unsigned char*)&hash1;);
    uint160 hash2;
    RIPEMD160((unsigned char*)&hash1;, sizeof(hash1), (unsigned char*)&hash2;);
    return hash2;
}
inline uint160 Hash160(const std::vector& vch)
{
    return Hash160(vch.begin(), vch.end());
}
unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector& vDataToHash);        

Cryptanalysis and validation

or a hash function for which L is the number of bits in the message digest, finding a message that corresponds to a given message digest can always be done using a brute force search in 2L evaluations. This is called a preimage attack and may or may not be practical depending on L and the particular computing environment. The second criterion, finding two different messages that produce the same message digest, known as a collision, requires on average only 2L/2 evaluations using a birthday attack.
Some of the applications that use cryptographic hashes, such as password storage, are only minimally affected by a collision attack. Constructing a password that works for a given account requires a preimage attack, as well as access to the hash of the original password (typically in the shadow file) which may or may not be trivial. Reversing password encryption (e.g., to obtain a password to try against a user’s account elsewhere) is not made possible by the attacks. (However, even a secure password hash cannot prevent brute-force attacks on weak passwords.)
In the case of document signing, an attacker could not simply fake a signature from an existing document—the attacker would have to produce a pair of documents, one innocuous and one damaging, and get the private key holder to sign the innocuous document. There are practical circumstances in which this is possible; until the end of 2008, it was possible to create forged SSL certificates using an MD5 collision which would be accepted by widely used web browsers

Miners

SHA-256 Can be mined with CPU, GPU, and ASIC mining.

CPU Mining Guide

        Coming Soon!!!
        
GPU Mining Guide

          Coming Soon!!!