예제 #1
0
/**
 * Construct a proof.
 */
void constructProof(Credential *credential, unsigned char *masterSecret) {
  unsigned char i;
  unsigned int rA_size;
  unsigned int rA_offset;
  rA_size = realSize(credential->signature.v, SIZE_V) - 1 - realSize(credential->signature.e, SIZE_E);
  if (rA_size > SIZE_R_A) { rA_size = SIZE_R_A; }
  rA_offset = SIZE_R_A - rA_size;

  // Generate random values for m~[i], e~, v~ and rA
  for (i = 0; i <= credential->size; i++) {
    if (disclosed(i) == 0) {
      // IMPORTANT: Correction to the length of mTilde to prevent overflows
      RandomBits(session.prove.mHat[i], LENGTH_M_ - 1);
    }
  }
  debugValues("mTilde", session.prove.mHat, SIZE_M_, SIZE_L);
  // IMPORTANT: Correction to the length of eTilde to prevent overflows
  RandomBits(public.prove.eHat, LENGTH_E_ - 1);
  debugValue("eTilde", public.prove.eHat, SIZE_E_);
  // IMPORTANT: Correction to the length of vTilde to prevent overflows
  RandomBits(public.prove.vHat, LENGTH_V_ - 1);
  debugValue("vTilde", public.prove.vHat, SIZE_V_);
  // IMPORTANT: Correction to the length of rA to prevent negative values
  RandomBits(public.prove.rA + rA_offset, rA_size * 8 - 1);
  for (i = 0; i < rA_offset; i++) {
    public.prove.rA[i] = 0x00; // Set first byte(s) of rA, since it's not set by RandomBits command
  }
예제 #2
0
void StepScan::fillPlotVarCombobox( const MatrixWorkspace_const_sptr & ws )
{
  // Hold the name of the scan index log in a common place
  const std::string scan_index("scan_index");
  // Clear the combobox and immediately re-insert 'scan_index' (so it's the first entry)
  m_uiForm.plotVariable->clear();
  m_uiForm.plotVariable->addItem( QString::fromStdString(scan_index) );

  // First check that the provided workspace has the scan_index - complain if it doesn't
  try {
    auto scan_index_prop = ws->run().getTimeSeriesProperty<int>(scan_index);
    if ( scan_index_prop->realSize() < 2 )
    {
      // TODO: This might be mistakenly triggered for live datasets.
      QMessageBox::warning(this,"scan_index log empty","This data does not appear to be an alignment scan");
      return;
    }
  } catch ( std::exception& ) {
  // Old way: ws->run().hasProperty(scan_index)
    QMessageBox::warning(this,"scan_index log not found","Is this an ADARA-style dataset?");
    return;
  }

  // This is unfortunately more or less a copy of SumEventsByLogValue::getNumberSeriesLogs
  // but I want to populate the box before running the algorithm
  const auto & logs = ws->run().getLogData();
  for ( auto log = logs.begin(); log != logs.end(); ++log )
  {
    const std::string logName = (*log)->name();
    // Don't add scan_index - that's already there
    if ( logName == scan_index ) continue;
    // Try to cast to an ITimeSeriesProperty
    auto tsp = dynamic_cast<const ITimeSeriesProperty*>(*log);
    // Move on to the next one if this is not a TSP
    if ( tsp == NULL ) continue;
    // Don't keep ones with only one entry
    if ( tsp->realSize() < 2 ) continue;
    // Now make sure it's either an int or double tsp, and if so add log to the list
    if ( dynamic_cast<TimeSeriesProperty<double>* >(*log) || dynamic_cast<TimeSeriesProperty<int>* >(*log))
    {
      m_uiForm.plotVariable->addItem( QString::fromStdString( logName ) );
    }
  }

  // Now that this has been populated, allow the user to select from it
  m_uiForm.plotVariable->setEnabled(true);
  // Now's the time to enable the start button as well
  m_uiForm.startButton->setEnabled(true);
}
예제 #3
0
TexturePacker::TextureNode* TexturePacker::pack(TextureNode* node, const glm::ivec2& size)
{
	if (!node->empty) {
		// Filled, we have to be a leaf
		assert(!node->left && !node->right);
		return NULL;
	} else if (node->left && node->right) {
		// Non-leaf, try inserting to the left and then to the right
		assert(node->left && node->right);
		TextureNode* retval = pack(node->left.get(), size);
		if (retval != NULL) {
			return retval;
		}
		return pack(node->right.get(), size);
	} else {
		glm::ivec2 realSize(node->origin.x + node->size.x == INT_MAX ? textureSize.x - node->origin.x : node->size.x,
			node->origin.y + node->size.y == INT_MAX ? textureSize.y - node->origin.y : node->size.y);
		// Unfilled leaf - try to fill
		if (node->size.x == size.x && node->size.y == size.y) {
			// This is an interior cell which perfectly fits, just pack it
			node->empty = false;
			return node;
		} else if (realSize.x < size.x || realSize.y < size.y) {
			// Not big enough
			return NULL;
		} else {
			// Large enough - split
			TextureNode* left;
			TextureNode* right;
			int remainX = realSize.x - size.x;
			int remainY = realSize.y - size.y;

			bool verticalSplit = remainX < remainY;
			if (remainX == 0 && remainY == 0) {
				// This is an exterior cell which perfectly fits - split along the side which is closer to INT_MAX
				if (node->size.x > node->size.y) {
					verticalSplit = false;
				} else {
					verticalSplit = true;
				}
			}

			if (verticalSplit) {
				// Split vertically (left is top)
				left = new TextureNode(node->origin, glm::ivec2(node->size.x, size.y));
				right = new TextureNode(glm::ivec2(node->origin.x, node->origin.y + size.y),
										glm::ivec2(node->size.x, node->size.y - size.y));
			} else {
				// Split horizontally
				left = new TextureNode(node->origin, glm::ivec2(size.x, node->size.y));
				right = new TextureNode(glm::ivec2(node->origin.x + size.x, node->origin.y),
										glm::ivec2(node->size.x - size.x, node->size.y));
			}

			node->left = std::unique_ptr<TextureNode>(left);
			node->right = std::unique_ptr<TextureNode>(right);
			return pack(node->left.get(), size);
		}
	}
}
예제 #4
0
void QtPrinterSymbolTextPainter::paint(const QPoint& aPoint, QPainter& aPainter, const QFont& aFontLower)
{
	Q_UNUSED(aFontLower)

	QPixmap* pixmap=pixmaps.value(aPainter.font().key());
	if(pixmap==NULL)
	{
		QPixmap fullResPixmap;
		fullResPixmap.load(QString(IMAGE_FILE_TYPE)+':'+ IMAGE_NAME);
		delete pixmap;
		QSize fullSize=aPainter.fontMetrics().boundingRect(PROTOTYPE_TEXT).size();
		QSize realSize(fullSize.width()*SIZE_FACTOR, fullSize.height()*SIZE_FACTOR);
		deltaX=(fullSize.width()-realSize.width())/2;
		deltaY=(fullSize.height()-realSize.height())/2;
		pixmap = new QPixmap(fullResPixmap.scaled(realSize));
		pixmaps.insert(aPainter.font().key(), pixmap);
	}
	aPainter.drawPixmap(QPoint(aPoint.x()+deltaX, aPoint.y()+deltaY), *pixmap);
}
예제 #5
0
BigInteger<BASE>& BigInteger<BASE>::operator<<=(int shift) {
	if(!isReal() || isNull()) 
		return *this;

	if(shift > 0) {
		int size = capacity();
		int realsize = realSize();
		while(realsize + shift > size)
			size = expand();
		if(realsize == 1 && _a[0] == 0) 
			return *this;
		for(int index = realsize-1; index >= 0; --index) 
			_a[index+shift] = _a[index];
		for(int index = shift-1; index >= 0; --index)
			_a[index] = 0;
		updRealSize(shift);
		return *this;
	}
	else if(shift == 0) 
		return *this;
	else 
		return (*this)>>=(-shift);
}
예제 #6
0
 Impl(size_t size = 0) :
     buffer(realSize(size), container::value_type())
 {}
예제 #7
0
 void Buffer::resize(std::size_t newSize)
 {
     impl->buffer.resize(realSize(newSize));
 }
예제 #8
0
/**
 * Construct a proof.
 */
void constructProof(Credential *credential, unsigned char *masterSecret) {
  unsigned char i, j;
  unsigned int rA_size;
  unsigned int rA_offset;

  unsigned long dwPrevHashedBytes;
  unsigned short wLenMsgRem;
  unsigned short pRemainder;
      
  rA_size = realSize(credential->signature.v, SIZE_V) - 1 - realSize(credential->signature.e, SIZE_E);
  if (rA_size > SIZE_R_A) { rA_size = SIZE_R_A; }
  rA_offset = SIZE_R_A - rA_size;

  init_PRNG();

  // HASH - init
  
  memset(session.prove.bufferHash, 0, 64);  

  pRemainder = 0;
  dwPrevHashedBytes = 0;
  wLenMsgRem = 0;

  //multosSecureHashIV(SIZE_STATZK, SHA_256, session.prove.challenge, public.prove.apdu.nonce, session.prove.bufferHash, &dwPrevHashedBytes, &wLenMsgRem, &pRemainder);

  /* C = Z^m * S^r \mod n */

  ModExp(SIZE_M, SIZE_N, credential->attribute[0], credential->issuerKey.n, credential->issuerKey.Z, public.prove.buffer.number[0]);          
  ModExp(SIZE_M, SIZE_N, r, credential->issuerKey.n, credential->issuerKey.S, public.prove.buffer.number[1]);          

  ModMul(SIZE_N, public.prove.buffer.number[0], public.prove.buffer.number[1], credential->issuerKey.n);  
  Copy(SIZE_N, session.prove.C, public.prove.buffer.number[0]);
    
  multosSecureHashIV(SIZE_N, SHA_256, session.prove.challenge, session.prove.C, session.prove.bufferHash, &dwPrevHashedBytes, &wLenMsgRem, &pRemainder);

  /* C_tilde = (Z^(m_r))^ \tilde{m_h} * S ^ \tilde{r}/ */

  ComputeHat();  
  ModExp(SIZE_M_, SIZE_N, session.prove.mHatTemp, credential->issuerKey.n, rev_attr_1, public.prove.buffer.number[0]);          

  ComputeHat();  
  ModExp(SIZE_M_, SIZE_N, session.prove.mHatTemp, credential->issuerKey.n, credential->issuerKey.S, public.prove.buffer.number[1]);          
  ModMul(SIZE_N, public.prove.buffer.number[0], public.prove.buffer.number[1], credential->issuerKey.n);  
  
  Copy(SIZE_N, session.prove.Ctilde, public.prove.buffer.number[0]);
  
  multosSecureHashIV(SIZE_N, SHA_256, session.prove.challenge, session.prove.Ctilde, session.prove.bufferHash, &dwPrevHashedBytes, &wLenMsgRem, &pRemainder);

  /* \tilde{Co} = Z^{\tilde{m}} * S^{\tilde{r}} \mod n */
  
  ModExp(SIZE_M_, SIZE_N, session.prove.mHatTemp, credential->issuerKey.n, credential->issuerKey.S, public.prove.buffer.number[1]);          

  ComputeHat();  
  ModExp(SIZE_M_, SIZE_N, session.prove.mHatTemp, credential->issuerKey.n, credential->issuerKey.Z, public.prove.buffer.number[0]);          

  ModMul(SIZE_N, public.prove.buffer.number[0], public.prove.buffer.number[1], credential->issuerKey.n);
  multosSecureHashIV(SIZE_N, SHA_256, session.prove.challenge, public.prove.buffer.number[0], session.prove.bufferHash, &dwPrevHashedBytes, &wLenMsgRem, &pRemainder);

  //reset_PRNG(); // XXXX: Move after \tilde{Z} ?

  // IMPORTANT: Correction to the length of eTilde to prevent overflows
  RandomBits(public.prove.eHat, LENGTH_E_ - 1);
  debugValue("eTilde", public.prove.eHat, SIZE_E_);
  // IMPORTANT: Correction to the length of vTilde to prevent overflows
  RandomBits(public.prove.vHat, LENGTH_V_ - 1);
  debugValue("vTilde", public.prove.vHat, SIZE_V_);
  // IMPORTANT: Correction to the length of rA to prevent negative values
  RandomBits(public.prove.rA + rA_offset, rA_size * 8 - 1);
  for (i = 0; i < rA_offset; i++) {
    public.prove.rA[i] = 0x00; // Set first byte(s) of rA, since it's not set by RandomBits command
  }