Example #1
0
void __xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
		     unsigned long *v2_in, unsigned long *v3_in,
		     unsigned long *v4_in, unsigned long *v5_in)
{
	DEFINE(v1);
	DEFINE(v2);
	DEFINE(v3);
	DEFINE(v4);
	DEFINE(v5);
	unsigned long lines = bytes / (sizeof(unative_t)) / 4;

	do {
		LOAD(v1);
		LOAD(v2);
		LOAD(v3);
		LOAD(v4);
		LOAD(v5);
		XOR(v1, v2);
		XOR(v3, v4);
		XOR(v1, v5);
		XOR(v1, v3);
		STORE(v1);

		v1 += 4;
		v2 += 4;
		v3 += 4;
		v4 += 4;
		v5 += 4;
	} while (--lines > 0);
}
Example #2
0
/*
 * CBCEncrypt - Encrypt message using CBC mode
 * 
 * In CBC mode the message is divided into blocks of 16 bytes, to 1 block
 * Applied to the XOR and calculated its block cipher with block
 * Encryption XOR obtained is applied to the second data block in clear
 * And the result is encrypted with AES given, the result will be the 2nd block
 * Encryption, so on.
 * 
 * This function is:
 * 	1 - separated data block of 16 bytes,
 * 	2 - XOR operation is performed with the IV / block precesor
 * 	3 - was called to the encryption function
 * 	4 - Once all blocks are encrypted will join
 * 	5 - forms the encrypted message and returns
 * 
 */
