DualWord DualWordArray::at(size_t i) const { //const MultiPackedWord multipackedRep = multipacked()[i]; //const UnpackedWord unpackedRep = unpacked()[i]; //const DualWord retval(multipackedRep, unpackedRep); //return retval; return DualWord(multipacked()[i], unpacked()[i]); }
static int LoadSignature(const CString &signatureFilename, signature_packet_t *p_sig) { FILE * pFile = _tfsopen(signatureFilename, _T("rb"), SH_DENYWR); if (pFile) { int size = 65536; std::unique_ptr<unsigned char[]> buffer(new unsigned char[size]); int length = 0; if ((length = (int)fread(buffer.get(), sizeof(char), size, pFile)) >= 8) { fclose(pFile); // is unpacking needed? if ((uint8_t)buffer[0] < 0x80) { std::unique_ptr<unsigned char[]> unpacked(new unsigned char[size]); size = pgp_unarmor((char *)buffer.get(), length, unpacked.get(), length); if (size < 2) return -1; buffer.swap(unpacked); } else size = length; if (packet_type(buffer[0]) != SIGNATURE_PACKET) return -1; DWORD i_header_len = packet_header_len(buffer[0]); if ((i_header_len != 1 && i_header_len != 2 && i_header_len != 4) || i_header_len + 1 > (DWORD)size) return -1; DWORD i_len = scalar_number((uint8_t *)(buffer.get() + 1), i_header_len); if (i_len + i_header_len + 1 != (DWORD)size) return -1; if (parse_signature_packet(p_sig, (uint8_t *)(buffer.get() + 1 + i_header_len), i_len)) return -1; if (p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE) { if (p_sig->version == 4) { free(p_sig->specific.v4.hashed_data); free(p_sig->specific.v4.unhashed_data); } return -1; } return 0; } else fclose(pFile); } return -1; }
int main(int c,char **argv) { QCoreApplication app(c,argv); if(app.arguments().size()<2) { qDebug() << app.arguments()[0] << " texturename"; return 0; } QFile src_tex(app.arguments()[1]); if(src_tex.exists() && src_tex.open(QFile::ReadOnly)) { TexFileHdr hdr; src_tex.read((char *)&hdr,sizeof(TexFileHdr)); if(0==memcmp(hdr.magic,"TX2",3)) { qDebug() << "hdr.file_size" << hdr.file_size; qDebug() << "image size " << hdr.wdth << 'x'<<hdr.hght; qDebug() << "flags" << QString::number(hdr.flags,16); qDebug() << "fade" << hdr.fade[0]<< hdr.fade[1]; qDebug() << "alpha" << QString::number(hdr.alpha,16); QString originalname=QString(src_tex.read(hdr.header_size-sizeof(TexFileHdr))); qDebug() << "Original name was:" << originalname; QFileInfo fi(originalname); QDir here; here.mkpath(fi.path()); QFile unpacked(originalname); unpacked.open(QFile::WriteOnly); unpacked.write(src_tex.readAll()); unpacked.close(); CohTextureInfo info { hdr.file_size, hdr.wdth, hdr.hght, hdr.flags, {hdr.fade[0],hdr.fade[1]}, hdr.alpha }; qDebug() << saveTo(info); } } return 0; }
void burst_result::msgpack_unpack(msgpack::object o) { shared_ptr<result_window> unpacked(new result_window()); unpacked->msgpack_unpack(o); p_ = unpacked; }
// Extract digits from fully packed slots void extractDigitsPacked(Ctxt& ctxt, long botHigh, long r, long ePrime, const vector<ZZX>& unpackSlotEncoding) { FHE_TIMER_START; // Step 1: unpack the slots of ctxt FHE_NTIMER_START(unpack); ctxt.cleanUp(); // Apply the d automorphisms and store them in scratch area long d = ctxt.getContext().zMStar.getOrdP(); vector<Ctxt> scratch; // used below vector<Ctxt> unpacked(d, Ctxt(ZeroCtxtLike, ctxt)); { // explicit scope to force all temporaries to be released vector< shared_ptr<DoubleCRT> > coeff_vector; coeff_vector.resize(d); for (long i = 0; i < d; i++) coeff_vector[i] = shared_ptr<DoubleCRT>(new DoubleCRT(unpackSlotEncoding[i], ctxt.getContext(), ctxt.getPrimeSet()) ); Ctxt tmp1(ZeroCtxtLike, ctxt); Ctxt tmp2(ZeroCtxtLike, ctxt); // FIXME: implement using hoisting! for (long j = 0; j < d; j++) { // process jth Frobenius tmp1 = ctxt; tmp1.frobeniusAutomorph(j); tmp1.cleanUp(); // FIXME: not clear if we should call cleanUp here for (long i = 0; i < d; i++) { tmp2 = tmp1; tmp2.multByConstant(*coeff_vector[mcMod(i+j, d)]); unpacked[i] += tmp2; } } } FHE_NTIMER_STOP(unpack); // Step 2: extract the digits top-1,...,0 from the slots of unpacked[i] long p = ctxt.getContext().zMStar.getP(); long p2r = power_long(p,r); long topHigh = botHigh + r-1; #ifdef DEBUG_PRINTOUT cerr << "+ After unpack "; decryptAndPrint(cerr, unpacked[0], *dbgKey, *dbgEa, printFlag); cerr << " extracting "<<(topHigh+1)<<" digits\n"; #endif if (p==2 && r>2) topHigh--; // For p==2 we sometime get a bit for free FHE_NTIMER_START(extractDigits); for (long i=0; i<(long)unpacked.size(); i++) { if (topHigh<=0) { // extracting LSB = no-op scratch.assign(1,unpacked[i]); } else { // extract digits topHigh...0, store them in scratch extractDigits(scratch, unpacked[i], topHigh+1); } // set upacked[i] = -\sum_{j=botHigh}^{topHigh} scratch[j] * p^{j-botHigh} if (topHigh >= (long)scratch.size()) { topHigh = scratch.size() -1; cerr << " @ suspect: not enough digits in extractDigitsPacked\n"; } unpacked[i] = scratch[topHigh]; for (long j=topHigh-1; j>=botHigh; --j) { unpacked[i].multByP(); unpacked[i] += scratch[j]; } if (p==2 && botHigh>0) // For p==2, subtract also the previous bit unpacked[i] += scratch[botHigh-1]; unpacked[i].negate(); if (r>ePrime) { // Add in digits from the bottom part, if any long topLow = r-1 - ePrime; Ctxt tmp = scratch[topLow]; for (long j=topLow-1; j>=0; --j) { tmp.multByP(); tmp += scratch[j]; } if (ePrime>0) tmp.multByP(ePrime); // multiply by p^e' unpacked[i] += tmp; } unpacked[i].reducePtxtSpace(p2r); // Our plaintext space is now mod p^r } FHE_NTIMER_STOP(extractDigits); #ifdef DEBUG_PRINTOUT cerr << "+ Before repack "; decryptAndPrint(cerr, unpacked[0], *dbgKey, *dbgEa, printFlag); #endif // Step 3: re-pack the slots FHE_NTIMER_START(repack); const EncryptedArray& ea2 = *ctxt.getContext().ea; ZZX xInSlots; vector<ZZX> xVec(ea2.size()); ctxt = unpacked[0]; for (long i=1; i<d; i++) { x2iInSlots(xInSlots, i, xVec, ea2); unpacked[i].multByConstant(xInSlots); ctxt += unpacked[i]; } FHE_NTIMER_STOP(repack); }
// Extract digits from thinly packed slots void extractDigitsThin(Ctxt& ctxt, long botHigh, long r, long ePrime) { FHE_TIMER_START; Ctxt unpacked(ctxt); unpacked.cleanUp(); vector<Ctxt> scratch; // Step 2: extract the digits top-1,...,0 from the slots of unpacked[i] long p = ctxt.getContext().zMStar.getP(); long p2r = power_long(p,r); long topHigh = botHigh + r-1; #ifdef DEBUG_PRINTOUT cerr << "+ After unpack "; decryptAndPrint(cerr, unpacked, *dbgKey, *dbgEa, printFlag); cerr << " extracting "<<(topHigh+1)<<" digits\n"; #endif if (p==2 && r>2) topHigh--; // For p==2 we sometime get a bit for free if (topHigh<=0) { // extracting LSB = no-op scratch.assign(1, unpacked); } else { // extract digits topHigh...0, store them in scratch extractDigits(scratch, unpacked, topHigh+1); } // set upacked = -\sum_{j=botHigh}^{topHigh} scratch[j] * p^{j-botHigh} if (topHigh >= LONG(scratch.size())) { topHigh = scratch.size() -1; cerr << " @ suspect: not enough digits in extractDigitsPacked\n"; } unpacked = scratch[topHigh]; for (long j=topHigh-1; j>=botHigh; --j) { unpacked.multByP(); unpacked += scratch[j]; } if (p==2 && botHigh>0) // For p==2, subtract also the previous bit unpacked += scratch[botHigh-1]; unpacked.negate(); if (r>ePrime) { // Add in digits from the bottom part, if any long topLow = r-1 - ePrime; Ctxt tmp = scratch[topLow]; for (long j=topLow-1; j>=0; --j) { tmp.multByP(); tmp += scratch[j]; } if (ePrime>0) tmp.multByP(ePrime); // multiply by p^e' unpacked += tmp; } unpacked.reducePtxtSpace(p2r); // Our plaintext space is now mod p^r #ifdef DEBUG_PRINTOUT cerr << "+ Before repack "; decryptAndPrint(cerr, unpacked[0], *dbgKey, *dbgEa, printFlag); #endif ctxt = unpacked; }