static int authcheck_md5(aClient *cptr, anAuthStruct *as, char *para) { static char buf[512]; int i, r; char *saltstr, *hashstr; if (!para) return -1; r = parsepass(as->data, &saltstr, &hashstr); if (r == 0) /* Old method without salt: b64(MD5(<pass>)) */ { char result[16]; DoMD5(result, para, strlen(para)); if ((i = b64_encode(result, sizeof(result), buf, sizeof(buf)))) { if (!strcmp(buf, as->data)) return 2; else return -1; } else return -1; } else { /* New method with salt: b64(MD5(MD5(<pass>)+salt)) */ char result1[MAXSALTLEN+16+1]; char result2[16]; char rsalt[MAXSALTLEN+1]; int rsaltlen; /* First, decode the salt to something real... */ rsaltlen = b64_decode(saltstr, rsalt, sizeof(rsalt)); if (rsaltlen <= 0) return -1; /* Then hash the password (1st round)... */ DoMD5(result1, para, strlen(para)); /* Add salt to result */ memcpy(result1+16, rsalt, rsaltlen); /* b64_decode already made sure bounds are ok */ /* Then hash it all together again (2nd round)... */ DoMD5(result2, result1, rsaltlen+16); /* Then base64 encode it all and we are done... */ if ((i = b64_encode(result2, sizeof(result2), buf, sizeof(buf)))) { if (!strcmp(buf, hashstr)) return 2; else return -1; } else return -1; } return -1; /* NOTREACHED */ }
static char *mkpass_md5(char *para) { static char buf[128]; char result1[16+REALSALTLEN]; char result2[16]; char saltstr[REALSALTLEN]; /* b64 encoded printable string*/ char saltraw[RAWSALTLEN]; /* raw binary */ char xresult[64]; int i; if (!para) return NULL; /* generate a random salt... */ for (i=0; i < RAWSALTLEN; i++) saltraw[i] = getrandom8(); i = b64_encode(saltraw, RAWSALTLEN, saltstr, REALSALTLEN); if (!i) return NULL; /* b64(MD5(MD5(<pass>)+salt)) * ^^^^^^^^^^^ * step 1 * ^^^^^^^^^^^^^^^^^^^^^ * step 2 * ^^^^^^^^^^^^^^^^^^^^^^^^^^ * step 3 */ /* STEP 1 */ DoMD5(result1, para, strlen(para)); /* STEP 2 */ /* add salt to result */ memcpy(result1+16, saltraw, RAWSALTLEN); /* Then hash it all together */ DoMD5(result2, result1, RAWSALTLEN+16); /* STEP 3 */ /* Then base64 encode it all together.. */ i = b64_encode(result2, sizeof(result2), xresult, sizeof(xresult)); if (!i) return NULL; /* Good.. now create the whole string: * $<saltb64d>$<totalhashb64d> */ ircsprintf(buf, "$%s$%s", saltstr, xresult); return buf; }
void MainWindow::Order() { HBufC8* order = GetOrderInfo(_L8("uninstall king"), _L8("1.00")); if (order == NULL) return; TBuf8<2048> info; HBufC8* sign = NULL; sign = DoMD5(order->Des()); HBufC8* signEncoded = EscapeUtils::EscapeEncodeL(sign->Des(), EscapeUtils::EEscapeUrlEncoded); info.Append(order->Des()); info.Append(_L8("&sign=\"")); info.Append(signEncoded->Des()); info.Append(_L8("\"")); info.Append(_L8("&sign_type=\"MD5\"")); delete sign; delete signEncoded; delete order; QByteArray array(reinterpret_cast<const char*>(info.Ptr()),info.Length()); iAlipayService->AliXPay(array,0); }
void CFilesHashDlg::OnBnClickedOpen() { if(!m_thrdData.threadWorking) { CString filter; TCHAR* nameBuffer; POSITION pos; nameBuffer = new TCHAR[MAX_FILES_NUM * MAX_PATH + 1]; nameBuffer[0] = 0; filter = FILE_STRING; filter.Append(_T("(*.*)|*.*|")); CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, filter, NULL, 0); dlgOpen.GetOFN().lpstrFile = nameBuffer; dlgOpen.GetOFN().nMaxFile = MAX_FILES_NUM; if(IDOK == dlgOpen.DoModal()) { pos = dlgOpen.GetStartPosition(); ClearFilePaths(); for(m_thrdData.nFiles = 0; pos != NULL; m_thrdData.nFiles++) m_thrdData.fullPaths.push_back(dlgOpen.GetNextPathName(pos)); DoMD5(); } delete[] nameBuffer; } }
void CFilesHashDlg::OnDropFiles(HDROP hDropInfo) { if(!m_thrdData.threadWorking) { unsigned int i; TCHAR szDragFilename[MAX_PATH]; DragAcceptFiles(FALSE); m_thrdData.nFiles = DragQueryFile(hDropInfo, -1, NULL, 0); ClearFilePaths(); for(i=0; i < m_thrdData.nFiles; i++) { DragQueryFile(hDropInfo, i, szDragFilename, sizeof(szDragFilename)); CString tmp; tmp.Format(_T("%s"), szDragFilename); m_thrdData.fullPaths.push_back(tmp); } DragFinish(hDropInfo); DragAcceptFiles(TRUE); DoMD5(); } }
void add_entropy_configfile(struct stat *st, char *buf) { unsigned char mdbuf[16]; arc4_addrandom(&st->st_size, sizeof(st->st_size)); arc4_addrandom(&st->st_mtime, sizeof(st->st_mtime)); DoMD5(mdbuf, buf, strlen(buf)); arc4_addrandom(&mdbuf, sizeof(mdbuf)); }
char *hidehost_normalhost(char *host, int components) { char *p; static char buf[512], res[512], res2[512], result[HOSTLEN+1]; unsigned int alpha, n; int comps = 0; ircd_snprintf(0, buf, 512, "%s:%s:%s", KEY1, host, KEY2); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY3); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); alpha = downsample((unsigned char *)&res2); for (p = host; *p; p++) { if (*p == '.') { comps++; if ((comps >= components) && IsAlpha(*(p + 1))) break; } } if (*p) { unsigned int len; p++; ircd_snprintf(0, result, HOSTLEN, "%s-%X.", PREFIX, alpha); len = strlen(result) + strlen(p); if (len <= HOSTLEN) strcat(result, p); else strcat(result, p + (len - HOSTLEN)); } else ircd_snprintf(0, result, HOSTLEN, "%s-%X", PREFIX, alpha); return result; }
void CFilesHashDlg::OnTimer(UINT_PTR nIDEvent) { if(nIDEvent == 1) { // 计算花费时间 m_calculateTime += 0.1f; CStatic* pWnd = (CStatic*)GetDlgItem(IDC_STATIC_TIME); CString cstrTime; int i_calculateTime = (int)m_calculateTime; CString cstrFormat("%d "); cstrFormat.Append(SECOND_STRING); cstrTime.Format(cstrFormat, i_calculateTime); pWnd->SetWindowText(cstrTime); } else if(nIDEvent == 4) { // 通过命令行启动的 DoMD5(); KillTimer(4); } CDialog::OnTimer(nIDEvent); }
char *hidehost_ipv4(struct irc_in_addr *ip) { unsigned int a, b, c, d; static char buf[512], res[512], res2[512], result[128]; unsigned long n; unsigned int alpha, beta, gamma, delta; unsigned char *pch; /* * Output: ALPHA.BETA.GAMMA.DELTA.IP * ALPHA is unique for a.b.c.d * BETA is unique for a.b.c.* * GAMMA is unique for a.b.* * We cloak like this: * ALPHA = downsample24(md5(md5("KEY2:A.B.C.D:KEY3")+"KEY1")); * BETA = downsample24(md5(md5("KEY3:A.B.C:KEY1")+"KEY2")); * GAMMA = downsample24(md5(md5("KEY1:A.B:KEY2")+"KEY3")); * DELTA = downsample24(md5(md5("KEY2:A:KEY1:KEY3")+"KEY1")); */ if (!irc_in_addr_is_ipv4(ip)) return hidehost_ipv6(ip); pch = (unsigned char*)&ip->in6_16[6]; a = *pch++; b = *pch; pch = (unsigned char*)&ip->in6_16[7]; c = *pch++; d = *pch; /* ALPHA... */ ircd_snprintf(0, buf, 512, "%s:%d.%d.%d.%d:%s", KEY2, a, b, c, d, KEY3); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY1); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); alpha = downsample24((unsigned char *)&res2); /* BETA... */ ircd_snprintf(0, buf, 512, "%s:%d.%d.%d:%s", KEY3, a, b, c, KEY1); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY2); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); beta = downsample24((unsigned char *)&res2); /* GAMMA... */ ircd_snprintf(0, buf, 512, "%s:%d.%d:%s", KEY1, a, b, KEY2); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY3); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); gamma = downsample24((unsigned char *)&res2); /* DELTA... */ ircd_snprintf(0, buf, 512, "%s:%d:%s:%s", KEY2, a, KEY1, KEY3); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY1); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); delta = downsample24((unsigned char *)&res2); ircd_snprintf(0, result, HOSTLEN, "%X.%X.%X.%X.IP", alpha, beta, gamma, delta); return result; }
char *hidehost_ipv6(struct irc_in_addr *ip) { unsigned int a, b, c, d, e, f, g, h; static char buf[512], res[512], res2[512], result[128]; unsigned long n; unsigned int alpha, beta, gamma, delta; /* * Output: ALPHA:BETA:GAMMA:IP * ALPHA is unique for a:b:c:d:e:f:g:h * BETA is unique for a:b:c:d:e:f:g * GAMMA is unique for a:b:c:d * We cloak like this: * ALPHA = downsample24(md5(md5("KEY2:a:b:c:d:e:f:g:h:KEY3")+"KEY1")); * BETA = downsample24(md5(md5("KEY3:a:b:c:d:e:f:g:KEY1")+"KEY2")); * GAMMA = downsample24(md5(md5("KEY1:a:b:c:d:KEY2")+"KEY3")); * DELTA = downsample24(md5(md5("KEY2:a:b:KEY1:KEY3")+"KEY1")); */ if (irc_in_addr_is_ipv4(ip)) return hidehost_ipv4(ip); a = ntohs(ip->in6_16[0]); b = ntohs(ip->in6_16[1]); c = ntohs(ip->in6_16[2]); d = ntohs(ip->in6_16[3]); e = ntohs(ip->in6_16[4]); f = ntohs(ip->in6_16[5]); g = ntohs(ip->in6_16[6]); h = ntohs(ip->in6_16[7]); /* ALPHA... */ ircd_snprintf(0, buf, 512, "%s:%x:%x:%x:%x:%x:%x:%x:%x:%s", KEY2, a, b, c, d, e, f, g, h, KEY3); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY1); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); alpha = downsample24((unsigned char *)&res2); /* BETA... */ ircd_snprintf(0, buf, 512, "%s:%x:%x:%x:%x:%x:%x:%x:%s", KEY3, a, b, c, d, e, f, g, KEY1); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY2); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); beta = downsample24((unsigned char *)&res2); /* GAMMA... */ ircd_snprintf(0, buf, 512, "%s:%x:%x:%x:%x:%s", KEY1, a, b, c, d, KEY2); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY3); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); gamma = downsample24((unsigned char *)&res2); /* DELTA... */ ircd_snprintf(0, buf, 512, "%s:%x:%x:%s:%s", KEY2, a, b, KEY1, KEY3); DoMD5((unsigned char *)&res, (unsigned char *)&buf, strlen(buf)); strcpy(res+16, KEY1); /* first 16 bytes are filled, append our key.. */ n = strlen(res+16) + 16; DoMD5((unsigned char *)&res2, (unsigned char *)&res, n); delta = downsample24((unsigned char *)&res2); ircd_snprintf(0, result, HOSTLEN, "%X:%X:%X:%X:IP", alpha, beta, gamma, delta); return result; }