void WaspAES::CBCEncrypt(	uint8_t *original_data,
							uint16_t size,
							uint8_t *InitialVector,
							uint16_t keySize)
{
	uint8_t IV[16];
	uint8_t Plain_text[16];
	uint8_t Previous_block[16];

	uint16_t index,index2;
	index = 0;
	index2 = 0;

	//Assign Initial Vector to IV variable
	assignBlock(IV,InitialVector);

	while( index < size )
	{
		// Copy 16B block
		for (int i =0; i<16 ; i++)
		{
			Plain_text[i] = original_data[index];
			index++;
		}
		
		// Perform XOR with corresponding IV block
		if ( index == 16)
		{
			// the first time the XOR is done with the Original IV
			XOR( Plain_text, IV, block_data);
		}
		else 
		{
			// the rest of the times, the XOR is done with 
			// the previous encrypted block
			XOR( Plain_text, Previous_block, block_data);
		}

		switch(keySize)
		{
			case 128:
				aes128_enc(block_data, &ctx128);
				break;
			case 192:
				aes192_enc(block_data, &ctx192);
				break;
			case 256:
				aes256_enc(block_data, &ctx256);
				break;
		}

		assignBlock( Previous_block, block_data);

		for (int i = 0; i<16;i++)
		{
			original_data[index2] = block_data[i];
			index2++;
		}
	}
}
Example #3
0
unsigned long long MDC2(unsigned long long *x, unsigned int t)
{
   // Divide x em blocos de 64 bits (ja esta)
   //Define IV e N_IV
   unsigned long long IV = 0x5252525252525252, N_IV = 0x2525252525252525;
   int i;
   unsigned long long H[t+1], N_H[t+1], K[t+1], N_K[t+1], C[t+1], N_C[t+1];
   H[0] = IV;
   N_H[0] = N_IV;
   for (i = 1; i <= t; i++)
   {
      K[i] = g(H[i-1], NOT_INVERTED);
      N_K[i] = g(N_H[i-1], INVERTED);
      
      // des ao plaintext x[i] com chave K[i]
      C[i] = XOR(DES(x[i], K[i]), x[i]);
      N_C[i] = XOR(DES(x[i], N_K[i]), x[i]);
      
      unsigned long long CL, CR, N_CL, N_CR;
      CL = C[i] >> 32; // Left 32 bits de C[i]
      CR = C[i] & 0x80000000; // Right 32 bits de C[i]
      N_CL = N_C[i] >> 32;
      N_CR = N_C[i] & 0x80000000;
      
      // Concatena
      H[i] = (CL << 32) | N_CR;
      N_H[i] = (N_CL << 32) | CR;
   }
}
Example #4
0
void AES_CMAC_Update(AES_CMAC_CTX *ctx, const u_int8_t *data, u_int len)
{
	u_int mlen;
	unsigned char in[16];
	
	if (ctx->M_n > 0)
	{
		mlen = MIN(16 - ctx->M_n, len);
		memcpy1(ctx->M_last + ctx->M_n, data, mlen);
		ctx->M_n += mlen;
		if (ctx->M_n < 16 || len == mlen)
			return;
		XOR(ctx->M_last, ctx->X);
		// rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);
		aes_encrypt( ctx->X, ctx->X, &ctx->rijndael);
		data += mlen;
		len -= mlen;
	}
	while (len > 16)
	{	/* not last block */
		XOR(data, ctx->X);
		// rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);

		memcpy1(in, &ctx->X[0], 16); //Bestela ez du ondo iten
		aes_encrypt( in, in, &ctx->rijndael);
		memcpy1(&ctx->X[0], in, 16);

		data += 16;
		len -= 16;
	}

	/* potential last block, save it */
	memcpy1(ctx->M_last, data, len);
	ctx->M_n = len;
}
Example #5
0
/**
   Ordered local closest node lookup
   @return k neighbors in a list
*/
struct ilist*
KDA_Closest(KDA_ID object_id)
{
  NOTE_FX(object_id);

  struct ilist* result = ilist_create();

  int d = XOR(self->id, object_id);
  ilist_add(result, d, self);

  for (int i = 0; i < KDA_SPACE_SIZE; i++)
  {
    for (struct list_item* item = k_bucket[i]->head;
         item; item = item->next)
    {
      KDA_Neighbor* neighbor = (KDA_Neighbor*) item->data;
      d = XOR(neighbor->id, object_id);
      if (result->size < k)
      {
        ilist_ordered_insert(result, d, neighbor);
      }
      else if (d < result->tail->key)
      {
        ilist_ordered_insert(result, d, neighbor);
        ilist_pop(result);
      }
    }
  }
  return result;
}
Example #6
0
File: CCM.c Project: SepOwnage/P-O5
 /*
 * Encrypt the given Payload, update sender context and output
 * decryption in ciphermessage.
 *
 * ciphermessage        pointer output array with size >= payload + MAC_LENGTH
 * ENC_sender_ctx       pointer to the encoding sender context
 * Payload              pointer to the plaintext to send
 * Plen                 the length of Payload in bytes max size = MAX_MESSAGE_LENGTH - MAC_LENGTH
 */
 void CCM_encrypt(message_ctx *ciphermessage, ENC_ctx *ENC_sender_ctx, const void *Payloadin, const unsigned int Plen)
 {
    const unsigned char *Payload = Payloadin;

    unsigned char TEMP[((MAX_MESSAGE_LENGTH*2 - MAC_LENGTH-1)/BLOCK_LENGTH + 1 + 2)*BLOCK_LENGTH];
    unsigned char MAC[MAC_LENGTH];
    unsigned int * temp = (unsigned int *) (ENC_sender_ctx->nonce+2);
    //increase counter part of Nonce, the counter part is written small endian
    (ENC_sender_ctx->counter)++;
    *temp = ENC_sender_ctx->counter;

    formatData(TEMP, ENC_sender_ctx->nonce ,Payload, Plen);

    generateMAC(MAC, ENC_sender_ctx->key,TEMP,(Plen-1)/BLOCK_LENGTH + 1 +2);
    create_cyphered_counter_block(TEMP, ENC_sender_ctx->key, ENC_sender_ctx->nonce, (Plen-1)/BLOCK_LENGTH + 2);
    XOR(MAC, MAC, TEMP, MAC_LENGTH);
    XOR(ciphermessage->data, Payload, TEMP+BLOCK_LENGTH, Plen);


    ciphermessage->seq_number = ENC_sender_ctx->counter;
    ciphermessage->length = Plen + MAC_LENGTH;

    memcpy(((unsigned char *) (ciphermessage->data)) + Plen,MAC,MAC_LENGTH);

 }
