Example #1
0
void QcacheEntry_c::FlushFrame()
{
	/////////////////////////////
	// store an incomplete frame
	/////////////////////////////

	if ( !m_dFrame.GetLength() )
		return;

	if ( m_dFrame.GetLength()<MAX_FRAME_SIZE )
	{
		// begin with two marker bytes
		// 100wwddd 00lllll
		// ww = 1..4 bytes per weight
		// ddd = 1..8 bytes per delta
		// lllll = 1..31 {delta,weight} pairs
		int iDeltaBytes = 1;
		int iWeightBytes = 1;
		SphDocID_t uLastId = m_uLastDocid;
		ARRAY_FOREACH ( i, m_dFrame )
		{
			SphDocID_t uDelta = m_dFrame[i].m_uDocid - uLastId - 1;
			uLastId = m_dFrame[i].m_uDocid;
			iDeltaBytes = Max ( iDeltaBytes, NumBytes ( uDelta ) );
			iWeightBytes = Max ( iWeightBytes, NumBytes ( m_dFrame[i].m_uWeight ) );
		}
Example #2
0
/****************************************
  Bit vector - copied straight from Andreas.
  ****************************************/
dynBitVec::dynBitVec (unsigned long nBits):
  numBits (nBits)
{
  v = new unsigned char[NumBytes ()];	/* Allocate and clear vector. */
  MEMTRACKALLOC
  ErrAlloc (v);
  memset (v, 0, NumBytes ());
};
Example #3
0
MFString& MFString::operator+=(char c)
{
	Reserve(NumBytes() + 2);
	pData->pMemory[pData->bytes++] = c;
	pData->pMemory[pData->bytes] = 0;
	return *this;
}
Example #4
0
MFString& MFString::PadLeft(int minLength, const char *pPadding)
{
	// check if the string is already long enough
	int len = NumBytes();
	if(len >= minLength)
		return *this;

	// reserve enough memory
	Reserve(minLength + 1);
	pData->bytes = minLength;

	// move string
	size_t preBytes = minLength - len;
	for(int a=len; a>=0; --a)
		pData->pMemory[a + preBytes] = pData->pMemory[a];

	// pre-pad the string
	size_t padLen = MFString_Length(pPadding);
	for(size_t a=0, b=0; a<preBytes; ++a, ++b)
	{
		if(b >= padLen)
			b = 0;

		pData->pMemory[a] = pPadding[b];
	}

	return *this;
}
Example #5
0
MFString& MFString::PadRight(int minLength, const char *pPadding, bool bAlignPadding)
{
	// check if the string is already long enough
	int len = NumBytes();
	if(len >= minLength)
		return *this;

	// reserve enough memory
	Reserve(minLength + 1);
	pData->bytes = minLength;
	pData->pMemory[minLength] = 0;

	// pad the string
	size_t padLen = MFString_Length(pPadding);
	size_t b = bAlignPadding ? len%padLen : 0;
	for(int a=len; a<minLength; ++a, ++b)
	{
		if(b >= padLen)
			b = 0;

		pData->pMemory[a] = pPadding[b];
	}

	return *this;
}
Example #6
0
/* function sampleRandomFieldElements : Samples random field elements in the GF2E field, 
										return their coefficients in the return value and set their pointers to the pointerToElements argument.
 * param numElements				  : number of elements to sample
 * param pointerToElements		      : an array to fill with the sampled elements' pointers.
 * return jobjectArray				  : array of element's coefficients
 */
jobjectArray sampleRandomFieldElements(JNIEnv * env, jint numElements, jlongArray pointerToElements){
	
	  jclass byteArrCls = env->FindClass("[B") ; //Define byte class
	  //create object array that will hold the challenges.
	  jobjectArray outChallenges = env->NewObjectArray(numElements, byteArrCls, NULL); 
	  
	  jlong* pointers = env->GetLongArrayElements(pointerToElements, 0);
	  
	  //Samples random elements, puts their bytes in the output array and put their addresses in the pointers array.
	  for (int i=0; i<numElements; i++){
		  //sample random field element.
		  GF2E* element = new GF2E;
		  *element = random_GF2E();

		  //Get the bytes of the random element.
		  jbyteArray elArr = env->NewByteArray(NumBytes(rep(*element)));
		  jbyte* el = env->GetByteArrayElements(elArr, 0);
		  convertGF2EToBytes(*element, el);
		  
		  //put the bytes of the random element in the output array.
		  env->SetObjectArrayElement(outChallenges, i, elArr);
		 
		  env->ReleaseByteArrayElements(elArr, el, 0);
		  //put the element address in the pointers array
		  pointers[i] = (jlong)element;

	  }

	  //release the allocated memory
	  env->ReleaseLongArrayElements(pointerToElements, pointers, 0);
	  
	  return outChallenges;
}
Example #7
0
jobjectArray calcPolynomialBytes(JNIEnv *env, jlong poly){
	GF2EX* polynom = (GF2EX*) poly;
	  long degree = deg(*polynom);

	  jclass byteArrCls = env->FindClass("[B") ; //Define byte class
	  //create object array that will hold the challenges.
	  jobjectArray polynomBytes = env->NewObjectArray(degree+1, byteArrCls, NULL); 

	  //convert each coefficient polynomial to byte array and put it in the output array.
	  for (int i=0; i<=degree; i++){
		  //get the coefficient polynomial
		  GF2E coefficient = coeff(*polynom, i);
			
		  //get the bytes of the coefficient.
		  jbyteArray elArr = env->NewByteArray(NumBytes(rep(coefficient)));
		  jbyte* el = env->GetByteArrayElements(elArr, 0);
		  convertGF2EToBytes(coefficient, el);
		    
		  //put the bytes of the coefficient element in the output array.
		  env->SetObjectArrayElement(polynomBytes, i, elArr);
		  env->ReleaseByteArrayElements(elArr, el, 0);
	  }

	  return polynomBytes;
}
Example #8
0
/* function convertGF2EToBytes : Get the bytes of the random element.
 * param element			   : element to convert to bytes
 * param byteArr		       : array that will contain the bytes
 *return int				   : number of byte of the created polynomial.
 */
void convertGF2EToBytes(GF2E element, jbyte* byteArr){
	 
	GF2X fromEl = rep(element); //convert the GF2E element to GF2X element.
	 int numBytes = NumBytes(fromEl); //get the number of element bytes.
	 //the function rep returns the representation of GF2E as the related GF2X, it returns as read only.
	 BytesFromGF2X((unsigned char *)byteArr, fromEl, numBytes);
}
Example #9
0
void ShowZZInHex ( const ZZ &a )
{
    byte bt[MAXB];

    long num = NumBytes(a);

    BytesFromZZ(bt, a, num);
    for (long i = num-1; i >= 0; i--)
        cout << hex << setw(2) << setfill('0')
             << (int)bt[i];
}
Example #10
0
/* Copies the ZZ into the mpz_t
   Assumes output has been mpz_init'd.
   AUTHOR: David Harvey
           Joel B. Mohler moved the ZZX_getitem_as_mpz code out to this function (2007-03-13) */
static void ZZ_to_mpz(mpz_t output, const struct ZZ* x)
{
    unsigned char stack_bytes[4096];
    unsigned long size = NumBytes(*x);
    int use_heap = (size > sizeof(stack_bytes));
    unsigned char* bytes = use_heap ? (unsigned char*) malloc(size) : stack_bytes;
    BytesFromZZ(bytes, *x, size);
    mpz_import(output, size, -1, 1, 0, 0, bytes);
    if (sign(*x) < 0)
        mpz_neg(output, output);
    if (use_heap)
        free(bytes);
}
Example #11
0
bool FrameParser::VBRHeader::Parse(BufferReader* aReader) {
  auto res = MakePair(ParseVBRI(aReader), ParseXing(aReader));
  const bool rv = (res.first().isOk() && res.first().unwrap()) ||
                  (res.second().isOk() && res.second().unwrap());
  if (rv) {
    MP3LOG(
        "VBRHeader::Parse found valid VBR/CBR header: type=%s"
        " NumAudioFrames=%u NumBytes=%u Scale=%u TOC-size=%zu",
        vbr_header::TYPE_STR[Type()], NumAudioFrames().valueOr(0),
        NumBytes().valueOr(0), Scale().valueOr(0), mTOC.size());
  }
  return rv;
}
Example #12
0
//Фунции для групповой работы
void NTL_Pack(ZZ x, unsigned char * buf, int& buf_ub) {
    ntl_params def_data;
    def_data.size = NumBytes(x);
    def_data.sign = x>=0?1:-1;
    memcpy(&(buf[buf_ub]),&def_data,sizeof(def_data));
    buf_ub+=sizeof(def_data);
    if (def_data.size>0) {
        unsigned char * temp_buf = new unsigned char [def_data.size];
        BytesFromZZ(temp_buf,x,def_data.size);
        memcpy(&(buf[buf_ub]),temp_buf,def_data.size);
        buf_ub+=def_data.size;
        delete [] temp_buf;
    }
};
Example #13
0
jobjectArray calcRestChallenges(JNIEnv *env, jlong polynomial, jintArray indexesInI){
	
	//convert to native objects
	  GF2EX* polynom = (GF2EX*) polynomial;
	  jint* indexes = env->GetIntArrayElements(indexesInI, 0);

	  int size = env->GetArrayLength(indexesInI);
	  jclass byteArrCls = env->FindClass("[B") ; //Define byte class
	  //create object array that will hold the challenges.
	  jobjectArray outChallenges = env->NewObjectArray(size, byteArrCls, NULL); 

	  //calculate the y coordinate (the challenge) to each one of the indexes (the indexes).
	  for (int i=0; i<size; i++){

		 //get the index polynomial
		 GF2E element = generateIndexPolynomial(indexes[i]);
		 
		 //Evaluate the poltyomial on the index to get the challenge element.
		 GF2E result = eval(*polynom, element);

		 //Get the bytes of the challenge element.
		 jbyteArray elArr = env->NewByteArray(NumBytes(rep(result)));
		 jbyte* el = env->GetByteArrayElements(elArr, 0);
		 convertGF2EToBytes(result, el);
		  
		 //put the bytes of the challenge element in the output array.
		 env->SetObjectArrayElement(outChallenges, i, elArr);
		 env->ReleaseByteArrayElements(elArr, el, 0);
	  }

	  bool valid = true;
	  for (int i=0; i<size; i++){
		  jbyteArray elArr = (jbyteArray)env->GetObjectArrayElement(outChallenges, i);
		  GF2E element = convertBytesToGF2E(env, elArr); 
		  //create the index element
		  GF2E indexElement = generateIndexPolynomial(indexes[i]);
		 
		  //compute Q(i)
		  GF2E result = eval(*polynom, indexElement);
		  //check that Q(i)=ei
		  if (result != element){
				valid = false;
		  }
	  }
	  return outChallenges;
}
Example #14
0
NTL_CLIENT

//Функция отсылки ZZ числа
int MPI_NTL_Send(ZZ  x, int process_id) {
    unsigned char * buf;
    ntl_params def_data;
    def_data.size = NumBytes(x);
    def_data.sign = x>=0?1:-1;
    MPI_Send(&def_data,sizeof(ntl_params),MPI_CHAR,process_id,MPI_NTL_SIGN,MPI_COMM_WORLD);

    if (def_data.size > 0) {
        buf = new unsigned char [def_data.size];
        BytesFromZZ(buf,x,def_data.size);
        MPI_Send(buf,def_data.size,MPI_CHAR,process_id,MPI_NTL_DATA,MPI_COMM_WORLD);
        delete [] buf;
    }
    return 0;
};
Example #15
0
//Функция широковещательной рассылки ZZ числа
int MPI_NTL_Bcast(ZZ& x, int process_id) {
    unsigned char * buf;
    ntl_params def_data;
    def_data.size = NumBytes(x);
    def_data.sign = x>=0?1:-1;

    MPI_Bcast(&def_data,sizeof(ntl_params),MPI_CHAR,process_id,MPI_COMM_WORLD);

    if  (def_data.size >0) {
        buf = new unsigned char [def_data.size];
        BytesFromZZ(buf,x,def_data.size);
        MPI_Bcast(buf,def_data.size,MPI_CHAR,process_id,MPI_COMM_WORLD);
        ZZFromBytes(x,buf,def_data.size);
        x*=def_data.sign;
        delete [] buf;
    }
    else {
        x=0;
    }
    return 0;
};
Example #16
0
/* function sampleChallenge : Samples random field elements in the GF2E field.
 * param pointerToChallenge	: will hold the pointer to the sampled element
 * return jobjectArray		: array of element coefficients
 */
JNIEXPORT jbyteArray JNICALL Java_edu_biu_scapi_interactiveMidProtocols_sigmaProtocol_orMultiple_SigmaORMultipleVerifierComputation_sampleChallenge
  (JNIEnv *env, jobject, jlongArray pointerToChallenge){
	  
	//sample random field element.	
	GF2E* element = new GF2E;
	*element = random_GF2E(); 
	
	//get the element's byte.
	jbyteArray elArr = env->NewByteArray(NumBytes(rep(*element)));
	jbyte* el = env->GetByteArrayElements(elArr, 0);
	convertGF2EToBytes(*element, el);
	env->ReleaseByteArrayElements(elArr, el, 0);

	//set the pointer in the argument.
	jlong* pointer = env->GetLongArrayElements(pointerToChallenge, 0);
	pointer[0] = (jlong)element;
	// release the array
	env->ReleaseLongArrayElements(pointerToChallenge, pointer, 0);

	return elArr;
}