void TestApp::test_hash(const SHA256 &sha256, const char *hash_text) { std::string hash = sha256.get_hash(true); if (hash != hash_text) fail(); if (strlen(hash_text) != 64) fail(); unsigned char out_hash[32]; sha256.get_hash(out_hash); for (int cnt=0; cnt<32; cnt++) { unsigned int value = out_hash[cnt]; char nibble_high = *(hash_text++); char nibble_low = *(hash_text++); nibble_high >= 'A' ? (nibble_high = nibble_high - 'A' + 10) : nibble_high = nibble_high - '0'; nibble_low >= 'A' ? (nibble_low = nibble_low - 'A' + 10) : nibble_low = nibble_low - '0'; if (value != ((nibble_high << 4) | (nibble_low) )) fail(); } }
QVector<QString> & PBSKeygen::getKeys() { SHA256 sha; QString macS = getMacAddress(); if (macS.length() != 12) { throw ERROR; } char mac[6]; bool status; for (int i = 0; i < 12; i += 2) mac[i / 2] = (macS.mid(i, 1).toInt(&status, 16) << 4) + macS.mid(i + 1, 1).toInt(&status, 16); if (!status) throw ERROR; sha.reset(); sha.addData(saltSHA256, (unsigned long)sizeof(saltSHA256)); sha.addData(mac, (unsigned long)sizeof(mac)); unsigned char hash[32]; sha.result((unsigned char *) hash); QString key = ""; for (int i = 0; i < 13; ++i) { key.append(lookup.at(hash[i] % lookup.length())); } results.append(key); return results; }
//--------------------------------------------------------------------- bool PeerContactProfile::usesContactProfileSecret(const char *contactProfileSecret) { AutoRecursiveLock lock(mLock); if (NULL == contactProfileSecret) return false; if (!mDocument) return false; try { ElementPtr contactProfileElement = getContactProfileElement(); if (!contactProfileElement) return false; ElementPtr proofElement = contactProfileElement->findFirstChildElementChecked("private")->findFirstChildElementChecked("proof"); String proofAsBase64 = proofElement->getText(true); SecureByteBlock proofHash; convertFromBase64(proofAsBase64, proofHash); SecureByteBlock calculatedProofHash(32); if (calculatedProofHash.size() != proofHash.size()) return false; SHA256 shaProof; shaProof.Update((const BYTE *)"proof:", strlen("proof:")); shaProof.Update((const BYTE *)contactProfileSecret, strlen(contactProfileSecret)); shaProof.Final(calculatedProofHash); if (0 != memcmp(calculatedProofHash, proofHash, proofHash.size())) return false; // this is the secret and it is verified mContactProfileSecret = contactProfileSecret; } catch (zsLib::XML::Exceptions::CheckFailed &) { return false; } return true; }
// Non-public secure PBKDF2 hash function with salting and 1,337 iterations std::string JSI_Lobby::EncryptPassword(const std::string& password, const std::string& username) { const int DIGESTSIZE = SHA_DIGEST_SIZE; const int ITERATIONS = 1337; static const unsigned char salt_base[DIGESTSIZE] = { 244, 243, 249, 244, 32, 33, 34, 35, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 32, 33, 244, 224, 127, 129, 130, 140, 153, 133, 123, 234, 123 }; // initialize the salt buffer unsigned char salt_buffer[DIGESTSIZE] = {0}; SHA256 hash; hash.update(salt_base, sizeof(salt_base)); hash.update(username.c_str(), username.length()); hash.finish(salt_buffer); // PBKDF2 to create the buffer unsigned char encrypted[DIGESTSIZE]; pbkdf2(encrypted, (unsigned char*)password.c_str(), password.length(), salt_buffer, DIGESTSIZE, ITERATIONS); static const char base16[] = "0123456789ABCDEF"; char hex[2 * DIGESTSIZE]; for (int i = 0; i < DIGESTSIZE; ++i) { hex[i*2] = base16[encrypted[i] >> 4]; // 4 high bits hex[i*2 + 1] = base16[encrypted[i] & 0x0F]; // 4 low bits } return std::string(hex, sizeof(hex)); }
/** * Clear from clipboard data, that we put there previously * @return \c true, if we cleared our data, or stored data don't belong to us */ bool PWSclipboard::ClearCBData() { wxMutexLocker clip(m_clipboardMutex); if (m_set && wxTheClipboard->Open()) { wxTextDataObject obj; if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT) && wxTheClipboard->GetData(obj)) { StringX buf(obj.GetText().data(), obj.GetText().size()); if (buf.length()) { // check if the data on the clipboard is the same we put there unsigned char digest[SHA256::HASHLEN]; SHA256 ctx; ctx.Update(reinterpret_cast<const unsigned char *>(buf.c_str()), buf.length()*sizeof(wchar_t)); ctx.Final(digest); if (memcmp(digest, m_digest, SHA256::HASHLEN) == 0) { // clear & reset wxTheClipboard->Clear(); memset(m_digest, 0, SHA256::HASHLEN); m_set = false; // Also trash data in buffer and clipboard somehow? pws_os::Trace0(L"Cleared our data from buffer.\n"); } else{ pws_os::Trace0(L"Buffer doesn't contain our data. Nothing to clear.\n"); } } } wxTheClipboard->Close(); } return !m_set; }
Blob ConvertFromBase58ShaSquare(RCString s) { BigInteger bi = 0; for (const char *p=s; *p; ++p) { if (const char *q = strchr(s_pszBase58, *p)) { bi = bi*58 + BigInteger(q-s_pszBase58); } else Throw(E_INVALIDARG); } vector<byte> v((bi.Length+7)/8); bi.ToBytes(&v[0], v.size()); if (v.size()>=2 && v.end()[-1]==0 && v.end()[-1]>=0x80) v.resize(v.size()-1); vector<byte> r; for (const char *p=s; *p==s_pszBase58[0]; ++p) r.push_back(0); r.resize(r.size()+v.size()); std::reverse_copy(v.begin(), v.end(), r.end()-v.size()); if (r.size() < 4) Throw(E_FAIL); SHA256 sha; HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(ConstBuf(&r[0], r.size()-4)))); if (memcmp(hash.data(), &r.end()[-4], 4)) Throw(HRESULT_FROM_WIN32(ERROR_CRC)); return Blob(&r[0], r.size()-4); }
int sha256_test() { SHA256 sha; byte hash[SHA256::DIGEST_SIZE]; testVector test_sha[] = { testVector("abc", "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22" "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00" "\x15\xAD"), testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60" "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB" "\x06\xC1") }; int times( sizeof(test_sha) / sizeof(testVector) ); for (int i = 0; i < times; ++i) { sha.Update(test_sha[i].input_, test_sha[i].inLen_); sha.Final(hash); if (memcmp(hash, test_sha[i].output_, SHA256::DIGEST_SIZE) != 0) return -1 - i; } return 0; }
void RandomPool::IncorporateEntropy(const byte *input, size_t length) { SHA256 hash; hash.Update(m_key, 32); hash.Update(input, length); hash.Final(m_key); m_keySet = false; }
bool provider::dhAgree(byte_block& agree, const byte_block& priv, const byte_block& pub) { SHA256 hasher; byte_block _agree(dh_agree_block_size); if (!dh.Agree(_agree, priv, pub)) return false; assert(_agree.SizeInBytes() == dh_agree_block_size); hasher.CalculateDigest(agree, _agree, dh_agree_block_size); return true; }
void PWSrand::AddEntropy(unsigned char *bytes, unsigned int numBytes) { ASSERT(bytes != nullptr); SHA256 s; s.Update(K, sizeof(K)); s.Update(bytes, numBytes); s.Final(K); }
void PWSrand::NextRandBlock() { SHA256 s; s.Update(K, sizeof(K)); s.Final(R); unsigned int *Kp = reinterpret_cast<unsigned int *>(K); unsigned int *Rp = reinterpret_cast<unsigned int *>(R); const int N = SHA256::HASHLEN / sizeof(uint32); Kp[0]++; for (int32 i = 0; i < N; i++) Kp[i] += Rp[i]; }
const std::string getHash(std::string fname){ std::ifstream f; f.open(fname.c_str()); SHA256 digest; const size_t BufferSize = 144 * 7 * 1024; char * buffer = new char[BufferSize]; if (f != NULL){ f.read(buffer, BufferSize);//read(char *s, streamsize n) std::size_t numByte = size_t(f.gcount());//gcount(): return the number of characters extracted by the last unformatted input operation digest.add(buffer, numByte); } f.close(); delete[] buffer; return digest.getHash(); }
void PWSfile::HashRandom256(unsigned char *p256) { /** * This is for random data that will be written to the file directly. * The idea is to avoid directly exposing our generated randomness * to the attacker, since this might expose state of the RNG. * Therefore, we'll hash the randomness. * * As the names imply, this works on 256 bit (32 byte) arrays. */ PWSrand::GetInstance()->GetRandomData(p256, 32); SHA256 salter; salter.Update(p256, 32); salter.Final(p256); }
PWSrand::PWSrand() : ibRandomData(SHA256::HASHLEN) { m_IsInternalPRNG = !pws_os::InitRandomDataFunction(); SHA256 s; unsigned slen = 0; unsigned char *p; pws_os::GetRandomSeed(nullptr, slen); p = new unsigned char[slen]; pws_os::GetRandomSeed(p, slen); s.Update(p, slen); delete[] p; s.Final(K); }
std::string sha256(const std::string& input) { SHA256::uint8 digest[SHA256::DIGEST_SIZE]; memset(digest,0,SHA256::DIGEST_SIZE); SHA256 ctx = SHA256(); ctx.init(); ctx.update( (SHA256::uint8*)input.c_str(), input.length()); ctx._final(digest); char buf[2*SHA256::DIGEST_SIZE+1]; buf[2*SHA256::DIGEST_SIZE] = 0; for (int i = 0; i < SHA256::DIGEST_SIZE; i++) sprintf(buf+i*2, "%02x", digest[i]); return std::string(buf); }
hashval CalcPbkdf2Hash(const UInt32 *pIhash, const ConstBuf& data, int idx) { SHA256 sha; size_t size = 16*4+data.Size+4; UInt32 *buf = (UInt32*)alloca(size); memset(buf, 0x36, 16*4); for (int i=0; i<8; ++i) buf[i] ^= pIhash[i]; memcpy(buf+16, data.P, data.Size); buf[16+data.Size/4] = htobe32(idx); hashval hv = sha.ComputeHash(ConstBuf(buf, size)); memset(buf, 0x5C, 16*4); for (int i=0; i<8; ++i) buf[i] ^= pIhash[i]; memcpy(buf+16, hv.constData(), hv.size()); return sha.ComputeHash(ConstBuf(buf, 64+hv.size())); }
String ConvertToBase58ShaSquare(const ConstBuf& cbuf) { SHA256 sha; HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(cbuf))); Blob v = cbuf + Blob(hash.data(), 4); vector<char> r; vector<byte> tmp(v.Size+1, 0); std::reverse_copy(v.begin(), v.end(), tmp.begin()); for (BigInteger n(&tmp[0], tmp.size()); Sign(n);) { pair<BigInteger, BigInteger> pp = div(n, 58); n = pp.first; r.insert(r.begin(), s_pszBase58[explicit_cast<int>(pp.second)]); } for (int i=0; i<v.Size && !v.constData()[i]; ++i) r.insert(r.begin(), s_pszBase58[0]); return String(&r[0], r.size()); }
std::string GetSha256ForFile(std::filesystem::path Filename) { SHA256 SHA; std::ifstream InStream(Filename.string()); unsigned char tmpbuf[256]; if (!InStream.is_open()) return ""; while (!InStream.eof()) { InStream.read((char*)tmpbuf, 256); size_t cnt = InStream.gcount(); SHA.add(tmpbuf, cnt); } return std::string(SHA.getHash()); }
/** * Put text data to clipboard * @param[in] data data to store in clipboard * @param isSensitive if data sensitive, we remember its hash and will clear on ClearCBData() call * @return \c true, if we could open the clipboard and put the data */ bool PWSclipboard::SetData(const StringX &data) { wxMutexLocker clip(m_clipboardMutex); bool res = false; if (wxTheClipboard->Open()) { res = wxTheClipboard->SetData(new wxTextDataObject(data.c_str())); wxTheClipboard->Close(); } m_set = true; if (res) { // identify data in clipboard as ours, so as not to clear the wrong data later // of course, we don't want an extra copy of a password floating around // in memory, so we'll use the hash SHA256 ctx; const wchar_t *str = data.c_str(); ctx.Update(reinterpret_cast<const unsigned char *>(str), data.length()*sizeof(wchar_t)); ctx.Final(m_digest); } return res; }
CArray8UInt32 CalcSCryptHash(const ConstBuf& password) { ASSERT(password.Size == 80); SHA256 sha; hashval ihash = sha.ComputeHash(password); const UInt32 *pIhash = (UInt32*)ihash.constData(); UInt32 x[32]; for (int i=0; i<4; ++i) { hashval hv = CalcPbkdf2Hash(pIhash, password, i+1); memcpy(x+8*i, hv.constData(), 32); } AlignedMem am((1025*32)*sizeof(UInt32), 128); ScryptCore(x, (UInt32*)am.get()); hashval hv = CalcPbkdf2Hash(pIhash, ConstBuf(x, sizeof x), 1); const UInt32 *p = (UInt32*)hv.constData(); CArray8UInt32 r; for (int i=0; i<8; ++i) r[i] = p[i]; return r; }
PWSFileSig::PWSFileSig(const stringT &fname) { const long THRESHOLD = 2048; // if file's longer than this, hash only head & tail m_length = 0; m_iErrorCode = PWSfile::SUCCESS; memset(m_digest, 0, sizeof(m_digest)); FILE *fp = pws_os::FOpen(fname, _T("rb")); if (fp != NULL) { SHA256 hash; unsigned char buf[THRESHOLD]; m_length = pws_os::fileLength(fp); // Minimum size for an empty V3 DB is 232 bytes - pre + post, no hdr or records! // Probably smaller for V1 & V2 DBs if (m_length > 232) { if (m_length <= THRESHOLD) { if (fread(buf, m_length, 1, fp) == 1) { hash.Update(buf, m_length); hash.Final(m_digest); } } else { // m_length > THRESHOLD if (fread(buf, THRESHOLD / 2, 1, fp) == 1 && fseek(fp, -THRESHOLD / 2, SEEK_END) == 0 && fread(buf + THRESHOLD / 2, THRESHOLD / 2, 1, fp) == 1) { hash.Update(buf, THRESHOLD); hash.Final(m_digest); } } } else { // File too small m_iErrorCode = PWSfile::TRUNCATED_FILE; } fclose(fp); } else { m_iErrorCode = PWSfile::CANT_OPEN_FILE; } }
PWSFileSig::PWSFileSig(const stringT &fname) { const long THRESHOLD = 2048; // if file's longer than this, hash only head & tail m_length = 0; m_iErrorCode = PWSfile::SUCCESS; memset(m_digest, 0, sizeof(m_digest)); FILE *fp = pws_os::FOpen(fname, _T("rb")); if (fp != nullptr) { SHA256 hash; m_length = pws_os::fileLength(fp); // Not the right place to be worried about min size, as this is format // version specific (and we're in PWSFile). // An empty file, though, should be failed. if (m_length > 0) { unsigned char buf[THRESHOLD]; if (m_length <= THRESHOLD) { if (fread(buf, size_t(m_length), 1, fp) == 1) { hash.Update(buf, size_t(m_length)); hash.Final(m_digest); } } else { // m_length > THRESHOLD if (fread(buf, THRESHOLD / 2, 1, fp) == 1 && fseek(fp, -THRESHOLD / 2, SEEK_END) == 0 && fread(buf + THRESHOLD / 2, THRESHOLD / 2, 1, fp) == 1) { hash.Update(buf, THRESHOLD); hash.Final(m_digest); } } } else { // Empty file m_iErrorCode = PWSfile::TRUNCATED_FILE; } fclose(fp); } else { m_iErrorCode = PWSfile::CANT_OPEN_FILE; } }
std::string GetSha256ForFile(std::string Filename) { SHA256 SHA; #ifndef WIN32 std::ifstream InStream(Filename.c_str()); #else std::ifstream InStream(Utility::Widen(Filename).c_str()); #endif unsigned char tmpbuf[256]; if (!InStream.is_open()) return ""; while (!InStream.eof()) { InStream.read((char*)tmpbuf, 256); size_t cnt = InStream.gcount(); SHA.add(tmpbuf, cnt); } return std::string(SHA.getHash()); }
void TransactionFrame::storeTransaction(LedgerManager& ledgerManager, LedgerDelta const& delta, int txindex, SHA256& resultHasher) const { auto txBytes(xdr::xdr_to_opaque(mEnvelope)); auto txResultBytes(xdr::xdr_to_opaque(getResultPair())); resultHasher.add(txResultBytes); std::string txBody = base64::encode( reinterpret_cast<const unsigned char*>(txBytes.data()), txBytes.size()); std::string txResult = base64::encode( reinterpret_cast<const unsigned char*>(txResultBytes.data()), txResultBytes.size()); xdr::opaque_vec<> txMeta(delta.getTransactionMeta()); std::string meta = base64::encode( reinterpret_cast<const unsigned char*>(txMeta.data()), txMeta.size()); string txIDString(binToHex(getContentsHash())); auto timer = ledgerManager.getDatabase().getInsertTimer("txhistory"); soci::statement st = (ledgerManager.getDatabase().getSession().prepare << "INSERT INTO txhistory (txid, ledgerseq, txindex, txbody, " "txresult, txmeta) VALUES " "(:id,:seq,:txindex,:txb,:txres,:meta)", soci::use(txIDString), soci::use(ledgerManager.getCurrentLedgerHeader().ledgerSeq), soci::use(txindex), soci::use(txBody), soci::use(txResult), soci::use(meta)); st.execute(true); if (st.get_affected_rows() != 1) { throw std::runtime_error("Could not update data in SQL"); } }
void CalcPbkdf2Hash_80_4way(UInt32 dst[32], const UInt32 *pIhash, const ConstBuf& data) { SHA256 sha; DECLSPEC_ALIGN(128) UInt32 ist[16][4], ost[8][4], buf4[32][4]; UInt32 buf[32], ostate[8], istate[8], bufPasswd[20]; for (int i=0; i<20; ++i) bufPasswd[i] = be32toh(((const UInt32*)data.P)[i]); for (int i=0; i<8; ++i) buf[i] = be32toh(pIhash[i] ^ 0x5C5C5C5C); memset(buf+8, 0x5C, 8*4); sha.InitHash(ostate); sha.HashBlock(ostate, (const byte*)buf, 0); for (int i=0; i<8; ++i) buf[i] = be32toh(pIhash[i] ^ 0x36363636); memset(buf+8, 0x36, 8*4); sha.InitHash(istate); sha.HashBlock(istate, (const byte*)buf, 0); sha.HashBlock(istate, (const byte*)bufPasswd, 0); for (int i=0; i<8; ++i) { ist[i][0] = ist[i][1] = ist[i][2] = ist[i][3] = istate[i]; ost[i][0] = ost[i][1] = ost[i][2] = ost[i][3] = ostate[i]; } for (int i=0; i<4; ++i) buf4[i][0] = buf4[i][1] = buf4[i][2] = buf4[i][3] = bufPasswd[16+i]; memcpy(buf4[4], s_InnerPad, sizeof s_InnerPad); Sha256Update_4way_x86x64Sse2(ist, buf4); memcpy(ist[8], s_OuterPad, sizeof s_OuterPad); Sha256Update_4way_x86x64Sse2(ost, ist); for (int i=0; i<8; ++i) for (int j=0; j<4; ++j) dst[j*8+i] = swap32(ost[i][j]); }
HashValue SHA256_SHA256(const ConstBuf& cbuf) { SHA256 sha; return ConstBuf(sha.ComputeHash(sha.ComputeHash(cbuf))); }
//--------------------------------------------------------------------- PeerContactProfilePtr PeerContactProfile::createExternalFromPrivateProfile(ElementPtr privateProfileElement) { if (!privateProfileElement) return PeerContactProfilePtr(); privateProfileElement = (privateProfileElement->clone())->toElementChecked(); static const char *contactProfileSkeleton = "<contactProfile version=\"0\">\n" " <private>\n" " <salt />\n" " <proof cipher=\"sha256/aes256\" />\n" " <encryptedProfile cipher=\"sha256/aes256\" />\n" " <contactProfileSecret cipher=\"sha256/aes256\" />\n" " </private>\n" "</contactProfile>"; DocumentPtr contactProfileDoc = Document::create(); contactProfileDoc->parse(contactProfileSkeleton); String contactID = services::IHelper::randomString(32); String contactProfileSecret = services::IHelper::randomString(32); // generate external profile { std::string contactSalt; // generate salt { AutoSeededRandomPool rng; SecureByteBlock contactSaltRaw(32); rng.GenerateBlock(contactSaltRaw, contactSaltRaw.size()); contactSalt = convertToBase64(contactSaltRaw, contactSaltRaw.size()); } ElementPtr contactProfileElement = contactProfileDoc->getFirstChildElementChecked(); contactProfileElement->setAttribute("id", contactID); ElementPtr privateElement = contactProfileElement->getFirstChildElementChecked(); ElementPtr saltElement = privateElement->getFirstChildElementChecked(); TextPtr saltText = Text::create(); saltText->setValue(contactSalt); saltElement->adoptAsLastChild(saltText); SecureByteBlock contactProofHash(32); SHA256 contactProof; contactProof.Update((const BYTE *)"proof:", strlen("proof:")); contactProof.Update((const BYTE *)contactProfileSecret.c_str(), contactProfileSecret.size()); contactProof.Final(contactProofHash); String contactProofInBase64 = convertToBase64(contactProofHash, contactProofHash.size()); ElementPtr proofElement = saltElement->getNextSiblingElementChecked(); TextPtr proofText = Text::create(); proofText->setValue(contactProofInBase64); proofElement->adoptAsLastChild(proofText); DocumentPtr privateProfileDocument = Document::create(); privateProfileDocument->adoptAsLastChild(privateProfileElement); ULONG length = 0; boost::shared_array<char> output; output = privateProfileDocument->write(&length); ElementPtr encryptedProfileElement = proofElement->getNextSiblingElementChecked(); String encryptedProfileString = encryptToBase64("profile", contactProfileSecret, contactSalt, (const BYTE *)(output.get()), length); TextPtr encryptProfileText = Text::create(); encryptProfileText->setValue(encryptedProfileString); encryptedProfileElement->adoptAsLastChild(encryptProfileText); ElementPtr contactProfileSecretElement = encryptedProfileElement->getNextSiblingElementChecked(); TextPtr contactProfileSecretText = Text::create(); contactProfileSecretText->setValue(contactProfileSecret); contactProfileSecretElement->adoptAsLastChild(contactProfileSecretText); } PeerContactProfilePtr pThis(new PeerContactProfile); pThis->mThisWeak = pThis; pThis->mDocument = contactProfileDoc; pThis->mContactProfileSecret = contactProfileSecret; return pThis; }
QVector<QString> & AliceKeygen::getKeys() { if (supportedAlice->isEmpty()) throw ERROR; SHA256 sha; char hash[32]; bool status; for (int j = 0; j < supportedAlice->size(); ++j) {/*For pre AGPF 4.5.0sx*/ QString serialStr = supportedAlice->at(j)->serial + "X"; int k = supportedAlice->at(j)->magic[0]; int Q = supportedAlice->at(j)->magic[1]; int serial = (getSsidName().right(8).toInt(&status, 10) - Q) / k; QString tmp = ""; tmp.setNum(serial); for (int i = 0; i < 7 - tmp.length(); i++) { serialStr += "0"; } serialStr += tmp; char mac[6]; QString key = ""; QString macS = getMacAddress(); if (macS.size() == 12) { for (int i = 0; i < 12; i += 2) mac[i / 2] = (macS.mid(i, 1).toInt(&status, 16) << 4) + macS.mid(i + 1, 1).toInt(&status, 16); /* Compute the hash */ sha.reset(); sha.addData(specialSeq, (unsigned long) sizeof(specialSeq)); sha.addData(serialStr.toAscii().data(), serialStr.size()); sha.addData(mac, (unsigned long) sizeof(mac)); sha.result((unsigned char *) hash); for (int i = 0; i < 24; ++i) { key += preInitCharset.at(hash[i] & 0xFF); } if (!results.contains(key)) results.append(key); } /*For post AGPF 4.5.0sx*/ QString macEth = macS.left(6); for (int extraNumber = 0;extraNumber < 10; ++extraNumber) { QString calc = ""; calc.setNum(extraNumber); calc += getSsidName().right(8); calc.setNum(calc.toInt(&status, 10), 16); calc = calc.toUpper(); if (macEth.at(5) == calc.at(0)) { macEth += calc.right(6); break; } } for (int i = 0; i < 12; i += 2) mac[i / 2] = (macEth.mid(i, 1).toInt(&status, 16) << 4) + macEth.mid(i + 1, 1).toInt(&status, 16); /* Compute the hash */ sha.reset(); sha.addData(specialSeq, (unsigned long) sizeof(specialSeq)); sha.addData(serialStr.toAscii().data(), serialStr.size()); sha.addData(mac, (unsigned long) sizeof(mac)); sha.result((unsigned char *) hash); key = ""; for (int i = 0; i < 24; ++i) key += preInitCharset.at(hash[i] & 0xFF); if (!results.contains(key)) results.append(key); } return results; }
static bool doSHA256Checks() { SHA256 hasher; // empty test hasher.hash(std::string("")); if (hasher.toString() != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") INTEGRITY_ERROR; // 1 char test hasher.hash(std::string("a")); if (hasher.toString() != "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb") INTEGRITY_ERROR; // 1 chunk, < 448 bits hasher.hash(std::string("The quick brown fox jumps over the lazy dog.")); if (hasher.toString() != "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c") INTEGRITY_ERROR; // 2 chunk, > 448 bits hasher.hash(std::string("Pneumonoultramicroscopicsilicovolcanoconiosis")); if (hasher.toString() != "0984363991e13bb6c2c6a9442d2ae50ec3b86843131fc02889f4ee2d1c8ca65c") INTEGRITY_ERROR; // 2 chunk hasher.hash(std::string("Pneumonoultramicroscopicsilicovolcanoconiosis is a really, really, really long word.")); if (hasher.toString() != "15064c79fd7d70624a804acc001c0fb4529d2907f82e1af2f231b4832a93a573") INTEGRITY_ERROR; return true; }
void updateSHA256Result() { const SHA256 sha (hashEntryBox.getText().toUTF8()); shaResult.setText (sha.toHexString(), dontSendNotification); }