Example #7
0
void xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
		   unsigned long *v2_in, unsigned long *v3_in)
{
	DEFINE(v1);
	DEFINE(v2);
	DEFINE(v3);
	unsigned long lines = bytes / (sizeof(unative_t)) / 4;

	preempt_disable();
	enable_kernel_altivec();

	do {
		LOAD(v1);
		LOAD(v2);
		LOAD(v3);
		XOR(v1, v2);
		XOR(v1, v3);
		STORE(v1);

		v1 += 4;
		v2 += 4;
		v3 += 4;
	} while (--lines > 0);

	preempt_enable();
}
Example #8
0
void WaspAES::CBCEncrypt(uint8_t *original_data,uint16_t size, uint8_t *InitialVector,uint16_t keySize){
///////////////////////////
// In CBC mode the message is divided into blocks of 16 bytes, to 1 block
// Applied to the XOR and calculated its block cipher with block
// Encryption XOR obtained is applied to the second data block in clear
// And the result is encrypted with AES given, the result will be the 2nd block
// Encryption, so on.
//
// This function is:
// 1 - separated data block of 16 bytes,
// 2 - XOR operation is performed with the IV / block precesor
// 3 - was called to the encryption function
// 4 - Once all blocks are encrypted will join
// 5 - forms the encrypted message and returns
//
///////////////////////////

  uint8_t IV[16];
  uint8_t Plain_text[16];
  uint8_t Previous_block[16];
  
  uint16_t index,index2;
  index = 0;
  index2 = 0;
  
  //Assign Initial Vector to IV variable
  assignBlock(IV,InitialVector);
  
  while(index<size){
    // Encrypt
    for (int i =0; i<16;i++){
      Plain_text[i]= original_data[index];	
      index++;
    }
    if (index == 16){
      XOR(Plain_text,IV,block_data);
    }else {
      XOR(Plain_text,Previous_block,block_data);
    }

    switch(keySize){
      case 128:
	aes128_enc(block_data, &ctx128);
	break;
      case 192:
	aes192_enc(block_data, &ctx192);
	break;
      case 256:
	aes256_enc(block_data, &ctx256);
	break;
    }
  
    assignBlock(Previous_block,block_data);
    
    for (int i = 0; i<16;i++){
      original_data[index2] = block_data[i];
      index2++;
    }
  }
}
Example #9
0
int main()
{
	printf("\nNOT 1: %d\n", NOT(1));
	printf("NOT 0: %d\n", NOT(0));

	printf("\n1 AND 1: %d\n", AND(1, 1));
	printf("1 AND 0: %d\n", AND(1, 0));
	printf("0 AND 1: %d\n", AND(0, 1));
	printf("0 AND 0: %d\n", AND(0, 0));

	printf("\n1 OR 1: %d\n", OR(1, 1));
	printf("1 OR 0: %d\n", OR(1, 0));
	printf("0 OR 1: %d\n", OR(0, 1));
	printf("0 OR 0: %d\n", OR(0, 0));

	printf("\n1 NOR 1: %d\n", NOR(1, 1));
	printf("1 NOR 0: %d\n", NOR(1, 0));
	printf("0 NOR 1: %d\n", NOR(0, 1));
	printf("0 NOR 0: %d\n", NOR(0, 0));

	printf("\n1 NAND 1: %d\n", NAND(1, 1));
	printf("1 NAND 0: %d\n", NAND(1, 0));
	printf("0 NAND 1: %d\n", NAND(0, 1));
	printf("0 NAND 0: %d\n", NAND(0, 0));

	printf("\n1 XOR 1: %d\n", XOR(1, 1));
	printf("1 XOR 0: %d\n", XOR(1, 0));
	printf("0 XOR 1: %d\n", XOR(0, 1));
	printf("0 XOR 0: %d\n", XOR(0, 0));

	printf("\n1 HALFSUM 1: %d\n", HALFSUM(1, 1));
	printf("1 HALFSUM 0: %d\n", HALFSUM(1, 0));
	printf("0 HALFSUM 1: %d\n", HALFSUM(0, 1));
	printf("0 HALFSUM 0: %d\n", HALFSUM(0, 0));

	printf("\n1 HALFCARRY 1: %d\n", HALFCARRY(1, 1));
	printf("1 HALFCARRY 0: %d\n", HALFCARRY(1, 0));
	printf("0 HALFCARRY 1: %d\n", HALFCARRY(0, 1));
	printf("0 HALFCARRY 0: %d\n", HALFCARRY(0, 0));

	printf("\n1 FULLSUM 1 CARRY 1: %d\n", FULLSUM(1, 1, 1));
	printf("1 FULLSUM 1 CARRY 0: %d\n", FULLSUM(1, 1, 0));
	printf("1 FULLSUM 0 CARRY 1: %d\n", FULLSUM(1, 0, 1));
	printf("1 FULLSUM 0 CARRY 0: %d\n", FULLSUM(1, 0, 0));
	printf("0 FULLSUM 1 CARRY 1: %d\n", FULLSUM(0, 1, 1));
	printf("0 FULLSUM 1 CARRY 0: %d\n", FULLSUM(0, 1, 0));
	printf("0 FULLSUM 0 CARRY 1: %d\n", FULLSUM(0, 0, 1));
	printf("0 FULLSUM 0 CARRY 0: %d\n", FULLSUM(0, 0, 0));
	
	printf("\n1 FULLCARRY 1 CARRY 1: %d\n", FULLCARRY(1, 1, 1));
	printf("1 FULLCARRY 1 CARRY 0: %d\n", FULLCARRY(1, 1, 0));
	printf("1 FULLCARRY 0 CARRY 1: %d\n", FULLCARRY(1, 0, 1));
	printf("1 FULLCARRY 0 CARRY 0: %d\n", FULLCARRY(1, 0, 0));
	printf("0 FULLCARRY 1 CARRY 1: %d\n", FULLCARRY(0, 1, 1));
	printf("0 FULLCARRY 1 CARRY 0: %d\n", FULLCARRY(0, 1, 0));
	printf("0 FULLCARRY 0 CARRY 1: %d\n", FULLCARRY(0, 0, 1));
	printf("0 FULLCARRY 0 CARRY 0: %d\n", FULLCARRY(0, 0, 0));
	
}
Example #10
0
char FULLSUM(char input1, char input2, char input3)
{
	char sum;

	sum = XOR(XOR(input1, input2), input3);

	return sum;
}
Example #11
0
void gc_set_foreground_xor(GdkGC *gc, GdkColor *col1, GdkColor *col2)
{ 
  GdkColor newcol;
  newcol.pixel = XOR(col1->pixel, col2->pixel);
  newcol.red = XOR(col1->red, col2->red);
  newcol.green = XOR(col1->green, col2->green);
  newcol.blue = XOR(col1->blue, col2->blue);
  gdk_gc_set_foreground(gc, gdk_color_copy(&newcol)); /* memleak? */
}
void fb_addd_low(dig_t *c, const dig_t *a, const dig_t *b, int size) {
	if (size == 2 * FB_DIGS) {
		*(__m128i *)c = XOR(*(__m128i*)(a), *(__m128i*)(b));
		*(__m128i *)(c + 2) = XOR(*(__m128i*)(a + 2), *(__m128i*)(b + 2));
		*(__m128i *)(c + 4) = XOR(*(__m128i*)(a + 4), *(__m128i*)(b + 4));
		*(__m128i *)(c + 6) = XOR(*(__m128i*)(a + 6), *(__m128i*)(b + 6));
	} else {
		for (int i = 0; i < size; i++, a++, b++, c++) {
			(*c) = (*a) ^ (*b);
		}
	}
}
Example #13
0
unsigned long long MDC4(unsigned long long *x, unsigned int t)
{
   // Divide x em blocos de 64 bits (ja esta)
   //Define IV e N_IV
   unsigned long long IV = 0x5252525252525252, N_IV = 0x2525252525252525;
   int i;
   unsigned long long G[t+1], N_G[t+1], K[t+1], N_K[t+1], C[t+1], N_C[t+1];
   unsigned long long J[t+1], N_J[t+1];
   G[0] = IV;
   N_G[0] = N_IV;
   for (i = 1; i <= t; i++)
   {
      // IGUAL AO MDC2
      K[i] = g(G[i-1], NOT_INVERTED);
      N_K[i] = g(N_G[i-1], INVERTED);
            
      // des ao plaintext x[i] com chave K[i]
      C[i] = XOR(DES(x[i], K[i]), x[i]);
      N_C[i] = XOR(DES(x[i], N_K[i]), x[i]);
      
      unsigned long long CL, CR, N_CL, N_CR;
      CL = C[i] >> 32; // Left 32 bits de C[i]
      CR = C[i] & 0x80000000; // Right 32 bits de C[i]
      N_CL = N_C[i] >> 32;
      N_CR = N_C[i] & 0x80000000;
      
      // Concatena
      H[i] = (CL << 32) | N_CR;
      N_H[i] = (N_CL << 32) | CR;
      
      // NOVO PEDACO
      J[i] = g(H[i], NOT_INVERTED);
      N_J[i] = g(N_H[i], INVERTED);
      
      D[i] = XOR(DES(N_G[i-1], J[i]), N_G[i-1]);
      N_D[i] = XOR(DES(G[i-1], N_J[i]), G[i-1]);
      
      // Divide em duas partes
      unsigned long DL, DR, N_DL, N_DR;
      DL = D[i] >> 32; // Left 32 bits de C[i]
      DR = D[i] & 0x80000000; // Right 32 bits de C[i]
      N_DL = N_D[i] >> 32;
      N_DR = N_D[i] & 0x80000000;
      
      //Concatena
      G[i] = (DL<<32) | N_DR;
      N_G[i] =  (N_DL<<32) | DR;
      
   }
   printf("OUTPUT:%llX\n", (G[t]<<32)|(N_G[t]));
}
Example #14
0
File: CCM.c Project: SepOwnage/P-O5
 /*
 * Decrypt the given ciphermessage, update receiver context and output
 * decryption in payload.
 *
 * payload              pointer to output array with size >= ciphermessage - MAC_LENGTH
 * payload_size         size of the output payload
 * ENC_receiver_ctx     pointer to the encoding receiver context
 * ciphermessage        pointer to the encrypted input message
 */
 void CCM_decrypt(void *payloadin, unsigned int *payload_size,  ENC_ctx *ENC_receiver_ctx, const message_ctx *ciphermessage){
    unsigned char *payload = payloadin;

    unsigned char MAC[MAC_LENGTH], MAC_check[MAC_LENGTH];
    unsigned char temp[ (1+((MAX_MESSAGE_LENGTH*2 - MAC_LENGTH-1)/BLOCK_LENGTH)+2)*BLOCK_LENGTH];
    unsigned char temp_payload[MAX_MESSAGE_LENGTH*2 - MAC_LENGTH];

    //check of message is not sended again:
    if (ENC_receiver_ctx->counter>=ciphermessage->seq_number){
        if (PRINT_errors == 1){
                printf("\n");
                printf("resending of message");
                printf("\n \n");};
        *payload_size = 0;
        return;
    };

    if (ciphermessage->length <= MAC_LENGTH){
        if (PRINT_errors == 1){
                printf("\n");
                printf("invalid1\n");
                printf("\n \n");};
        *payload_size = 0;
        return;
        };

    // set Nonce counter part to the received counter part (small endian)
    memcpy(ENC_receiver_ctx->nonce+2, &ciphermessage->seq_number, 4);

    create_cyphered_counter_block(temp, ENC_receiver_ctx->key, ENC_receiver_ctx->nonce, (ciphermessage->length -MAC_LENGTH-1)/BLOCK_LENGTH + 2);

    XOR(MAC, ((unsigned char *) (ciphermessage->data)) + ciphermessage->length-MAC_LENGTH,temp, MAC_LENGTH);
    XOR(temp_payload, ciphermessage->data, temp+BLOCK_LENGTH, ciphermessage->length - MAC_LENGTH);

    formatData(temp, ENC_receiver_ctx->nonce ,temp_payload, ciphermessage->length - MAC_LENGTH);

    generateMAC(MAC_check, ENC_receiver_ctx->key,temp,2+(ciphermessage->length - MAC_LENGTH-1)/BLOCK_LENGTH + 1);

    if (memcmp(MAC, MAC_check, MAC_LENGTH) != 0){
        if (PRINT_errors == 1){
                printf("\n");
                printf("invalid2\n");
                printf("\n \n");};
        *payload_size = 0;
        return;
    };
    ENC_receiver_ctx->counter =  ciphermessage->seq_number;
    *payload_size = ciphermessage->length - MAC_LENGTH;
    memcpy(payload,temp_payload, *payload_size);
 }
