int main( int argc, char *argv[] ) { int keysize, i; unsigned char tmp[200]; char title[TITLE_LEN]; todo_list todo; if( argc == 1 ) memset( &todo, 1, sizeof( todo ) ); else { memset( &todo, 0, sizeof( todo ) ); for( i = 1; i < argc; i++ ) { if( strcmp( argv[i], "md4" ) == 0 ) todo.md4 = 1; else if( strcmp( argv[i], "md5" ) == 0 ) todo.md5 = 1; else if( strcmp( argv[i], "sha1" ) == 0 ) todo.sha1 = 1; else if( strcmp( argv[i], "sha256" ) == 0 ) todo.sha256 = 1; else if( strcmp( argv[i], "sha512" ) == 0 ) todo.sha512 = 1; else if( strcmp( argv[i], "arc4" ) == 0 ) todo.arc4 = 1; else if( strcmp( argv[i], "des3" ) == 0 ) todo.des3 = 1; else if( strcmp( argv[i], "des" ) == 0 ) todo.des = 1; else if( strcmp( argv[i], "aes_cbc" ) == 0 ) todo.aes_cbc = 1; else if( strcmp( argv[i], "aes_gcm" ) == 0 ) todo.aes_gcm = 1; else if( strcmp( argv[i], "camellia" ) == 0 ) todo.camellia = 1; else if( strcmp( argv[i], "blowfish" ) == 0 ) todo.blowfish = 1; else if( strcmp( argv[i], "havege" ) == 0 ) todo.havege = 1; else if( strcmp( argv[i], "ctr_drbg" ) == 0 ) todo.ctr_drbg = 1; else if( strcmp( argv[i], "rsa" ) == 0 ) todo.rsa = 1; else if( strcmp( argv[i], "dhm" ) == 0 ) todo.dhm = 1; else if( strcmp( argv[i], "ecdsa" ) == 0 ) todo.ecdsa = 1; else if( strcmp( argv[i], "ecdh" ) == 0 ) todo.ecdh = 1; else { printf( "Unrecognized option: %s\n", argv[i] ); printf( "Available options:" OPTIONS ); } } } printf( "\n" ); memset( buf, 0xAA, sizeof( buf ) ); #if defined(POLARSSL_MD4_C) if( todo.md4 ) TIME_AND_TSC( "MD4", md4( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_MD5_C) if( todo.md5 ) TIME_AND_TSC( "MD5", md5( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_SHA1_C) if( todo.sha1 ) TIME_AND_TSC( "SHA-1", sha1( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_SHA256_C) if( todo.sha256 ) TIME_AND_TSC( "SHA-256", sha256( buf, BUFSIZE, tmp, 0 ) ); #endif #if defined(POLARSSL_SHA512_C) if( todo.sha512 ) TIME_AND_TSC( "SHA-512", sha512( buf, BUFSIZE, tmp, 0 ) ); #endif #if defined(POLARSSL_ARC4_C) if( todo.arc4 ) { arc4_context arc4; arc4_setup( &arc4, tmp, 32 ); TIME_AND_TSC( "ARC4", arc4_crypt( &arc4, BUFSIZE, buf, buf ) ); } #endif #if defined(POLARSSL_DES_C) && defined(POLARSSL_CIPHER_MODE_CBC) if( todo.des3 ) { des3_context des3; des3_set3key_enc( &des3, tmp ); TIME_AND_TSC( "3DES", des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } if( todo.des ) { des_context des; des_setkey_enc( &des, tmp ); TIME_AND_TSC( "DES", des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } #endif #if defined(POLARSSL_AES_C) #if defined(POLARSSL_CIPHER_MODE_CBC) if( todo.aes_cbc ) { aes_context aes; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "AES-CBC-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); aes_setkey_enc( &aes, tmp, keysize ); TIME_AND_TSC( title, aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } } #endif #if defined(POLARSSL_GCM_C) if( todo.aes_gcm ) { gcm_context gcm; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "AES-GCM-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); gcm_init( &gcm, POLARSSL_CIPHER_ID_AES, tmp, keysize ); TIME_AND_TSC( title, gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp ) ); } } #endif #endif #if defined(POLARSSL_CAMELLIA_C) && defined(POLARSSL_CIPHER_MODE_CBC) if( todo.camellia ) { camellia_context camellia; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); camellia_setkey_enc( &camellia, tmp, keysize ); TIME_AND_TSC( title, camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } } #endif #if defined(POLARSSL_BLOWFISH_C) && defined(POLARSSL_CIPHER_MODE_CBC) if( todo.blowfish ) { blowfish_context blowfish; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); blowfish_setkey( &blowfish, tmp, keysize ); TIME_AND_TSC( title, blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } } #endif #if defined(POLARSSL_HAVEGE_C) if( todo.havege ) { havege_state hs; havege_init( &hs ); TIME_AND_TSC( "HAVEGE", havege_random( &hs, buf, BUFSIZE ) ); } #endif #if defined(POLARSSL_CTR_DRBG_C) if( todo.ctr_drbg ) { ctr_drbg_context ctr_drbg; if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) exit(1); TIME_AND_TSC( "CTR_DRBG (NOPR)", if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1) ); if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) exit(1); ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON ); TIME_AND_TSC( "CTR_DRBG (PR)", if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1) ); }
void * Buscar(void * param) { vector <string> BloqueDic; BloqueDic = *(vector<string>*) param; int LargoBloque= BloqueDic.size(); //cout << " Primero: "<<BloqueDic[0]<<" ultimo: "<<BloqueDic[LargoBloque-1]<<endl; string PalabraDB = DB[indice].pass; int TamanoDB = DB.size(); string Criptograma; string result; while(indice<TamanoDB){ int IndiceAux = indice; pthread_mutex_lock (&mutexsum); result = BuscarCache(DB[indice].pass); //cout << "Resultado del cache es: "<<result<<endl; if(result.compare("1")!=0){ //cout << "LA ENCONTRE y es(cache): "<<result<<endl; Resultado << DB[indice].name <<" "<<result<<endl; //cout << DB[indice].name <<" "<<result<<endl; indice++; result.clear(); } pthread_mutex_unlock (&mutexsum); if(result.compare("1")==0&&IndiceAux==indice) { for(int i = 0;i<LargoBloque;i++){ if(IndiceAux!=indice){ break; } Criptograma = md5(BloqueDic[i]); string Comp; pthread_mutex_lock (&mutexsum); if (indice<TamanoDB){ Comp = DB[indice].pass; } pthread_mutex_unlock (&mutexsum); if(Criptograma.compare(Comp)==0){ pthread_mutex_lock (&mutexsum); //cout << "LA ENCONTRE y es: "<<BloqueDic[i]<<endl; Resultado << DB[indice].name <<" "<<BloqueDic[i]<<endl; //cout << DB[indice].name <<" "<<BloqueDic[i]<<endl; indice++; insert(Criptograma,BloqueDic[i]); pthread_mutex_unlock (&mutexsum); break; } } } } //cout << "terminooooooooo la hebra\n"; pthread_exit(NULL); }
/* Currently documented in doc/src/declarative/globalobject.qdoc */ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEngine *engine) { #ifndef QT_NO_SETTINGS qmlsqldatabase_initDatabasesPath(engine); QSqlDatabase database; QString dbname = context->argument(0).toString(); QString dbversion = context->argument(1).toString(); QString dbdescription = context->argument(2).toString(); int dbestimatedsize = context->argument(3).toNumber(); QScriptValue dbcreationCallback = context->argument(4); QCryptographicHash md5(QCryptographicHash::Md5); md5.addData(dbname.toUtf8()); QString dbid(QLatin1String(md5.result().toHex())); QString basename = qmlsqldatabase_databaseFile(dbid, engine); bool created = false; QString version = dbversion; { QSettings ini(basename+QLatin1String(".ini"),QSettings::IniFormat); if (QSqlDatabase::connectionNames().contains(dbid)) { database = QSqlDatabase::database(dbid); version = ini.value(QLatin1String("Version")).toString(); if (version != dbversion && !dbversion.isEmpty() && !version.isEmpty()) THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch")); } else { created = !QFile::exists(basename+QLatin1String(".sqlite")); database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); if (created) { ini.setValue(QLatin1String("Name"), dbname); if (dbcreationCallback.isFunction()) version = QString(); ini.setValue(QLatin1String("Version"), version); ini.setValue(QLatin1String("Description"), dbdescription); ini.setValue(QLatin1String("EstimatedSize"), dbestimatedsize); ini.setValue(QLatin1String("Driver"), QLatin1String("QSQLITE")); } else { if (!dbversion.isEmpty() && ini.value(QLatin1String("Version")) != dbversion) { // Incompatible THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch")); } version = ini.value(QLatin1String("Version")).toString(); } database.setDatabaseName(basename+QLatin1String(".sqlite")); } if (!database.isOpen()) database.open(); } QScriptValue instance = engine->newObject(); instance.setProperty(QLatin1String("transaction"), engine->newFunction(qmlsqldatabase_transaction,1)); instance.setProperty(QLatin1String("readTransaction"), engine->newFunction(qmlsqldatabase_read_transaction,1)); instance.setProperty(QLatin1String("version"), version, QScriptValue::ReadOnly); instance.setProperty(QLatin1String("changeVersion"), engine->newFunction(qmlsqldatabase_change_version,3)); QScriptValue result = engine->newVariant(instance,QVariant::fromValue(database)); if (created && dbcreationCallback.isFunction()) { dbcreationCallback.call(QScriptValue(), QScriptValueList() << result); } return result; #else return engine->undefinedValue(); #endif // QT_NO_SETTINGS }
static void check(skiatest::Reporter* r, const char path[], SkISize size, bool supportsScanlineDecoding, bool supportsSubsetDecoding) { SkAutoTDelete<SkStream> stream(resource(path)); if (!stream) { SkDebugf("Missing resource '%s'\n", path); return; } SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); if (!codec) { ERRORF(r, "Unable to decode '%s'", path); return; } // This test is used primarily to verify rewinding works properly. Using kN32 allows // us to test this without the added overhead of creating different bitmaps depending // on the color type (ex: building a color table for kIndex8). DM is where we test // decodes to all possible destination color types. SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); REPORTER_ASSERT(r, info.dimensions() == size); SkBitmap bm; bm.allocPixels(info); SkAutoLockPixels autoLockPixels(bm); SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); REPORTER_ASSERT(r, result == SkCodec::kSuccess); SkMD5::Digest digest; md5(bm, &digest); bm.eraseColor(SK_ColorYELLOW); result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); REPORTER_ASSERT(r, result == SkCodec::kSuccess); // verify that re-decoding gives the same result. compare_to_good_digest(r, digest, bm); stream.reset(resource(path)); SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( SkScanlineDecoder::NewFromStream(stream.detach())); if (supportsScanlineDecoding) { bm.eraseColor(SK_ColorYELLOW); REPORTER_ASSERT(r, scanlineDecoder); REPORTER_ASSERT(r, scanlineDecoder->start(info) == SkCodec::kSuccess); for (int y = 0; y < info.height(); y++) { result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0); REPORTER_ASSERT(r, result == SkCodec::kSuccess); } // verify that scanline decoding gives the same result. compare_to_good_digest(r, digest, bm); } else { REPORTER_ASSERT(r, !scanlineDecoder); } // The rest of this function tests decoding subsets, and will decode an arbitrary number of // random subsets. // Do not attempt to decode subsets of an image of only once pixel, since there is no // meaningful subset. if (size.width() * size.height() == 1) { return; } SkRandom rand; SkIRect subset; SkCodec::Options opts; opts.fSubset = ⊂ for (int i = 0; i < 5; i++) { subset = generate_random_subset(&rand, size.width(), size.height()); SkASSERT(!subset.isEmpty()); const bool supported = codec->getValidSubset(&subset); REPORTER_ASSERT(r, supported == supportsSubsetDecoding); SkImageInfo subsetInfo = info.makeWH(subset.width(), subset.height()); SkBitmap bm; bm.allocPixels(subsetInfo); const SkCodec::Result result = codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes(), &opts, NULL, NULL); if (supportsSubsetDecoding) { REPORTER_ASSERT(r, result == SkCodec::kSuccess); // Webp is the only codec that supports subsets, and it will have modified the subset // to have even left/top. REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop)); } else { // No subsets will work. REPORTER_ASSERT(r, result == SkCodec::kUnimplemented); } } }
//method returns account if card with given password and number exists const Account* DataStorage::getAccountByCard(const string &number,const string& password){ for(int i=0;i<static_cast<int>(DataStorage::_data.accounts().size());i++){ for(int j=0;j<static_cast<int>(DataStorage::_data.accounts()[i].cards().size());j++){ if((DataStorage::_data.accounts()[i].cards()[j].number()==number)&&(DataStorage::_data.accounts()[i].cards()[j].password()==md5(password))) return &DataStorage::_data.accounts()[i]; } } return new Account(); }
int Coupler::waitForMessage(void) { fd_set fd; FD_ZERO(&fd); FD_SET(sock, &fd); bool resend = true; string buf; char *buffer; unsigned int size; while(resend) { int nError = select(0, &fd, NULL, NULL, &tv); // czekamy a¿ bêdzie mo¿na coœ odczytaæ z socketa if (nError == 0) // timeout { return 1; } if (nError == SOCKET_ERROR) // winsock error { return 2; } int dataLength = recv(sock, (char*)&size, sizeof(size), 0); if (dataLength == 0) // client disconnected { return 3; } nError = WSAGetLastError(); if (nError != 0) // winsock error { return 4; } size = ntohl(size); char checksum[32]; dataLength = recv(sock, checksum, sizeof(checksum), 0); if (dataLength == 0) // client disconnected { return 3; } nError = WSAGetLastError(); if (nError != 0) // winsock error { return 4; } buffer = new char[size]; dataLength = recv(sock, buffer, size, 0); if (dataLength == 0) // client disconnected { return 3; } nError = WSAGetLastError(); if (nError != 0) // winsock error { return 4; } buffer[size] = '\0'; buf = buffer; string checkSum(checksum); if(md5(buf) != checkSum) { send(sock, "Error\0", 6, 0); resend = true; } else { send(sock, "Ok\0", 3, 0); resend = false; } } int ret = parent->decrypt(buf.c_str(), size); delete [] buffer; return ret; }
/** * Compute the digest for bm and compare it to a known good digest. * @param r Reporter to assert that bm's digest matches goodDigest. * @param goodDigest The known good digest to compare to. * @param bm The bitmap to test. */ static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& goodDigest, const SkBitmap& bm) { SkMD5::Digest digest; md5(bm, &digest); REPORTER_ASSERT(r, digest == goodDigest); }
/** * @brief MD5 wrapper * output = md5(input) * @param[in] input Input data buffer * @param[in] inputLength Input data length in bytes * @param[out] output Output data buffer. * */ void bctbx_md5(const uint8_t *input, size_t inputLength, uint8_t output[16]) { md5(input, inputLength, output); }
int Coupler::sendAndWait(const char* msg, int length) { string checkSum; int size = length; checkSum = md5(msg); int bufSize = size+checkSum.length()+sizeof(size)+1; char *buffer = new char[bufSize]; size = htonl(size); memcpy(buffer, &size, sizeof(size)); memcpy(buffer+sizeof(size), checkSum.c_str(), checkSum.length()); memcpy(buffer+sizeof(size)+checkSum.length(), msg, length); buffer[bufSize-1] = '\0'; bool resend = true; char response[10]; int counter = 0; while(resend) { /*std::cout << "Wysylam: (len = " << bufSize; for(int i = 0; i < bufSize; ++i) std::cout << buffer[i]; std::cout << "\n";*/ if(send(sock, buffer, bufSize, 0) == SOCKET_ERROR) return 1; fd_set fd; FD_ZERO(&fd); FD_SET(sock, &fd); std::cout << "Czekam na odpowiedz\n"; int nError = select(0, &fd, NULL, NULL, &tv); // czekamy a¿ bêdzie mo¿na coœ odczytaæ z socketa if (nError == 0) // timeout { return 1; } if (nError == SOCKET_ERROR) // winsock error { return 2; } int dataLength = recv(sock, response, sizeof(response), 0); if (dataLength == 0) // client disconnected { return 3; } nError = WSAGetLastError(); if (nError != 0) // winsock error { return 4; } std::cout << "Odebrano odpowiedz: " << response << "\n"; if(strcmp(response, "Ok") == 0) resend = false; else { ++counter; if(counter > 2) // maksymalnie 3 razy ponawiamy próbê wys³ania { delete [] buffer; return 5; } } } int ret = waitForMessage(); delete [] buffer; return ret; }
void MainWindow::TextChanged(QString text) { if(text.isEmpty()) { this->ui->lineEdit_2->setText("Enter some text"); return; } QString str; switch(this->comboselected) { case 0: // MD5 this->ui->lineEdit_2->setText(QString().fromStdString(md5(text.toStdString()))); break; case 1: // MD4 //this->ui->lineEdit_2->setText(); break; case 2: // SHA-1 this->ui->lineEdit_2->setText(SHA1Hash(text)); break; case 3: // SHA-2 //this->ui->lineEdit_2->setText(); break; case 4: // SHA-3 //this->ui->lineEdit_2->setText(); break; case 5: // SHA-256 this->ui->lineEdit_2->setText(SHA256Hash(text)); break; case 6: // SHA-384 //this->ui->lineEdit_2->setText(); break; case 7: // SHA-512 //this->ui->lineEdit_2->setText(); break; case 8: // RIPEMD-128 //this->ui->lineEdit_2->setText(); break; case 9: // RIPEMD-160 //this->ui->lineEdit_2->setText(); break; case 10: // Whirlpool //this->ui->lineEdit_2->setText(); break; case 11: // GOST //this->ui->lineEdit_2->setText(); break; case 12: // Tiger //this->ui->lineEdit_2->setText(); break; case 13: // Skein //this->ui->lineEdit_2->setText(); break; case 14: // Blake if(BlakeHash(str, text)) this->ui->lineEdit_2->setText(str); break; case 15: // NONE this->ui->lineEdit_2->setText(text); break; default: break; } }
//cache file int PutInCacheFile(char *fileName,char *xmlFileName) { FILE *fp; if ((fp=fopen(fileName,"w"))==NULL) { printf("cannot open file\n"); exit(0); } xmlDocPtr doc; // djf定义解析文档指针 xmlNodePtr rootNode,bucNode,objNode;//定义节点指针(在各个节点之间移动) char *szDocName; szDocName = (char *)xmlFileName; doc = xmlReadFile(szDocName,"GB2312",XML_PARSE_RECOVER); if (doc == NULL) { printf("document not parsed successfully"); return -1; } //确定文档根元素 rootNode = xmlDocGetRootElement(doc); if (rootNode == NULL) { printf("empty document"); xmlFreeDoc(doc); return -1; } //curNode=curNode->xmlChildrenNode; bucNode = rootNode->children; printf("--------------------------------\n"); while (bucNode != NULL) //打印第一层节点 { objNode = bucNode->children; while (objNode!=NULL)//打印第二层节点 { unsigned char temp[50]; strcpy(temp,rootNode->name); strcat(temp,"/"); strcat(temp,bucNode->name); strcat(temp,"/"); strcat(temp,objNode->name); int len = strlen(temp); //生成md5值 unsigned char md5sum[16]={0}; unsigned char md5_str[33]={0}; md5(temp,len,md5sum); md5_2_str(md5sum,md5_str); //生成value值 Meta_Data *metaData = (Meta_Data *)malloc(sizeof(Meta_Data)); Meta_Data *meta1 = (Meta_Data *)malloc(sizeof(Meta_Data)); strcpy(metaData->replica[0].rep_ip,"192.168.0.18"); md_put(md5_str,metaData); GetValue(md5_str,meta1); printf("the value is %s\n",meta1->replica[0].rep_ip); //printf("%s\t%s\n",temp,md5_str); fprintf(fp,"%s\t%s\t%s\n",temp,md5_str,meta1->replica[0].rep_ip); // PutValue(temp,md5_str); objNode=objNode->next; } bucNode = bucNode->next; } xmlFreeDoc(doc); fclose(fp); }
static QString generateThumbnailPath(const QString& uri, ThumbnailGroup::Enum group) { KMD5 md5(QFile::encodeName(uri)); QString baseDir = ThumbnailLoadJob::thumbnailBaseDir(group); return baseDir + QString(QFile::encodeName(md5.hexDigest())) + ".png"; }
void apop(Ticketreq *tr, int type) { int challen, i, tries; char *secret, *hkey, *p; Ticketreq treq; DigestState *s; char sbuf[SECRETLEN], hbuf[DESKEYLEN]; char tbuf[TICKREQLEN]; char buf[MD5dlen*2]; uchar digest[MD5dlen], resp[MD5dlen]; ulong rb[4]; char chal[256]; USED(tr); /* * Create a challenge and send it. */ randombytes((uchar*)rb, sizeof(rb)); p = chal; p += snprint(p, sizeof(chal), "<%lux%lux.%lux%lux@%s>", rb[0], rb[1], rb[2], rb[3], domainname()); challen = p - chal; print("%c%-5d%s", AuthOKvar, challen, chal); /* give user a few attempts */ for(tries = 0; ; tries++) { /* * get ticket request */ if(readn(0, tbuf, TICKREQLEN) < 0) exits(0); convM2TR(tbuf, &treq); tr = &treq; if(tr->type != type) exits(0); /* * read response */ if(readn(0, buf, MD5dlen*2) < 0) exits(0); for(i = 0; i < MD5dlen; i++) resp[i] = (h2b(buf[2*i])<<4)|h2b(buf[2*i+1]); /* * lookup */ secret = findsecret(KEYDB, tr->uid, sbuf); hkey = findkey(KEYDB, tr->hostid, hbuf); if(hkey == 0 || secret == 0){ replyerror("apop-fail bad response %s", raddr); logfail(tr->uid); if(tries > 5) return; continue; } /* * check for match */ if(type == AuthCram){ hmac_md5((uchar*)chal, challen, (uchar*)secret, strlen(secret), digest, nil); } else { s = md5((uchar*)chal, challen, 0, 0); md5((uchar*)secret, strlen(secret), digest, s); } if(memcmp(digest, resp, MD5dlen) != 0){ replyerror("apop-fail bad response %s", raddr); logfail(tr->uid); if(tries > 5) return; continue; } break; } succeed(tr->uid); /* * reply with ticket & authenticator */ if(tickauthreply(tr, hkey) < 0) exits(0); if(debug){ if(type == AuthCram) syslog(0, AUTHLOG, "cram-ok %s %s", tr->uid, raddr); else syslog(0, AUTHLOG, "apop-ok %s %s", tr->uid, raddr); } }
void GoGenerator::generateStruct() { if (program_->structs_.defs_.empty()) return; for(auto& it :program_->structs_.defs_) { if(it->fileName_!=program_->fileName_) { //包含头文件 不生成代码 continue; } std::string name=program_->outputDir_+it->name_+".go"; goFile_.open(name.c_str()); goFile_<<indent()<<"package "<<"rpc"<<std::endl; ///struct //fingerprint goFile_<<std::endl; goFile_<<indent()<<"const "<<it->name_<<"_"<<"strFingerprint=\""<<md5(it->getFingerPrint())<<"\""<<std::endl; goFile_<<indent()<<"type "<<it->name_<<" struct{"<<std::endl; indent_up(); //属性 for(auto& inner:it->members_) { goFile_<<indent()<<setInitialUpper(inner->name_)<<" "<<typeName(inner->type_)<<" `name:\""<<inner->name_<<"\"`"<<std::endl; } indent_down(); goFile_<<indent()<<"}" <<std::endl; //struct id goFile_<<indent()<<"func (this *"<<it->name_<<") GetFingerprint() string{"<<std::endl; indent_up(); goFile_<<indent()<<"return "<<it->name_<<"_"<<"strFingerprint"<<std::endl; indent_down(); goFile_<<"}"<<std::endl; //struct 序列化 goFile_<<indent()<<"func (this *"<<it->name_<<") Serialize( P__ IProtocol){"<<std::endl; indent_up(); for(auto& inner:it->members_) { serializeField(inner->type_,"this."+setInitialUpper(inner->name_),"P__"); goFile_<<std::endl; } indent_down(); goFile_<<"}"<<std::endl; //struct 反序列化 goFile_<<indent()<<"func (this *"<<it->name_<<") DeSerialize( P__ IProtocol) bool{"<<std::endl; indent_up(); for(auto& inner:it->members_) { deSerializeField(inner->type_,"this."+setInitialUpper(inner->name_)); goFile_<<std::endl; } goFile_<<indent()<<"return true"<<std::endl; indent_down(); goFile_<<"}"<<std::endl; goFile_<<std::endl; goFile_.close(); } }
void GoGenerator::genServiceProxy() { if (program_->services_.defs_.empty()) return; //接口文件 std::string fileName=program_->outputDir_+"I"+program_->baseName_+"Proxy.go"; goFile_.open(fileName.c_str()); goFile_<<indent()<<"package "<<"rpc"<<std::endl; goFile_<<std::endl; for (auto& it:program_->services_.defs_) { if(it->fileName_!=program_->fileName_) { //包含头文件 不生成代码 continue; } std::string ifName="I"+it->name_+"Proxy"; goFile_<<indent()<<"type "<<ifName<<" interface {"<<std::endl; indent_up(); for(auto& inner:it->funs_) { goFile_<<indent()<<setInitialUpper(inner->name_)<<" ("; genFunAgrList(goFile_,inner->argrs_); goFile_<<") bool"; goFile_<<std::endl; } indent_down(); goFile_<<indent()<<"}"<<std::endl; goFile_<<std::endl; } goFile_.close(); // fileName=program_->outputDir_+program_->baseName_+"Proxy.go"; goFile_.open(fileName.c_str()); goFile_<<indent()<<"package "<<"rpc"<<std::endl; goFile_<<std::endl; for (auto& it:program_->services_.defs_) { if(it->fileName_!=program_->fileName_) { //包含头文件 不生成代码 continue; } std::string ifName=it->name_+"Proxy"; goFile_<<indent()<<"const "<<it->name_<<"_"<<"strFingerprintProxy=\""<<md5(it->getFingerPrint())<<"\""<<std::endl; goFile_<<indent()<<"type "<<ifName<<" struct {"<<std::endl; indent_up(); goFile_<<indent()<<"I__ I"<<ifName<<std::endl; indent_down(); goFile_<<indent()<<"}"<<std::endl; goFile_<<std::endl; //get id goFile_<<indent()<<"func (this *"<<it->name_<<"Proxy) GetFingerprint() string{"<<std::endl; indent_up(); goFile_<<indent()<<"return "<<it->name_<<"_"<<"strFingerprintProxy"<<std::endl; indent_down(); goFile_<<indent()<<"}"<<std::endl; //dispatch goFile_<<indent()<<"func (this *"<<it->name_<<"Proxy) "<<"Dispatch"<<"("; goFile_<<" P__ IProtocol"; goFile_<<") bool {"<<std::endl; indent_up(); goFile_<<indent()<<"id :=P__.ReadUInt16()"<<std::endl; goFile_<<indent()<<"switch id {"<<std::endl; int i=0; for(auto& it:it->funs_) { goFile_<<indent()<<"case "<<i++<<":"<<std::endl; indent_up(); goFile_<<indent()<<"return "<<"this.recv_"<<it->name_<<"(P__)"<<std::endl; indent_down(); } goFile_<<indent()<<"default:"<<std::endl; goFile_<<indent()<<" return false"<<std::endl; goFile_<<indent()<<"}//switch "<<std::endl; indent_down(); goFile_<<indent()<<"}//dispatch func"<<std::endl; //func for(auto& inner:it->funs_) { goFile_<<indent()<<"func (this *"<<it->name_<<"Proxy) "<<"recv_"<<inner->name_<<" ("; goFile_<<" P__ IProtocol "; goFile_<<") bool {"<<std::endl; indent_up(); goFile_<<std::endl; deSerializeFields(inner->argrs_); goFile_<<indent()<<"return this.I__."<<setInitialUpper(inner->name_)<<"("; genFunAgrList(goFile_,inner->argrs_,true); goFile_<<")"<<std::endl; indent_down(); goFile_<<indent()<<"}"<<std::endl; } } goFile_.close(); }
String CUserAccount::getMD5Digest(const String plaintext) { CMD5 md5(plaintext.c_str()); return md5.getMD5Digest(); }