예제 #1
0
const uint256 CoinSpend::signatureHash(const SpendMetaData &m) const {
	CHashWriter h(0,0);
	h << m << serialCommitmentToCoinValue << accCommitmentToCoinValue << commitmentPoK << accumulatorPoK;
	return h.GetHash();
}
예제 #2
0
/** Inlined bodies **/
inline std::size_t hash_value(map_location  const & a){
	boost::hash<size_t> h;
	return h( (a.x << 16) ^ a.y );
}
예제 #3
0
/* associated data and nonce length in byte
 * nlen should be less than 16 bytes and larger than 0 byte;
 */
int process_ad(ae_cxt* cxt, const byte* ad, unsigned long long adlen, const byte* nonce, unsigned long long nlen)
{
	byte* state = cxt->es;

	cxt->ad = (byte*) ad;
	cxt->adlen = adlen;
	cxt->nonce = (byte*) nonce;
	cxt->nlen = nlen;
	/* process the first block */
	int ozp = 0;
	if(adlen < STATE_LEN){       // less than one block
		memcpy(state, ad, adlen);
		memset(state+adlen, 0, STATE_LEN-adlen);
		state[adlen] = 0x80;
		ozp = 1;                // one-zero padding works only if the adlen < 16
	}
	else{                       // full first block
		memcpy(state, ad, STATE_LEN);
	}

	/* apply fix0 and the E_k */
	int fix0 = state[0] & 0x80;    /* test if the MSB is zero */
	state[0] &= 0x7f;

	/* apply the first encryption */
	Encode(state, state);
	/* when fix0 works, apply h */
	if(fix0){
		word* wd = (word*) state;
		h(wd[0], wd[1], wd[2], wd[3]);
	}
	else{
		// do nothing
	}

	/* process the middle normal blocks of ad */
	unsigned long long i;
	for(i = 1; i < (unsigned long long)adlen/STATE_LEN; i++){
		xor_bytes(state, ad+i*STATE_LEN, STATE_LEN);
		pstate2("After xoring associated data:", state);
		Encode(state, state);
	}
	/* process the last block partial block if any */
	unsigned long long lastblocklen = adlen % STATE_LEN;
	if((adlen > STATE_LEN) && lastblocklen){
		xor_bytes(state, ad+i*STATE_LEN, lastblocklen);
		state[lastblocklen] ^= 0x80;
		pstate2("After processing last partial associated data block:", state);
		Encode(state, state);
		ozp = 1;
	}

	/* process the nonce */
	xor_bytes(state, nonce, nlen);

	/* apply padding to nonce */
	if(nlen != STATE_LEN)
		state[nlen] ^= 0x80;

	/* apply f1 or f2 to get V */
	if(ozp){ // apply f2
		word* wd = (word*) state;
		f2(wd[0], wd[1], wd[2], wd[3]);
	}
	else{ // apply f1
		word* wd = (word*) state;
		f1(wd[0], wd[1], wd[2], wd[3]);
	}
	pstate2("After applying f1/f2 to state:", state);

	memcpy(cxt->ts, state, STATE_LEN);
	Encode(state, state);

	return SUCCESS;
}
예제 #4
0
bool gWaveform::mouseOnStart() 
{
  return mouseX-10 >  chanStart + x() - BORDER              &&
         mouseX-10 <= chanStart + x() - BORDER + FLAG_WIDTH &&
         mouseY    >  h() + y() - FLAG_HEIGHT;
}
예제 #5
0
void gWaveform::draw() 
{
  /* blank canvas */

  fl_rectf(x(), y(), w(), h(), COLOR_BG_0);

  /* draw selection (if any) */

  if (selectionA != selectionB) {

    int a_x = selectionA + x() - BORDER; // - start;
    int b_x = selectionB + x() - BORDER; //  - start;

    if (a_x < 0)
      a_x = 0;
    if (b_x >= w()-1)
      b_x = w()-1;

    if (selectionA < selectionB)
      fl_rectf(a_x+BORDER, y(), b_x-a_x, h(), COLOR_BD_0);
    else
      fl_rectf(b_x+BORDER, y(), a_x-b_x, h(), COLOR_BD_0);
  }

  /* draw waveform from x1 (offset driven by the scrollbar) to x2
   * (width of parent window). We don't draw the entire waveform,
   * only the visibile part. */

  int offset = h() / 2;
  int zero   = y() + offset; // sample zero (-inf dB)

  int wx1 = abs(x() - ((gWaveTools*)parent())->x());
  int wx2 = wx1 + ((gWaveTools*)parent())->w();
  if (x()+w() < ((gWaveTools*)parent())->w())
    wx2 = x() + w() - BORDER;

  fl_color(0, 0, 0);
  for (int i=wx1; i<wx2; i++) {
    fl_line(i+x(), zero, i+x(), data.sup[i]);
    fl_line(i+x(), zero, i+x(), data.inf[i]);
    
    /* print grid */

    for (unsigned k=0; k<grid.points.size; k++) {
      if (grid.points.at(k) == i) {
        //gLog("draw grid line at %d\n", i);
        fl_color(fl_rgb_color(54, 54, 54));
        fl_line_style(FL_DASH, 0, NULL);
        fl_line(i+x(), y(), i+x(), y()+h());
        fl_color(0, 0, 0);
        fl_line_style(FL_SOLID, 0, NULL);
        break;
      }
    }
  }

  /* border box */

  fl_rect(x(), y(), w(), h(), COLOR_BD_0);

  /* print chanStart */

  int lineX = x()+chanStart+1;

  if (chanStartLit) fl_color(COLOR_BD_1);
  else              fl_color(COLOR_BD_0);

  /* vertical line */

  fl_line(lineX, y()+1, lineX, y()+h()-2);

  /* print flag and avoid overflow */

  if (lineX+FLAG_WIDTH > w()+x()-2)
    fl_rectf(lineX, y()+h()-FLAG_HEIGHT-1, w()-lineX+x()-1, FLAG_HEIGHT);
  else  {
    fl_rectf(lineX, y()+h()-FLAG_HEIGHT-1, FLAG_WIDTH, FLAG_HEIGHT);
    fl_color(255, 255, 255);
    fl_draw("s", lineX+4, y()+h()-3);
  }

  /* print chanEnd */

  lineX = x()+chanEnd;
  if (chanEndLit) fl_color(COLOR_BD_1);
  else            fl_color(COLOR_BD_0);

  fl_line(lineX, y()+1, lineX, y()+h()-2);

  if (lineX-FLAG_WIDTH < x())
    fl_rectf(x()+1, y()+1, lineX-x(), FLAG_HEIGHT);
  else {
    fl_rectf(lineX-FLAG_WIDTH, y()+1, FLAG_WIDTH, FLAG_HEIGHT);
    fl_color(255, 255, 255);
    fl_draw("e", lineX-10, y()+10);
  }
}
예제 #6
0
int gWaveform::alloc(int datasize)
{
  ratio = chan->wave->size / (float) datasize;

  if (ratio < 2)
    return 0;

  freeData();

  data.size = datasize;
  data.sup  = (int*) malloc(data.size * sizeof(int));
  data.inf  = (int*) malloc(data.size * sizeof(int));

  int offset = h() / 2;
  int zero   = y() + offset; // center, zero amplitude (-inf dB)

  /* grid frequency: store a grid point every 'gridFreq' pixel. Must be
   * even, as always */

  int gridFreq = 0;
  if (grid.level != 0) {
    gridFreq = chan->wave->size / grid.level; 
    if (gridFreq % 2 != 0)
      gridFreq--;
  }

  for (int i=0; i<data.size; i++) {

    int pp;  // point prev
    int pn;  // point next

    /* resampling the waveform, hardcore way. Many thanks to
     * http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html
     * Note: we use
     *   p = j * (m-1 / n)
     * instead of
     *   p = j * (m-1 / n-1)
     * in order to obtain 'datasize' cells to parse (and not datasize-1) */

    pp = i * ((chan->wave->size - 1) / (float) datasize);
    pn = (i+1) * ((chan->wave->size - 1) / (float) datasize);

    if (pp % 2 != 0) pp -= 1;
    if (pn % 2 != 0) pn -= 1;

    float peaksup = 0.0f;
    float peakinf = 0.0f;

    /* scan the original data in chunks */

    int k = pp;
    while (k < pn) {

      if (chan->wave->data[k] > peaksup)
        peaksup = chan->wave->data[k];    // FIXME - Left data only
      else
      if (chan->wave->data[k] <= peakinf)
        peakinf = chan->wave->data[k];    // FIXME - Left data only

      /* print grid */

      if (gridFreq != 0)
        if (k % gridFreq == 0 && k != 0)
          grid.points.add(i);
      
      k += 2;
    }

    data.sup[i] = zero - (peaksup * chan->boost * offset);
    data.inf[i] = zero - (peakinf * chan->boost * offset);

    // avoid window overflow

    if (data.sup[i] < y())       data.sup[i] = y();
    if (data.inf[i] > y()+h()-1) data.inf[i] = y()+h()-1;
  }

  recalcPoints();
  return 1;
}
예제 #7
0
inline std::size_t hash_value(const no_addressof_type& x)
{
  boost::hash<int> h;
  return h(x.n);
}