Example #15
0
void insert(struct node** head,int n)
{
    struct node* new_node=(struct node*)malloc(sizeof(struct node));
    new_node->data=n;
    new_node->npx=XOR(*head,NULL);

    if(*head!=NULL)
    {
        struct node* next=XOR((*head)->npx,NULL);
        (*head)->npx=XOR(new_node,next);
    }

    *head=new_node;
}
Example #16
0
//By XOR
//XOR of two same numbers gives 0
int MissingByXor(int *a, int size)
{
	int i = 0;
	int Xor1 = a[0];
	int Xor2 = 1;

	for(i = 1; i < size; i++)
		Xor1 = XOR(Xor1, a[i]); 

	for(i = 2; i <= size+1; i++)
		Xor2 = XOR(Xor2, i);

	
	return XOR(Xor1, Xor2);
}
Example #17
0
// skipped some of the special handling in here - if we get crashes, let the interpreter handle this
// op
void JitILBase::divwux(UGeckoInstruction inst)
{
	// FIXME
	FALLBACK_IF(true);

#if 0
	int a = inst.RA, b = inst.RB, d = inst.RD;
	gpr.FlushLockX(RSCRATCH1);
	gpr.Lock(a, b, d);

	if (d != a && d != b)
	{
		gpr.LoadToX64(d, false, true);
	}
	else
	{
		gpr.LoadToX64(d, true, true);
	}

	MOV(32, R(RSCRATCH), gpr.R(a));
	XOR(32, R(RSCRATCH2), R(RSCRATCH));
	gpr.KillImmediate(b);
	DIV(32, gpr.R(b));
	MOV(32, gpr.R(d), R(RSCRATCH));
	gpr.UnlockAll();
	gpr.UnlockAllX();

	if (inst.Rc)
	{
		CALL((u8*)asm_routines.computeRc);
	}
#endif
}
Example #18
0
main()
{
int count=0,copy,n,A[10],B[10],i,temp;
printf("Enter Binary Number \n");
scanf("%d",&n);
copy = n;
while (copy!=0)
{
A[count++] = copy%10;
copy/=10;
}
printf("%d\n",count);
for (i=0;i<count/2;i++) 
{
temp = A[i];
A[i] = A[count-i-1];
A[count-i-1] = temp;
}
B[0] = A[0];
for (i=1;i<count;i++) B[i] = XOR(A[i-1],A[i]);
printf("Entered Number Is : \n");
for (i=0;i<count;i++) printf("%d ",A[i]);
printf("\n");
printf("Gray Code Of Entered Number Is : \n");
for (i=0;i<count;i++) printf("%d ",B[i]);
printf("\n");
return;
}
Example #19
0
int CNTReader::SendCommand(const byte *sbuff,short slen,unsigned char * rbuff,short *rlen,int timeout)
{
    unsigned char sCmd[512]= {0},sResp[512]= {0};
    int  nCmdLen=0;
    if(!IsOpen())
        return PORT_NOTOPEN_ERROR;
    sCmd[0]=0x02;
    sCmd[1]=slen/256;
    sCmd[2]=slen%256;
    memcpy(sCmd+3,sbuff,slen);
    nCmdLen=3+slen;
    sCmd[nCmdLen]=XOR(sbuff,slen);
    nCmdLen++;
    sCmd[nCmdLen]=0x03;
    nCmdLen++;
    if( !PostSend(sCmd,nCmdLen,timeout))
    {
        return SEND_DATA_ERROR;
    }
    //Sleep(80);
    if( !PostRecv(sResp,sizeof(sResp),timeout))
    {
        return RECV_DATA_ERROR;
    }
//Resp:数据长度(2字节)+状态码(2字节)+数据
    *rlen=sResp[0]*256+sResp[1]-2;	//去掉2字节状态码
    if(*rlen>256)
        *rlen=256;
    if(*rlen>0) memcpy(rbuff,sResp+4,*rlen);
    return sResp[2]*256+sResp[3];
}
Example #20
0
static
	void FillWindowsVersionArea(uint8_t area[20])
{
	const uint8_t WinVersion[20] = "r70393861";
	memcpy(area, WinVersion, 20);
	XOR(area, 20, H3C_KEY, strlen(H3C_KEY));
}
Example #21
0
// compute gradient magnitude and orientation at each location (uses sse)
void gradMag( float *I, float *M, float *O, int h, int w, int d ) {
  int x, y, y1, c, h4, s; float *Gx, *Gy, *M2; __m128 *_Gx, *_Gy, *_M2, _m;
  float *acost = acosTable(), acMult=25000/2.02f;
  // allocate memory for storing one column of output (padded so h4%4==0)
  h4=(h%4==0) ? h : h-(h%4)+4; s=d*h4*sizeof(float);
  M2=(float*) alMalloc(s,16); _M2=(__m128*) M2;
  Gx=(float*) alMalloc(s,16); _Gx=(__m128*) Gx;
  Gy=(float*) alMalloc(s,16); _Gy=(__m128*) Gy;
  // compute gradient magnitude and orientation for each column
  for( x=0; x<w; x++ ) {
    // compute gradients (Gx, Gy) and squared magnitude (M2) for each channel
    for( c=0; c<d; c++ ) grad1( I+x*h+c*w*h, Gx+c*h4, Gy+c*h4, h, w, x );
    for( y=0; y<d*h4/4; y++ ) _M2[y]=ADD(MUL(_Gx[y],_Gx[y]),MUL(_Gy[y],_Gy[y]));
    // store gradients with maximum response in the first channel
    for(c=1; c<d; c++) {
      for( y=0; y<h4/4; y++ ) {
        y1=h4/4*c+y; _m = CMPGT( _M2[y1], _M2[y] );
        _M2[y] = OR( AND(_m,_M2[y1]), ANDNOT(_m,_M2[y]) );
        _Gx[y] = OR( AND(_m,_Gx[y1]), ANDNOT(_m,_Gx[y]) );
        _Gy[y] = OR( AND(_m,_Gy[y1]), ANDNOT(_m,_Gy[y]) );
      }
    }
    // compute gradient mangitude (M) and normalize Gx
    for( y=0; y<h4/4; y++ ) {
      _m = MIN( RCPSQRT(_M2[y]), SET(1e10f) );
      _M2[y] = RCP(_m);
      _Gx[y] = MUL( MUL(_Gx[y],_m), SET(acMult) );
      _Gx[y] = XOR( _Gx[y], AND(_Gy[y], SET(-0.f)) );
    };
    memcpy( M+x*h, M2, h*sizeof(float) );
    // compute and store gradient orientation (O) via table lookup
    if(O!=0) for( y=0; y<h; y++ ) O[x*h+y] = acost[(int)Gx[y]];
  }
  alFree(Gx); alFree(Gy); alFree(M2);
}
Example #22
0
	void enframe(packet p,int seq){

	 frame s;
		int i;
		s.checksum = (char)NULL;
		s.seq = 0;
		s.eop = 0;
		for (i = 0; i<=23;i++){
		s.data.load[i] = (char)NULL;
		}

		s.type=data;
		s.seq=seq;

		s.data=p;
		s.eop=p.eop;
		s.checksum=XOR(s);
		
		enqueued(s);
		enqueuef(s);
		
		if(seven==6){
			s = error(s);
			seven=0;
		}else{
			seven++;
		}
		

		to_physical_layer(s);

	}
