void normalize(){ (*this) /= modulus(); }
Point normalized(){ Point p = *this; return p / modulus(); }
void _reentrant verify_result(){ WORD temp, temp1, i; WORD no_words, rem_bytes; WORD bytes = num_bytes; if (sysaddr_mod != 0){ verify_modulo(); return; } if (start_byte_send != start_byte_receive){ shift_bytes(); // update start_byte_send and start_byte_receive start_byte_send = 0; start_byte_receive = 0; } // If start_byte_receive != 0, we check the first address location if (start_byte_receive != 0) { if (start_byte_receive == 1) { if(bytes == 1) { temp = source_data[0] & 0x00FF00; temp1 = returned_data[0] & 0x00FF00; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; } return; } else if (bytes > 1) { temp = source_data[0] & 0xFFFF00; temp1 = returned_data[0] & 0xFFFF00; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; return; } bytes -= 2; } } if (start_byte_receive == 2) { temp = source_data[0] & 0xFF0000; temp1 = returned_data[0] & 0xFF0000; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; return; } bytes--; } no_words = divide(bytes, 3); rem_bytes = modulus(bytes, 3); for (i=1; i <= no_words; i++){ if(source_data[i] != returned_data[i]){ TEST_FAILED; test_result[j++] = extaddr_lo; return; } } } else { // start_byte_receive = 0 no_words = divide(num_bytes,3); rem_bytes = modulus(num_bytes,3); for (i=0; i<no_words; i++){ if(source_data[i] != returned_data[i]){ TEST_FAILED; test_result[j++] = extaddr_lo; return; } } } if (rem_bytes == 1) { // each mem loc = 3 bytes temp = source_data[i] & 0xFF; temp1 = returned_data[i] & 0xFF; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; } } else if (rem_bytes == 2) { temp = source_data[i] & 0xFFFF; temp1 = returned_data[i] & 0xFFFF; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; } } }
/* Try to do an accelerated tile of the pTile into pRegion of pDrawable. * Based on fbFillRegionTiled(), fbTile(). */ Bool exaFillRegionTiled (DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile, DDXPointPtr pPatOrg, CARD32 planemask, CARD32 alu, unsigned int clientClipType) { ExaScreenPriv(pDrawable->pScreen); PixmapPtr pPixmap; ExaPixmapPrivPtr pExaPixmap; ExaPixmapPrivPtr pTileExaPixmap = ExaGetPixmapPriv(pTile); int xoff, yoff; int tileWidth, tileHeight; int nbox = REGION_NUM_RECTS (pRegion); BoxPtr pBox = REGION_RECTS (pRegion); Bool ret = FALSE; int i; tileWidth = pTile->drawable.width; tileHeight = pTile->drawable.height; /* If we're filling with a solid color, grab it out and go to * FillRegionSolid, saving numerous copies. */ if (tileWidth == 1 && tileHeight == 1) return exaFillRegionSolid(pDrawable, pRegion, exaGetPixmapFirstPixel (pTile), planemask, alu, clientClipType); pPixmap = exaGetDrawablePixmap (pDrawable); pExaPixmap = ExaGetPixmapPriv (pPixmap); if (pExaScr->fallback_counter || pExaPixmap->accel_blocked || pTileExaPixmap->accel_blocked) return FALSE; if (pExaScr->do_migration) { ExaMigrationRec pixmaps[2]; pixmaps[0].as_dst = TRUE; pixmaps[0].as_src = FALSE; pixmaps[0].pPix = pPixmap; pixmaps[0].pReg = exaGCReadsDestination(pDrawable, planemask, FillTiled, alu, clientClipType) ? NULL : pRegion; pixmaps[1].as_dst = FALSE; pixmaps[1].as_src = TRUE; pixmaps[1].pPix = pTile; pixmaps[1].pReg = NULL; exaDoMigration (pixmaps, 2, TRUE); } pPixmap = exaGetOffscreenPixmap (pDrawable, &xoff, &yoff); if (!pPixmap || !exaPixmapIsOffscreen(pTile)) return FALSE; if ((*pExaScr->info->PrepareCopy) (pTile, pPixmap, 1, 1, alu, planemask)) { if (xoff || yoff) REGION_TRANSLATE(pScreen, pRegion, xoff, yoff); for (i = 0; i < nbox; i++) { int height = pBox[i].y2 - pBox[i].y1; int dstY = pBox[i].y1; int tileY; if (alu == GXcopy) height = min(height, tileHeight); modulus(dstY - yoff - pDrawable->y - pPatOrg->y, tileHeight, tileY); while (height > 0) { int width = pBox[i].x2 - pBox[i].x1; int dstX = pBox[i].x1; int tileX; int h = tileHeight - tileY; if (alu == GXcopy) width = min(width, tileWidth); if (h > height) h = height; height -= h; modulus(dstX - xoff - pDrawable->x - pPatOrg->x, tileWidth, tileX); while (width > 0) { int w = tileWidth - tileX; if (w > width) w = width; width -= w; (*pExaScr->info->Copy) (pPixmap, tileX, tileY, dstX, dstY, w, h); dstX += w; tileX = 0; } dstY += h; tileY = 0; } } (*pExaScr->info->DoneCopy) (pPixmap); /* With GXcopy, we only need to do the basic algorithm up to the tile * size; then, we can just keep doubling the destination in each * direction until it fills the box. This way, the number of copy * operations is O(log(rx)) + O(log(ry)) instead of O(rx * ry), where * rx/ry is the ratio between box and tile width/height. This can make * a big difference if each driver copy incurs a significant constant * overhead. */ if (alu != GXcopy) ret = TRUE; else { Bool more_copy = FALSE; for (i = 0; i < nbox; i++) { int dstX = pBox[i].x1 + tileWidth; int dstY = pBox[i].y1 + tileHeight; if ((dstX < pBox[i].x2) || (dstY < pBox[i].y2)) { more_copy = TRUE; break; } } if (more_copy == FALSE) ret = TRUE; if (more_copy && (*pExaScr->info->PrepareCopy) (pPixmap, pPixmap, 1, 1, alu, planemask)) { for (i = 0; i < nbox; i++) { int dstX = pBox[i].x1 + tileWidth; int dstY = pBox[i].y1 + tileHeight; int width = min(pBox[i].x2 - dstX, tileWidth); int height = min(pBox[i].y2 - pBox[i].y1, tileHeight); while (dstX < pBox[i].x2) { (*pExaScr->info->Copy) (pPixmap, pBox[i].x1, pBox[i].y1, dstX, pBox[i].y1, width, height); dstX += width; width = min(pBox[i].x2 - dstX, width * 2); } width = pBox[i].x2 - pBox[i].x1; height = min(pBox[i].y2 - dstY, tileHeight); while (dstY < pBox[i].y2) { (*pExaScr->info->Copy) (pPixmap, pBox[i].x1, pBox[i].y1, pBox[i].x1, dstY, width, height); dstY += height; height = min(pBox[i].y2 - dstY, height * 2); } } (*pExaScr->info->DoneCopy) (pPixmap); ret = TRUE; } } exaMarkSync(pDrawable->pScreen); if (xoff || yoff) REGION_TRANSLATE(pScreen, pRegion, -xoff, -yoff); } return ret; }
void NetChannel::SendReliables()//actually sends to the server { //ok, lets check if we need to resend anything int received_seq = -1; for (int i = 0; i < NumberWindows; i++) { if (window[i].recieved == false && window[i].data) { //if we got an ack for packet after this one and still havent //received ack for this one, we should resend unsigned int minrtt = this->rtt > 100 ? rtt * 2 : 100; if ((received_seq > (int)window[i].sequence && window[i].resends == 0) || (window[i].sendtime + minrtt < NetGetTime())) { this->lastsendtime = NetGetTime(); netlogf("[%s] Resending sequence %d\n", this->server ? "Server" : "Client", window[i].sequence); bool fragmented = false; if (window[i].numfragments > 1) fragmented = true; //resend char d[2056]; NetMsg msg(2056, d); int seq = window[i].sequence;//this->sequence; //todo, handle sequence number overflow//seq &= ~(1<<31);//this is not OOB seq |= 1 << ReliableFlagBit;//this is for if reliable; if (fragmented) seq |= 1 << FragmentFlagBit;//this signifies split packet if (window[i].channel != -1)//sequence channel -1 = unsequenced seq |= 1 << OrderedFlagBit; //dont send this if not reliable msg.WriteInt(seq);//if MSB bit high, then fragmented msg.WriteInt(recieved_sequence); msg.WriteInt(this->GetAckBits());//then write bits with last recieved sequences if (window[i].channel != -1) { msg.WriteByte(window[i].channel); msg.WriteShort(window[i].channel_sequence); } if (fragmented) { msg.WriteShort(window[i].fragment); msg.WriteShort(window[i].numfragments); msg.WriteData(window[i].data + window[i].fragment*NET_FRAGMENT_SIZE, (window[i].size - window[i].fragment*NET_FRAGMENT_SIZE) < NET_FRAGMENT_SIZE ? window[i].size - window[i].fragment*NET_FRAGMENT_SIZE : NET_FRAGMENT_SIZE); } else { //msg.WriteShort(window[i].size); msg.WriteData(window[i].data, window[i].size); } window[i].sendtime = NetGetTime();//+500; window[i].resends += 1; this->unsent_acks = 0; this->connection->Send(this->remoteaddr, msg.data, msg.cursize); } } else if (window[i].recieved == true && window[i].data) { if ((int)window[i].sequence > received_seq) received_seq = window[i].sequence; } } if (this->reliable_sending.empty() == true) return; //why do I do this? //if (this->sequence == 0) // this->sequence = 1; while (this->reliable_sending.empty() == false) { RPacket front = this->reliable_sending.front(); bool fragmented = false; int numfrags = 1; if (front.size > NET_FRAGMENT_SIZE) { numfrags = front.size / NET_FRAGMENT_SIZE + 1; fragmented = true; } int fragment = 0;//fix this, dont subtract from sequence number!! int mw = modulus(this->sequence - 1, NumberWindows); //check if we are in the middle of sending packet if (window[mw].data && window[mw].fragment + 1 != window[mw].numfragments) { //netlog("we were in the middle of sending split packet, try and send more\n"); fragment = window[mw].fragment + 1; } for (; fragment < numfrags; fragment++) { //check if we can slide the window int zw = modulus(this->sequence - (NumberWindows-1), NumberWindows);//(this->sequence - 33) % 33; mw = modulus(this->sequence, NumberWindows); if (window[zw].recieved == true || window[zw].data == 0) { if (window[zw].data && window[zw].fragment + 1 == window[zw].numfragments)//delete old data { delete[] window[zw].data; window[zw].data = 0; } } else if (window[zw].data)//ok, we cant let this break on us { //netlog("[NetCon] Couldn't send packet because sending old one\n"); return;//we havent gotten ack on 31st packet, so cant slide } this->lastsendtime = NetGetTime(); char d[2056]; NetMsg msg(2056, d); int seq = this->sequence; //todo, handle sequence number overflow//seq &= ~(1<<31);//this is not OOB seq |= 1 << ReliableFlagBit;//this is for if reliable; if (fragmented) seq |= 1 << FragmentFlagBit;//this signifies split packet if (front.channel != -1) seq |= 1 << OrderedFlagBit; //dont send this if not reliable msg.WriteInt(seq);//if MSB bit high, then fragmented msg.WriteInt(recieved_sequence); msg.WriteInt(this->GetAckBits());//then write bits with last recieved sequences if (front.channel != -1) { msg.WriteByte(front.channel); msg.WriteShort(this->outgoing_ordered_sequence[front.channel]); } if (fragmented) { msg.WriteShort(fragment); msg.WriteShort(numfrags); } //fill out latest window slot window[mw].recieved = false; window[mw].data = front.data; window[mw].size = front.size; window[mw].sendtime = NetGetTime(); window[mw].sequence = this->sequence; window[mw].resends = 0; window[mw].fragment = fragment; window[mw].numfragments = numfrags; window[mw].channel = front.channel; if (window[mw].channel != -1) window[mw].channel_sequence = this->outgoing_ordered_sequence[window[mw].channel]; if (window[mw].fragment == numfrags - 1 || numfrags == 1) { this->outgoing_ordered_sequence[window[mw].channel]++; } //ok, pack in the data, make sure we dont pack too much while (this->reliable_sending.empty() == false) { RPacket pack = this->reliable_sending.front(); //write size of packet if (fragmented) { msg.WriteData(pack.data + fragment*NET_FRAGMENT_SIZE, (pack.size - fragment*NET_FRAGMENT_SIZE) < NET_FRAGMENT_SIZE ? pack.size - fragment*NET_FRAGMENT_SIZE : NET_FRAGMENT_SIZE); } else { //msg.WriteShort(pack.size); msg.WriteData(pack.data, pack.size); } break;//only send 1 for now } this->unsent_acks = 0; this->connection->Send(this->remoteaddr, msg.data, msg.cursize); if (this->sequence < MaxSequenceNumber) this->sequence++;//increment sequence number else this->sequence = 0; } if (window[modulus(this->sequence - 1, NumberWindows)].fragment + 1 == numfrags) this->reliable_sending.pop();//pop if finished with packet } }//actually does the networking
/** @brief Extract keypoint feature vector * * ----INPUT---- * @param x_key * @param y_key * @param sigma_key * @param theta_key keypoint coordinates. * * @param imX * @param imX precomputed gradient relative to the nearest scale. * * ----PARAM---- * @param lambda_descr (=6) * - The gaussian window has a standard deviation of lambda_descr X=* sigma_key * - The patch P^descr is ( 2 * lambda_descr * sigma_key * (1+1/Nhist) wide * * @param Nhist (=4) number of histograms in each of the two directions, * @param Nbins (=8) number of bins covering the range [0,2pi] * * ----OUTPUT---- * @output descr * * ----RETURN---- * @return count number of sample contributing to the descriptor */ void sift_extract_feature_vector(float x_key, float y_key, float sigma_key, float theta_key, const float* imX, const float* imY, int w, int h, int Nhist, int Nbins, float lambda_descr, float* descr) { // Initialize descr tab for(int i = 0; i < Nhist*Nhist*Nbins; i++){descr[i] = 0.0;} // Contributing pixels are inside a patch [siMin;siMax]X[sjMin;sjMax] of // width 2*lambda_descr*sigma_key*(nhist+1)/nhist float R = (1+1/(float)Nhist)*lambda_descr*sigma_key; float Rp = M_SQRT2*R; int siMin = MAX(0, (int)(x_key - Rp +0.5)); int sjMin = MAX(0, (int)(y_key - Rp +0.5)); int siMax = MIN((int)(x_key + Rp +0.5), h-1); int sjMax = MIN((int)(y_key + Rp +0.5), w-1); /// For each pixel inside the patch. for(int si = siMin; si < siMax; si++){ for(int sj = sjMin; sj < sjMax; sj++){ // Compute pixel coordinates (sX,sY) on keypoint's invariant referential. float X = si - x_key; float Y = sj - y_key; apply_rotation(X, Y, &X, &Y, -theta_key); // Does this sample fall inside the descriptor area ? if (MAX(ABS(X),ABS(Y)) < R) { // Compute the gradient orientation (theta) on keypoint referential. double dx = imX[si*w+sj]; double dy = imY[si*w+sj]; float ori = atan2(dy, dx) - theta_key; ori = modulus(ori, 2*M_PI); // Compute the gradient magnitude and apply a Gaussian weighing to give less emphasis to distant sample double t = lambda_descr*sigma_key; double M = hypot(dx, dy) * exp(-(X*X+Y*Y)/(2*t*t)); // bin indices, Compute the (tri)linear weightings ... float alpha = X/(2*lambda_descr*sigma_key/Nhist) + (Nhist-1.0)/2.0; float beta = Y/(2*lambda_descr*sigma_key/Nhist) + (Nhist-1.0)/2.0; float gamma = ori/(2*M_PI)*Nbins; // ...and add contributions to respective bins in different histograms. // a loop with 1 or two elements int i0 = floor(alpha); int j0 = floor(beta); for(int i = MAX(0,i0);i<=MIN(i0+1,Nhist-1);i++){ for(int j = MAX(0,j0);j<=MIN(j0+1,Nhist-1);j++){ // looping through all surrounding histograms. int k; // Contribution to left bin. k = ((int)gamma+Nbins)%Nbins; descr[i*Nhist*Nbins+j*Nbins+k] += (1.-(gamma-floor(gamma))) *(1.0-ABS((float)i-alpha)) *(1.0-ABS((float)j-beta)) *M; // Contribution to right bin. k = ((int)gamma+1+Nbins)%Nbins; descr[i*Nhist*Nbins+j*Nbins+k] += (1.0-(floor(gamma)+1-gamma)) *(1.0-ABS((float)i-alpha)) *(1.0-ABS((float)j-beta)) *M; } } } } } }
static int process (jack_nframes_t nframes, void *arg) { state *data = arg; if (nframes != data->block_size) return -1; jack_sample_t *input_buffer = jack_port_get_buffer (data->input_port, nframes); jack_sample_t *output_buffer = jack_port_get_buffer (data->output_port, nframes); int buffer_size = data->block_count * nframes; int block_index = data->block_index % data->block_count; memcpy (data->sample_data + buffer_size + block_index * nframes - nframes, input_buffer, nframes * sizeof (jack_sample_t)); if (block_index) memcpy (data->sample_data + block_index * nframes - nframes, input_buffer, nframes * sizeof (jack_sample_t)); int i; for (i = 0; i < buffer_size; i++) data->input_data[i] = data->window_data[i] * data->sample_data[block_index * nframes + i]; fftw_execute (data->fft_object); double maximum = 0; for (i = 0; i < buffer_size / 2 + 1; i++) { data->modulus_data[i] = modulus (data->output_data[i]); if (maximum < data->modulus_data[i]) maximum = data->modulus_data[i]; } for (i = 0; i < nframes; i++) output_buffer[i] = 0; double factor = 1600; /* XXX */ for (i = 0; i < buffer_size / 2 + 1; i++) { if (data->modulus_data[i] > THRESHOLD * maximum) { double amplitude = data->modulus_data[i] / factor; double frequency = 1.0 * i / buffer_size; double phase = data->block_index * nframes; int j; for (j = 0; j < nframes; j++) output_buffer[j] += amplitude * square (frequency * (phase + j)); } } data->block_index++; return 0; }
void NetChannel::ProcessPacket(char* buffer, int recvsize, std::vector<Packet>& container) { NetMsg msg(2048, buffer); int rsequence = msg.ReadInt();//sequence int reliable = rsequence & (1 << ReliableFlagBit); bool shoulduse = this->ProcessHeader(buffer, recvsize); if (shoulduse == false) { netlog("[NetChan] Dropped packet, for any number of reasons!\n"); return; } if (rsequence == -1)//OOB { if (recvsize < 4) return;//bad packet #ifdef NET_VERBOSE_DEBUG netlogf("[%s] Got OOB packet\n", this->server ? "Server" : "Client"); #endif Packet p; p.size = recvsize - 4; p.data = new char[p.size]; memcpy(p.data, &buffer[4], p.size); container.push_back(p); } else if (reliable == false) { #ifdef NET_VERBOSE_DEBUG netlogf("[%s] Decoding Packet %d bytes\n", this->server ? "Server" : "Client", recvsize); #endif int ackbits = msg.ReadInt();//this is ackbits int ptr = 8;//points to size of sub-packet while (ptr < recvsize)//can have multiple packets { unsigned short packetsize = *(unsigned short*)&buffer[ptr]; //packetsize = msg.ReadInt(); if (packetsize & 1 << SplitFlagBit) { packetsize &= ~(1 << SplitFlagBit); //range check if (packetsize + 5 + ptr > recvsize) { netlog("[NetChan] ERROR: Got packetsize that is too large!! Malformed packet!!\n"); break; } NetMsg msg2 = NetMsg(2048, &buffer[ptr + 2]); unsigned char sequence = msg2.ReadByte(); unsigned char frag = msg2.ReadByte(); unsigned char numfrags = msg2.ReadByte(); #ifdef NET_VERBOSE_DEBUG netlogf(" Got unreliable split packet %d of %d\n", frag + 1, numfrags); #endif if (sequence == this->unreliable_fragment.sequence) { if (frag == this->unreliable_fragment.frags_recieved)//it is next packet in set { this->unreliable_fragment.frags_recieved++; //msg.ReadData(&this->unreliable_fragment.data[this->unreliable_fragment.curpos], packetsize); memcpy(&this->unreliable_fragment.data[this->unreliable_fragment.curpos], &buffer[ptr + 5], packetsize); this->unreliable_fragment.curpos += packetsize; } } else//make sure its newer { if (this->unreliable_fragment.data) delete[] this->unreliable_fragment.data; this->unreliable_fragment.data = new char[numfrags*NET_FRAGMENT_SIZE]; this->unreliable_fragment.sequence = sequence; this->unreliable_fragment.frags_recieved = 1; this->unreliable_fragment.curpos = packetsize; //msg.ReadData(this->unreliable_fragment.data, packetsize); memcpy(this->unreliable_fragment.data, &buffer[ptr + 5], packetsize); } ptr += 5 + packetsize; if (frag + 1 == numfrags) { //we should be done if (this->unreliable_fragment.frags_recieved == numfrags) { #ifdef NET_VERBOSE_DEBUG netlog(" Was final packet in split unreliable set.\n"); #endif //return this->unreliable_fragment.data; Packet p; p.reliable = false; p.size = this->unreliable_fragment.curpos; p.data = this->unreliable_fragment.data; this->unreliable_fragment.data = 0; container.push_back(p); } } } else { //range check if (packetsize + 2 + ptr > recvsize) { netlog("[NetChan] ERROR: Got packetsize that is too large!! Malformed packet!!\n"); break; } #ifdef NET_VERBOSE_DEBUG netlogf(" Got packet of %d bytes at %d\n", packetsize, ptr); #endif Packet p; p.reliable = false; p.size = packetsize; //msg.cursize += packetsize; p.data = new char[p.size]; memcpy(p.data, &buffer[ptr + 2], p.size); container.push_back(p); ptr += 2 + packetsize; } } } else//safe { //check if the packet is complete if fragmented rsequence &= ~(1 << ReliableFlagBit); if (rsequence & (1 << FragmentFlagBit)) { rsequence &= ~(1 << FragmentFlagBit);//remove the bit //check if we have whole packet, if not continue if (rsequence & 1 << OrderedFlagBit) { if (recvsize < 19) return;//bad packet rsequence &= ~(1 << OrderedFlagBit); unsigned char chan = *(unsigned char*)&buffer[12]; unsigned short seq = *(unsigned short*)&buffer[13]; int frag = *(unsigned short*)&buffer[15]; int numfrags = *(unsigned short*)&buffer[17]; if (frag + 1 > numfrags) { netlog("[NetChan] ERROR: Fragment number over maximum number of fragments for set!\n"); return; } else if (numfrags > NET_MAX_FRAGMENTS) { netlog("[NetChan] ERROR: Fragmented packet too large, over NET_MAX_FRAGMENTS!\n"); return; } #ifdef NET_VERBOSE_DEBUG netlogf("[Client] Got ordered reliable split packet %d of %d\n", frag + 1, numfrags); #endif //we need to copy data into a buffer int startseq = rsequence - frag; int frag_index = modulus(startseq, NumberReliableFragments); if (reliable_frags[frag_index].sequence == startseq) { reliable_frags[frag_index].frags_recieved += 1; } else { //delete the old one //if (reliable_frags[startseq%20].data) //delete[] reliable_frags[startseq%20].data; //first packet we got in the set reliable_frags[frag_index].num_frags = numfrags; reliable_frags[frag_index].frags_recieved = 1; reliable_frags[frag_index].data = new char[NET_FRAGMENT_SIZE*numfrags]; reliable_frags[frag_index].sequence = startseq; reliable_frags[frag_index].curpos = 0; } //ok, copy in the data memcpy(reliable_frags[frag_index].data + frag*NET_FRAGMENT_SIZE, &buffer[16 + 3], recvsize - 19); reliable_frags[frag_index].curpos += recvsize - 19; if (reliable_frags[frag_index].frags_recieved == numfrags) { #ifdef NET_VERBOSE_DEBUG netlog("[Client] We got the whole split reliable packet\n"); #endif Packet p; p.reliable = true; p.size = reliable_frags[frag_index].curpos;//frags_recieved*(FRAGMENT_SIZE-1) + (recvsize - 16);//reliable_frags[startseq%20].frags_recieved*FRAGMENT_SIZE;//approximate p.data = reliable_frags[frag_index].data; reliable_frags[frag_index].data = 0; if (this->incoming_ordered_sequence[chan] + 1 == seq) { this->incoming_ordered_sequence[chan]++; #ifdef NET_VERBOSE_DEBUG netlogf("Pushed ordered pack %d\n", incoming_ordered_sequence[chan]); #endif container.push_back(p); //check map to see if next packet is availible while (this->ordered_buffer[chan].find(this->incoming_ordered_sequence[chan] + 1) != this->ordered_buffer[chan].end()) { container.push_back(this->ordered_buffer[chan][this->incoming_ordered_sequence[chan] + 1]); this->ordered_buffer[chan].erase(this->ordered_buffer[chan].find(this->incoming_ordered_sequence[chan] + 1)); this->incoming_ordered_sequence[chan]++; #ifdef NET_VERBOSE_DEBUG netlogf("Pushed ordered pack %d\n", incoming_ordered_sequence[chan]); #endif } } else { //hold it for a while until we get packets before it this->ordered_buffer[chan][seq] = p; } } } else { if (recvsize < 16) return;//bad packet int frag = *(unsigned short*)&buffer[12]; int numfrags = *(unsigned short*)&buffer[14]; #ifdef NET_VERBOSE_DEBUG netlogf("[Client] Got reliable split packet %d of %d\n", frag + 1, numfrags); #endif //we need to copy data into a buffer int startseq = rsequence - frag; int frag_index = modulus(startseq, NumberReliableFragments); if (reliable_frags[frag_index].sequence == startseq) { reliable_frags[frag_index].frags_recieved += 1; } else { //delete the old one //if (reliable_frags[startseq%20].data) //delete[] reliable_frags[startseq%20].data; //first packet we got in the set reliable_frags[frag_index].frags_recieved = 1; reliable_frags[frag_index].data = new char[NET_FRAGMENT_SIZE*numfrags]; reliable_frags[frag_index].sequence = startseq; reliable_frags[frag_index].curpos = 0; } //ok, copy in the data memcpy(reliable_frags[frag_index].data + frag*NET_FRAGMENT_SIZE, &buffer[16], recvsize - 16); reliable_frags[frag_index].curpos += recvsize - 16; if (reliable_frags[frag_index].frags_recieved == numfrags) { #ifdef NET_VERBOSE_DEBUG netlog("[Client] We got the whole split reliable packet\n"); #endif Packet p; p.reliable = true; p.size = reliable_frags[frag_index].curpos;//frags_recieved*(FRAGMENT_SIZE-1) + (recvsize - 16);//reliable_frags[startseq%20].frags_recieved*FRAGMENT_SIZE;//approximate p.data = reliable_frags[frag_index].data; reliable_frags[frag_index].data = 0; container.push_back(p); } } } else//safe { if (rsequence & 1 << OrderedFlagBit) { if (recvsize < 15) return;//bad packet #ifdef NET_VERBOSE_DEBUG netlog("[NetChan] Got Ordered Reliable Packet\n"); #endif //size at 15 //chan at 12 //seq at 13 unsigned short seq = *(unsigned short*)&buffer[13]; unsigned char chan = *(unsigned char*)&buffer[12]; Packet p; p.reliable = true; p.size = recvsize - (14 + 1); //lets make copy p.data = new char[p.size]; memcpy(p.data, &buffer[14 + 1], p.size); if (this->incoming_ordered_sequence[chan] + 1 == seq) { this->incoming_ordered_sequence[chan]++; #ifdef NET_VERBOSE_DEBUG netlogf("Pushed ordered pack %d\n", incoming_ordered_sequence[chan]); #endif container.push_back(p); //check map to see if next packet is availible while (this->ordered_buffer[chan].find(this->incoming_ordered_sequence[chan] + 1) != this->ordered_buffer[chan].end()) { container.push_back(this->ordered_buffer[chan][this->incoming_ordered_sequence[chan] + 1]); this->ordered_buffer[chan].erase(this->ordered_buffer[chan].find(this->incoming_ordered_sequence[chan] + 1)); this->incoming_ordered_sequence[chan]++; #ifdef NET_VERBOSE_DEBUG netlogf("Pushed ordered pack %d\n", incoming_ordered_sequence[chan]); #endif } } else { #ifdef NET_VERBOSE_DEBUG netlogf("Got ordered pack %d\n", seq); #endif //hold it for a while until we get packets before it this->ordered_buffer[chan][seq] = p; } } else { if (recvsize < 12) return;//bad packet #ifdef NET_VERBOSE_DEBUG netlog("[Client] Got Reliable packet\n"); #endif //not split packet, or ordered Packet p; p.reliable = true; p.size = recvsize - 12; p.data = new char[p.size]; memcpy(p.data, &buffer[12], p.size); container.push_back(p); } } } };
/* Try to do an accelerated tile of the pTile into pRegion of pDrawable. * Based on fbFillRegionTiled(), fbTile(). */ Bool uxa_fill_region_tiled(DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile, DDXPointPtr pPatOrg, CARD32 planemask, CARD32 alu) { uxa_screen_t *uxa_screen = uxa_get_screen(pDrawable->pScreen); PixmapPtr pPixmap; int xoff, yoff; int tileWidth, tileHeight; int nbox = REGION_NUM_RECTS(pRegion); BoxPtr pBox = REGION_RECTS(pRegion); Bool ret = FALSE; tileWidth = pTile->drawable.width; tileHeight = pTile->drawable.height; /* If we're filling with a solid color, grab it out and go to * FillRegionsolid, saving numerous copies. */ if (tileWidth == 1 && tileHeight == 1) return uxa_fill_region_solid(pDrawable, pRegion, uxa_get_pixmap_first_pixel(pTile), planemask, alu); pPixmap = uxa_get_offscreen_pixmap(pDrawable, &xoff, &yoff); if (!pPixmap || !uxa_pixmap_is_offscreen(pTile)) goto out; if (uxa_screen->info->check_copy && !uxa_screen->info->check_copy(pTile, pPixmap, alu, planemask)) return FALSE; REGION_TRANSLATE(pScreen, pRegion, xoff, yoff); if ((*uxa_screen->info->prepare_copy) (pTile, pPixmap, 1, 1, alu, planemask)) { while (nbox--) { int height = pBox->y2 - pBox->y1; int dstY = pBox->y1; int tileY; modulus(dstY - yoff - pDrawable->y - pPatOrg->y, tileHeight, tileY); while (height > 0) { int width = pBox->x2 - pBox->x1; int dstX = pBox->x1; int tileX; int h = tileHeight - tileY; if (h > height) h = height; height -= h; modulus(dstX - xoff - pDrawable->x - pPatOrg->x, tileWidth, tileX); while (width > 0) { int w = tileWidth - tileX; if (w > width) w = width; width -= w; (*uxa_screen->info->copy) (pPixmap, tileX, tileY, dstX, dstY, w, h); dstX += w; tileX = 0; } dstY += h; tileY = 0; } pBox++; } (*uxa_screen->info->done_copy) (pPixmap); ret = TRUE; } out: REGION_TRANSLATE(pScreen, pRegion, -xoff, -yoff); return ret; }
void BenchMarkAll(double t) { logtotal = 0; logcount = 0; cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl; cout << "<THEAD><TR><TH>Algorithm<TH>Bytes Processed<TH>Time Taken<TH>Megabytes(2^20 bytes)/Second\n<TBODY>" << endl; BenchMarkKeyless<CRC32>("CRC-32", t); BenchMarkKeyless<Adler32>("Adler-32", t); BenchMarkKeyless<MD2>("MD2", t); BenchMarkKeyless<MD5>("MD5", t); BenchMarkKeyless<SHA>("SHA-1", t); BenchMarkKeyless<SHA256>("SHA-256", t); BenchMarkKeyless<SHA512>("SHA-512", t); BenchMarkKeyless<HAVAL3>("HAVAL (pass=3)", t); BenchMarkKeyless<HAVAL4>("HAVAL (pass=4)", t); BenchMarkKeyless<HAVAL5>("HAVAL (pass=5)", t); #ifdef WORD64_AVAILABLE BenchMarkKeyless<Tiger>("Tiger", t); #endif BenchMarkKeyless<RIPEMD160>("RIPE-MD160", t); BenchMarkKeyless<PanamaHash<false> >("Panama Hash (little endian)", t); BenchMarkKeyless<PanamaHash<true> >("Panama Hash (big endian)", t); BenchMarkKeyed<MDC<MD5> >("MDC/MD5", t); BenchMarkKeyed<LREncryption<MD5> >("Luby-Rackoff/MD5", t); BenchMarkKeyed<DESEncryption>("DES", t); BenchMarkKeyed<DES_XEX3_Encryption>("DES-XEX3", t); BenchMarkKeyed<DES_EDE3_Encryption>("DES-EDE3", t); BenchMarkKeyed<IDEAEncryption>("IDEA", t); BenchMarkKeyed<RC2Encryption>("RC2", t); BenchMarkKeyed<RC5Encryption>("RC5 (r=16)", t); BenchMarkKeyed<BlowfishEncryption>("Blowfish", t); BenchMarkKeyed<Diamond2Encryption>("Diamond2", t); BenchMarkKeyed<Diamond2LiteEncryption>("Diamond2 Lite", t); BenchMarkKeyed<ThreeWayDecryption>("3-WAY", t); BenchMarkKeyed<TEAEncryption>("TEA", t); BenchMarkKeyed<SAFER_SK64_Encryption>("SAFER (r=8)", t); BenchMarkKeyed<GOSTEncryption>("GOST", t); #ifdef WORD64_AVAILABLE BenchMarkKeyed<SHARKEncryption>("SHARK (r=6)", t); #endif BenchMarkKeyed<CAST128Encryption>("CAST-128", t); BenchMarkKeyed<CAST256Encryption>("CAST-256", t); BenchMarkKeyed<SquareEncryption>("Square", t); BenchMarkKeyed<SKIPJACKEncryption>("SKIPJACK", t); BenchMarkKeyed<RC6Encryption>("RC6", t); BenchMarkKeyed<MARSEncryption>("MARS", t); BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (128-bit key)", t, 16); BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (192-bit key)", t, 24); BenchMarkKeyedVariable<RijndaelEncryption>("Rijndael (256-bit key)", t, 32); BenchMarkKeyed<TwofishEncryption>("Twofish", t); BenchMarkKeyed<SerpentEncryption>("Serpent", t); BenchMarkKeyed<ARC4>("ARC4", t); BenchMarkKeyed<SEAL>("SEAL", t); { WAKEEncryption c(key, new BitBucket); BenchMark("WAKE", c, t); } BenchMarkKeyed<PanamaCipher<false> >("Panama Cipher (little endian)", t); BenchMarkKeyed<PanamaCipher<true> >("Panama Cipher (big endian)", t); BenchMarkKeyed<SapphireEncryption>("Sapphire", t); BenchMarkKeyed<MD5MAC>("MD5-MAC", t); BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t); BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t); BenchMarkKeyed<CBC_MAC<RijndaelEncryption> >("CBC-MAC/Rijndael", t); BenchMarkKeyed<DMAC<RijndaelEncryption> >("DMAC/Rijndael", t); { Integer p("CB6C,B8CE,6351,164F,5D0C,0C9E,9E31,E231,CF4E,D551,CBD0,E671,5D6A,7B06,D8DF,C4A7h"); Integer q("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,A2AFh"); Integer s("63239752671357255800299643604761065219897634268887145610573595874544114193025997412441121667211431"); BlumBlumShub c(p, q, s); BenchMark("BlumBlumShub 512", c, t); } { Integer p("FD2A,8594,A132,20CC,4E6D,DE77,3AAA,CF15,CD9E,E447,8592,FF46,CC77,87BE,9876,9E2C," "8572,64C3,4CF4,188A,44D4,2130,1135,7982,6FF6,EDD3,26F0,5FAA,BAF4,A81E,7ADC,B80Bh"); Integer q("C8B9,5797,B349,6BA3,FD72,F2C0,A796,8A65,EE0F,B4BA,272F,4FEE,4DB1,06D5,ECEB,7142," "E8A8,E5A8,6BF9,A32F,BA37,BACC,8A75,8A6B,2DCE,D6EC,B515,980A,4BB1,08FB,6F2C,2383h"); Integer s("3578,8F00,2965,71A4,4382,699F,45FD,3922,8238,241B,CEBA,0543,3443,E8D9,12FB,AC46," "7EC4,8505,EC9E,7EE8,5A23,9B2A,B615,D0C4,9448,F23A,ADEE,E850,1A7A,CA30,0B5B,A408," "D936,21BA,844E,BDD6,7848,3D1E,9137,CC87,DAA5,773B,D45A,C8BB,5392,1393,108B,6992," "74E3,C5E2,C235,A321,0111,3BA4,BAB4,1A2F,17EE,C371,DE67,01C9,0F3D,907A,B252,9BDDh"); BlumBlumShub c(p, q, s); BenchMark("BlumBlumShub 1024", c, t); } { Integer p("EB56,978A,7BA7,B5D9,1383,4611,94F5,4766,FCEF,CF41,958A,FC41,43D0,839F,C56B,B568," "4ED3,9E5A,BABB,5ACE,8B11,CEBC,88A2,7C12,FFEE,E6E8,CF0A,E231,5BC2,DEDE,80B7,32F6," "340E,D8A6,B7DE,C779,7EE5,0E16,9C88,FC9F,2A0E,EE6C,7D47,C5F2,6B06,EB8C,F1C8,2E67," "5B82,8C28,4FB8,542F,2874,C355,CEEE,7A54,1B06,A8AB,8B66,6A5C,9DB2,72B8,74F3,7BC7h"); Integer q("EB6B,3645,4591,8343,7331,7CAC,B02E,4BB9,DEF5,8EDC,1772,DB9B,9571,5FAB,1CDD,4FB1," "7B9A,07CD,E715,D448,F552,CBBD,D387,C037,DE70,6661,F360,D0E8,D42E,292A,9321,DDCB," "0BF9,C514,BFAC,3F2C,C06E,DF64,A9B8,50D6,AC4F,B9E4,014B,5624,2B40,A0D4,5D0B,6DD4," "0989,D00E,0268,99AB,21DB,0BB4,DB38,84DA,594F,575F,95AC,1B70,45E4,96C8,C6AD,CE67h"); Integer s("C75A,8A0D,E231,295F,C08A,1716,8611,D5EC,E9EF,B565,90EC,58C0,57D0,DA7D,C6E6,DB00," "2282,1CA7,EA31,D64E,768C,0B19,8563,36DF,2226,F4EC,74A4,2844,2E8D,37E8,53DC,0172," "5F56,8CF9,B444,CA02,78B3,17AF,7C78,D320,16AE,AC3D,B97F,7259,1B8F,9C84,6A16,B878," "0595,70BB,9C52,18B5,9100,9C1F,E85A,4035,06F3,5F38,7462,F01D,0462,BFBC,A4CD,4A45," "3A77,E7F8,DED1,D6EF,CEF7,0937,CD3F,3AF1,4F88,932D,6D4B,002C,3735,304C,C5D3,B88A," "B57B,24B6,5346,9B46,5153,B7ED,B216,C181,B1C6,C52E,CD2B,E0AA,B1BB,0A93,C92E,4F79," "4931,E303,7C8F,A408,8ACF,56CD,6EC0,76A2,5015,6BA4,4C50,C44D,53B9,E168,5F84,B381," "2514,10B2,00E5,B4D1,4156,A2FE,0BF6,6F33,0A1B,91C6,31B8,1C90,02F1,FB1F,C494,8B65h"); BlumBlumShub c(p, q, s); BenchMark("BlumBlumShub 2048", c, t); } cout << "</TABLE>" << endl; cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl; cout << "<THEAD><TR><TH>Operation<TH>Iterations<TH>Total Time<TH>Milliseconds/Operation" << endl; cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa512.dat", "RSA 512", t); BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi512.dat", "Rabin 512", t); BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum512.dat", "BlumGoldwasser 512", t); BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc512.dat", "LUC 512", t); BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc512.dat", "ElGamal 512", t); cout << "<TBODY style=\"background: white\">" << endl; BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa1024.dat", "RSA 1024", t); BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi1024.dat", "Rabin 1024", t); BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum1024.dat", "BlumGoldwasser 1024", t); BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc1024.dat", "LUC 1024", t); BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc1024.dat", "ElGamal 1024", t); BenchMarkCrypto<LUCELG_Decryptor, LUCELG_Encryptor>("lucc512.dat", "LUCELG 512", t); cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkCrypto<RSAES_OAEP_SHA_Decryptor, RSAES_OAEP_SHA_Encryptor>("rsa2048.dat", "RSA 2048", t); BenchMarkCrypto<RabinDecryptor, RabinEncryptor>("rabi2048.dat", "Rabin 2048", t); BenchMarkCrypto<BlumGoldwasserPrivateKey, BlumGoldwasserPublicKey>("blum2048.dat", "BlumGoldwasser 2048", t); BenchMarkCrypto<LUCES_OAEP_SHA_Decryptor, LUCES_OAEP_SHA_Encryptor>("luc2048.dat", "LUC 2048", t); BenchMarkCrypto<ElGamalDecryptor, ElGamalEncryptor>("elgc2048.dat", "ElGamal 2048", t); BenchMarkCrypto<LUCELG_Decryptor, LUCELG_Encryptor>("lucc1024.dat", "LUCELG 1024", t); cout << "<TBODY style=\"background: white\">" << endl; BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa512.dat", "RSA 512", t); BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi512.dat", "Rabin 512", t); BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw512.dat", "RW 512", t); BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc512.dat", "LUC 512", t); BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr512.dat", "NR 512", t); BenchMarkSignature<DSAPrivateKey, DSAPublicKey>("dsa512.dat", "DSA 512", t); cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa1024.dat", "RSA 1024", t); BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi1024.dat", "Rabin 1024", t); BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw1024.dat", "RW 1024", t); BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc1024.dat", "LUC 1024", t); BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr1024.dat", "NR 1024", t); BenchMarkSignature<DSAPrivateKey, DSAPublicKey>("dsa1024.dat", "DSA 1024", t); BenchMarkSignature<LUCELG_Signer<SHA>, LUCELG_Verifier<SHA> >("lucs512.dat", "LUCELG 512", t); cout << "<TBODY style=\"background: white\">" << endl; BenchMarkSignature<RSASSA_PKCS1v15_SHA_Signer, RSASSA_PKCS1v15_SHA_Verifier>("rsa2048.dat", "RSA 2048", t); BenchMarkSignature<RabinSignerWith(SHA), RabinVerifierWith(SHA) >("rabi2048.dat", "Rabin 2048", t); BenchMarkSignature<RWSigner<SHA>, RWVerifier<SHA> >("rw2048.dat", "RW 2048", t); BenchMarkSignature<LUCSSA_PKCS1v15_SHA_Signer, LUCSSA_PKCS1v15_SHA_Verifier>("luc2048.dat", "LUC 2048", t); BenchMarkSignature<NRSigner<SHA>, NRVerifier<SHA> >("nr2048.dat", "NR 2048", t); BenchMarkSignature<LUCELG_Signer<SHA>, LUCELG_Verifier<SHA> >("lucs1024.dat", "LUCELG 1024", t); cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkKeyAgreement<XTR_DH>("xtrdh171.dat", "XTR-DH 171", t); BenchMarkKeyAgreement<XTR_DH>("xtrdh342.dat", "XTR-DH 342", t); BenchMarkKeyAgreement<DH>("dh512.dat", "DH 512", t); BenchMarkKeyAgreement<DH>("dh1024.dat", "DH 1024", t); BenchMarkKeyAgreement<DH>("dh2048.dat", "DH 2048", t); BenchMarkKeyAgreement<LUCDIF>("lucd512.dat", "LUCDIF 512", t); BenchMarkKeyAgreement<LUCDIF>("lucd1024.dat", "LUCDIF 1024", t); BenchMarkKeyAgreement<MQV>("mqv512.dat", "MQV 512", t); BenchMarkKeyAgreement<MQV>("mqv1024.dat", "MQV 1024", t); BenchMarkKeyAgreement<MQV>("mqv2048.dat", "MQV 2048", t); cout << "<TBODY style=\"background: white\">" << endl; { Integer modulus("199999999999999999999999980586675243082581144187569"); Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h"); Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah"); Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h"); Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach"); Integer r("100000000000000000000000000000000000000000000000151"); Integer k(2); Integer d("76572944925670636209790912427415155085360939712345"); ECP ec(modulus, a, b); ECP::Point P(x, y); P = ec.Multiply(k, P); ECP::Point Q(ec.Multiply(d, P)); ECDecryptor<ECP> cpriv(ec, P, r, Q, d); ECEncryptor<ECP> cpub(cpriv); ECSigner<ECP, SHA> spriv(cpriv); ECVerifier<ECP, SHA> spub(spriv); ECDHC<ECP> ecdhc(ec, P, r, k); ECMQVC<ECP> ecmqvc(ec, P, r, k); BenchMarkEncryption("ECIES over GF(p) 168", cpub, t); BenchMarkDecryption("ECIES over GF(p) 168", cpriv, cpub, t); BenchMarkSigning("ECNR over GF(p) 168", spriv, t); BenchMarkVerification("ECNR over GF(p) 168", spriv, spub, t); BenchMarkKeyGen("ECDHC over GF(p) 168", ecdhc, t); BenchMarkAgreement("ECDHC over GF(p) 168", ecdhc, t); BenchMarkKeyGen("ECMQVC over GF(p) 168", ecmqvc, t); BenchMarkAgreement("ECMQVC over GF(p) 168", ecmqvc, t); } cout << "<TBODY style=\"background: yellow\">" << endl; { Integer r("3805993847215893016155463826195386266397436443"); Integer k(12); Integer d("2065729449256706362097909124274151550853609397"); GF2NT gf2n(155, 62, 0); byte b[]={0x7, 0x33, 0x8f}; EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3)); EC2N::Point P(0x7B, 0x1C8); P = ec.Multiply(k, P); EC2N::Point Q(ec.Multiply(d, P)); ECDecryptor<EC2N> cpriv(ec, P, r, Q, d); ECEncryptor<EC2N> cpub(cpriv); ECSigner<EC2N, SHA> spriv(cpriv); ECVerifier<EC2N, SHA> spub(spriv); ECDHC<EC2N> ecdhc(ec, P, r, k); ECMQVC<EC2N> ecmqvc(ec, P, r, k); BenchMarkEncryption("ECIES over GF(2^n) 155", cpub, t); BenchMarkDecryption("ECIES over GF(2^n) 155", cpriv, cpub, t); BenchMarkSigning("ECNR over GF(2^n) 155", spriv, t); BenchMarkVerification("ECNR over GF(2^n) 155", spriv, spub, t); BenchMarkKeyGen("ECDHC over GF(2^n) 155", ecdhc, t); BenchMarkAgreement("ECDHC over GF(2^n) 155", ecdhc, t); BenchMarkKeyGen("ECMQVC over GF(2^n) 155", ecmqvc, t); BenchMarkAgreement("ECMQVC over GF(2^n) 155", ecmqvc, t); } cout << "</TABLE>" << endl; cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/logcount) << endl; }
void costmap_cb(const nav_msgs::GridCells::ConstPtr& msg) { ODOM_FRAME = msg->header.frame_id; geometry_msgs::PoseArray ff_msg; ff_msg.header.stamp = msg->header.stamp; ff_msg.header.frame_id = ODOM_FRAME; last_fv = msg->header.stamp; force_vector[0] = force_vector[1] = 0; std::vector<geometry_msgs::Point> points = msg->cells; std::vector<geometry_msgs::Pose> poses; int count = 0; float total_weight = 0.0; for (std::vector<std::string>::size_type i = 0; i < points.size(); i++) { geometry_msgs::PointStamped point, point_trans; point.header.stamp = msg->header.stamp; point.header.frame_id = ODOM_FRAME; point.point.x = points[i].x; point.point.y = points[i].y; tf_listener->waitForTransform(BASE_FRAME, ODOM_FRAME, point.header.stamp, ros::Duration(0.1)); try { tf_listener->transformPoint(BASE_FRAME, point, point_trans); } catch (tf::ExtrapolationException e) { ROS_ERROR("Unable to get tf transform: %s", e.what()); return; } float x = point_trans.point.x; float y = point_trans.point.y; float yaw = atan(y / x); if (x > 0) yaw = modulus(yaw + PI, 2*PI); std::vector<float> point_vector = point_to_vector(x, y); if (point_vector.size() > 0) { count++; //float weight = 0.75*(MAX_RANGE - BASE_RADIUS - CLEARING_DIST)/(sqrt(pow(x, 2) + pow(y, 2)) - BASE_RADIUS - CLEARING_DIST); //if ( weight < 0 ) // std::cout << "evil" << std::endl; //length += weight; //float weight = (PI - abs(yaw)) / PI; force_vector[0] += point_vector[0]; force_vector[1] += point_vector[1]; geometry_msgs::PoseStamped pose, pose_trans; pose.header.stamp = msg->header.stamp; pose.header.frame_id = BASE_FRAME; pose.pose.position.x = x; pose.pose.position.y = y; pose.pose.orientation = tf::createQuaternionMsgFromYaw(yaw); tf_listener->waitForTransform(ODOM_FRAME, BASE_FRAME, pose.header.stamp, ros::Duration(0.1)); try { tf_listener->transformPose(ODOM_FRAME, pose, pose_trans); } catch (tf::ExtrapolationException e) { ROS_ERROR("Unable to get tf transform: %s", e.what()); return; } poses.push_back(pose_trans.pose); } } //force_vector[0] /= length + 1; //force_vector[1] /= length + 1; std::cout << force_vector[0] << "," << force_vector[1] << std::endl; // publish resulting force vector as Pose geometry_msgs::PoseStamped force, force_trans; force.header.stamp = msg->header.stamp; force.header.frame_id = BASE_FRAME; float force_yaw = atan(force_vector[1] / force_vector[0]); if (force_vector[0] > 0) force_yaw = modulus(force_yaw + PI, 2*PI); force.pose.orientation = tf::createQuaternionMsgFromYaw(force_yaw); tf_listener->waitForTransform(BASE_FRAME, ODOM_FRAME, msg->header.stamp, ros::Duration(0.1)); try { tf_listener->transformPose(ODOM_FRAME, force, force_trans); } catch (tf::ExtrapolationException e) { ROS_ERROR("Unable to get tf transform: %s", e.what()); return; } force_obst_pub.publish(force_trans); // publish force field as PoseArray ff_msg.poses = poses; force_field_pub.publish(ff_msg); }
Vector3 Vector3::normalize() const { double mod = modulus(); if (mod == 0.0) return Vector3(*this); return Vector3(x / mod, y / mod, z / mod); }
void BenchmarkAll2(double t) { cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right>" << endl; cout << "<THEAD><TR><TH>Operation<TH>Iterations<TH>Total Time<TH>Milliseconds/Operation" << endl; cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkCrypto<RSAES<OAEP<SHA> > >("rsa1024.dat", "RSA 1024", t); BenchMarkCrypto<RabinES<OAEP<SHA> > >("rabi1024.dat", "Rabin 1024", t); BenchMarkCrypto<LUCES<OAEP<SHA> > >("luc1024.dat", "LUC 1024", t); BenchMarkCrypto<DLIES<> >("dlie1024.dat", "DLIES 1024", t); BenchMarkCrypto<LUC_IES<> >("lucc512.dat", "LUCELG 512", t); cout << "<TBODY style=\"background: white\">" << endl; BenchMarkCrypto<RSAES<OAEP<SHA> > >("rsa2048.dat", "RSA 2048", t); BenchMarkCrypto<RabinES<OAEP<SHA> > >("rabi2048.dat", "Rabin 2048", t); BenchMarkCrypto<LUCES<OAEP<SHA> > >("luc2048.dat", "LUC 2048", t); BenchMarkCrypto<DLIES<> >("dlie2048.dat", "DLIES 2048", t); BenchMarkCrypto<LUC_IES<> >("lucc1024.dat", "LUCELG 1024", t); cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkSignature<RSASS<PSSR, SHA> >("rsa1024.dat", "RSA 1024", t); BenchMarkSignature<RabinSS<PSSR, SHA> >("rabi1024.dat", "Rabin 1024", t); BenchMarkSignature<RWSS<PSSR, SHA> >("rw1024.dat", "RW 1024", t); BenchMarkSignature<LUCSS<PSSR, SHA> >("luc1024.dat", "LUC 1024", t); BenchMarkSignature<NR<SHA> >("nr1024.dat", "NR 1024", t); BenchMarkSignature<DSA>("dsa1024.dat", "DSA 1024", t); BenchMarkSignature<LUC_HMP<SHA> >("lucs512.dat", "LUC-HMP 512", t); BenchMarkSignature<ESIGN<SHA> >("esig1023.dat", "ESIGN 1023", t); BenchMarkSignature<ESIGN<SHA> >("esig1536.dat", "ESIGN 1536", t); cout << "<TBODY style=\"background: white\">" << endl; BenchMarkSignature<RSASS<PSSR, SHA> >("rsa2048.dat", "RSA 2048", t); BenchMarkSignature<RabinSS<PSSR, SHA> >("rabi2048.dat", "Rabin 2048", t); BenchMarkSignature<RWSS<PSSR, SHA> >("rw2048.dat", "RW 2048", t); BenchMarkSignature<LUCSS<PSSR, SHA> >("luc2048.dat", "LUC 2048", t); BenchMarkSignature<NR<SHA> >("nr2048.dat", "NR 2048", t); BenchMarkSignature<LUC_HMP<SHA> >("lucs1024.dat", "LUC-HMP 1024", t); BenchMarkSignature<ESIGN<SHA> >("esig2046.dat", "ESIGN 2046", t); cout << "<TBODY style=\"background: yellow\">" << endl; BenchMarkKeyAgreement<XTR_DH>("xtrdh171.dat", "XTR-DH 171", t); BenchMarkKeyAgreement<XTR_DH>("xtrdh342.dat", "XTR-DH 342", t); BenchMarkKeyAgreement<DH>("dh1024.dat", "DH 1024", t); BenchMarkKeyAgreement<DH>("dh2048.dat", "DH 2048", t); BenchMarkKeyAgreement<LUC_DH>("lucd512.dat", "LUCDIF 512", t); BenchMarkKeyAgreement<LUC_DH>("lucd1024.dat", "LUCDIF 1024", t); BenchMarkKeyAgreement<MQV>("mqv1024.dat", "MQV 1024", t); BenchMarkKeyAgreement<MQV>("mqv2048.dat", "MQV 2048", t); cout << "<TBODY style=\"background: white\">" << endl; { Integer modulus("199999999999999999999999980586675243082581144187569"); Integer a("659942,b7261b,249174,c86bd5,e2a65b,45fe07,37d110h"); Integer b("3ece7d,09473d,666000,5baef5,d4e00e,30159d,2df49ah"); Integer x("25dd61,4c0667,81abc0,fe6c84,fefaa3,858ca6,96d0e8h"); Integer y("4e2477,05aab0,b3497f,d62b5e,78a531,446729,6c3fach"); Integer r("100000000000000000000000000000000000000000000000151"); Integer k(2); Integer d("76572944925670636209790912427415155085360939712345"); ECP ec(modulus, a, b); ECP::Point P(x, y); P = ec.Multiply(k, P); ECP::Point Q(ec.Multiply(d, P)); ECIES<ECP>::Decryptor cpriv(ec, P, r, d); ECIES<ECP>::Encryptor cpub(cpriv); ECDSA<ECP, SHA>::Signer spriv(cpriv); ECDSA<ECP, SHA>::Verifier spub(spriv); ECDH<ECP>::Domain ecdhc(ec, P, r, k); ECMQV<ECP>::Domain ecmqvc(ec, P, r, k); BenchMarkEncryption("ECIES over GF(p) 168", cpub, t); BenchMarkDecryption("ECIES over GF(p) 168", cpriv, cpub, t); BenchMarkSigning("ECNR over GF(p) 168", spriv, t); BenchMarkVerification("ECNR over GF(p) 168", spriv, spub, t); BenchMarkKeyGen("ECDHC over GF(p) 168", ecdhc, t); BenchMarkAgreement("ECDHC over GF(p) 168", ecdhc, t); BenchMarkKeyGen("ECMQVC over GF(p) 168", ecmqvc, t); BenchMarkAgreement("ECMQVC over GF(p) 168", ecmqvc, t); } cout << "<TBODY style=\"background: yellow\">" << endl; { Integer r("3805993847215893016155463826195386266397436443"); Integer k(12); Integer d("2065729449256706362097909124274151550853609397"); GF2NT gf2n(155, 62, 0); byte b[]={0x7, 0x33, 0x8f}; EC2N ec(gf2n, PolynomialMod2::Zero(), PolynomialMod2(b,3)); EC2N::Point P(0x7B, 0x1C8); P = ec.Multiply(k, P); EC2N::Point Q(ec.Multiply(d, P)); ECIES<EC2N>::Decryptor cpriv(ec, P, r, d); ECIES<EC2N>::Encryptor cpub(cpriv); ECDSA<EC2N, SHA>::Signer spriv(cpriv); ECDSA<EC2N, SHA>::Verifier spub(spriv); ECDH<EC2N>::Domain ecdhc(ec, P, r, k); ECMQV<EC2N>::Domain ecmqvc(ec, P, r, k); BenchMarkEncryption("ECIES over GF(2^n) 155", cpub, t); BenchMarkDecryption("ECIES over GF(2^n) 155", cpriv, cpub, t); BenchMarkSigning("ECNR over GF(2^n) 155", spriv, t); BenchMarkVerification("ECNR over GF(2^n) 155", spriv, spub, t); BenchMarkKeyGen("ECDHC over GF(2^n) 155", ecdhc, t); BenchMarkAgreement("ECDHC over GF(2^n) 155", ecdhc, t); BenchMarkKeyGen("ECMQVC over GF(2^n) 155", ecmqvc, t); BenchMarkAgreement("ECMQVC over GF(2^n) 155", ecmqvc, t); } cout << "</TABLE>" << endl; }