bool PolynomialLeader::isElementInAllSets(uint32_t index, uint32_t binIndex, uint32_t tableIndex, uint32_t hashFuncIndex, uint8_t *secret, bf_info *specInfo) {

    GF2E::init(m_irreduciblePolynomial);

    for (auto &party : m_parties) {
        XOR(secret, m_leaderResults[party.first].get()+tableIndex*m_maskSizeInBytes, m_maskSizeInBytes);

        NTL::GF2E element = PolynomialUtils::convertBytesToGF2E(m_elements.get()+index*m_elementSize,m_elementSize);
        GF2E value = eval(*(m_partiesPolynomials[party.first][hashFuncIndex].get()),element);
        vector<uint8_t> arr = PolynomialUtils::convertElementToBytes(value);

        XOR(secret, arr.data(), m_maskSizeInBytes);
    }

    return isZero(secret, m_maskSizeInBytes);
}
Example #24
0
node* insertAtStart(node** head,int data)
{
		node* temp = NULL;

	temp = (node*)malloc(sizeof(node));
	temp->data = data;
	temp->addr = XOR(NULL,*head);

	if(*head!=NULL)
	{
		(*head)->addr = XOR(temp,XOR((*head)->addr,NULL));
	}

	*head = temp;
	return *head;
}
Example #25
0
bool region_set_activity(WRegion *reg, int sp)
{
    bool set=(reg->flags&REGION_ACTIVITY);
    bool nset=libtu_do_setparam(sp, set);

    if(!XOR(set, nset))
        return nset;

    if(nset){
        if(REGION_IS_ACTIVE(reg))
            return FALSE;

        reg->flags|=REGION_ACTIVITY;
        objlist_insert_last(&actlist, (Obj*)reg);

        if(reg->mgd_activity==0)
            propagate_activity(reg);
    }else{
        reg->flags&=~REGION_ACTIVITY;
        objlist_remove(&actlist, (Obj*)reg);

        if(reg->mgd_activity==0)
            propagate_clear(reg);
    }

    region_notify_change(reg, ioncore_g.notifies.activity);

    return nset;
}
Example #26
0
inline void LPSX(WORD *dst, const WORD *chunk)
{
	XOR(dst, chunk);
	S(dst);
	P(dst);
	L(dst);
}
Example #27
0
void main()
{
 int a,b,ch,o;

 printf("\n-:MENU:-\n1.AND\n2.OR\n3.NOT\n4.XOR\n0.Exit\n");
 do{
    printf("\nEnter Choice:");
    scanf("%d",&ch);

    switch(ch)
     {
      case 1:
             printf ("\nTruth Table for AND\nA B  \tO");
             for(a=0;a<=1;a++)
             {
              for(b=0;b<=1;b++)
                { 
                  o=AND(a,b);
                  printf("\n%d %d \t%d",a,b,o);
                }
             }
              break;
      case 2:
             printf ("\nTruth Table for OR\nA B  \tO");
             for(a=0;a<=1;a++)
             {
              for(b=0;b<=1;b++)
                {
                o=OR(a,b);
                printf("\n%d %d \t%d",a,b,o);
                }
             }
              break;
      case 3: 
             printf ("\nTruth Table for NOT\nA  \tO");
             for(a=0;a<=1;a++)
             {
             o=NOT(a);
             printf("\n%d  \t%d",a,o);
             }
              break;
      case 4:
             printf ("\nTruth Table for XOR\nA B  \tO");
             for(a=0;a<=1;a++)
             {
              for(b=0;b<=1;b++)
                {
                o=XOR(a,b);
                printf("\n%d %d \t%d",a,b,o);
                }
             }
              break;

      case 0: exit();
              break;
             default: printf("\nError");
             }
      }while(ch!=0);

}
Example #28
0
/* Returns 1 if there is a chance that the result is right
 * Returns 0 otherwise and stops before finishing the computation
 */
int decode(char result[SIZE+1], const char key[4]) {
	int i = 0;

	for (i = 0; i < SIZE; i++) {
		result[i] = XOR(cipher[i], key[i%3]);
		/*characters lower than 9 have few chances to appear in a string*/
		/*except the final one that might be 0*/
		if (i < SIZE - 1) {
			if (result[i] < 8) {
				return 0;
			}
			else {
				switch(result[i]) {
					case '{':
					case '}':
					case '#':
					case '`':
						return 0;
					default:
						break;
				}
			}
		}
	}
	result[SIZE] = '\0';
	return 1;
}
Example #29
0
void deleteFirst(node** head)
{
		node* nextNode = NULL;

	if(*head==NULL) return;
	nextNode = XOR(NULL,(*head)->addr);
	if(nextNode == NULL)
	{
		*head = NULL;
		return;
	}

	nextNode->addr = XOR(nextNode->addr,(*head));
	*head = nextNode;

}
Example #30
0
void calculate_trap(u8 new_data[], block* b)
{
    int i,j;
    bool binary_data_new[8],binary_data_old[8];
    bool binary_trap[8];

    void convert_binary(u8, bool []);
    bool XOR(bool, bool);
    u8 convert_char(bool []);

    if(b->index==0)
    {
        copy(b->trap_index[b->index].trap_data,new_data);
        copy(b->curr_data,new_data);
    }
    else
    {
        for(i=0; i<DATA_SIZE; i++)
        {
            convert_binary(new_data[i],binary_data_new);
            convert_binary(b->curr_data[i],binary_data_old);

            for(j=0; j<8; j++)
            {
                binary_trap[j]=XOR(binary_data_new[j],binary_data_old[j]);
            }

            b->trap_index[b->index].trap_data[i]=convert_char(binary_trap);
        }
    }

    time(&b->trap_index[b->index].time_trap);
}