Exemple #1
0
XMoshSum digestBlock( hp_byte* initialByteBlock, XMoshSum sum )
{

	sha2_word block[ ROUNDS ];

	sha2_word* words = ( sha2_word* ) &sum.data;

	for( unsigned int i = 0; i < 16; i++ )
	{
		BLOCK_COPY( block, initialByteBlock, i );
	}

	for( unsigned i = 16; i < ROUNDS; i++ )
	{
		block[ i ] = block[ i - 16 ]
				+ SIGMA0( block, i ) + block[ i - 7 ] + SIGMA1( block, i );
	}

	sha2_word a = words[ 0 ];
	sha2_word b = words[ 1 ];
	sha2_word c = words[ 2 ];
	sha2_word d = words[ 3 ];
	sha2_word e = words[ 4 ];
	sha2_word f = words[ 5 ];
	sha2_word g = words[ 6 ];
	sha2_word h = words[ 7 ];

	sha2_word temp1, temp2;

	for( unsigned i = 0; i < ROUNDS; i++ )
	{

		temp1 = ( h + ( SUM1( e ) ) + CH( e, f, g ) + K[ i ] + block[ i ] );
		temp2 = ( SUM0( a ) ) + MAJ( a, b, c );

		h = g;
		g = f;
		f = e;
		e = d + temp1;
		d = c;
		c = b;
		b = a;
		a = temp1 + temp2;
	}

	words[ 0 ] += a;
	words[ 1 ] += b;
	words[ 2 ] += c;
	words[ 3 ] += d;
	words[ 4 ] += e;
	words[ 5 ] += f;
	words[ 6 ] += g;
	words[ 7 ] += h;

	return sum;
}
Exemple #2
0
int create_csv_line(px_header *header, px_fieldInfo **felder, px_records block, char *blobname)
{
	int i, block_index = 0;

#define BLOCK_COPY(x,size) \
		memcpy(x,   block + block_index, size); \
		/*fprintf(stderr, "\nBl-IDX1: %04x - ",block_index);*/ \
		block_index += size;

	for (i = 0; i < header->numFields; i++ )
	{
		//		fprintf(stderr, "%02d: %d - ", felder[i]->type, felder[i]->size);
		if (i > 0)
			putchar(delim);
		if (felder[i]->type == PX_Field_Type_Alpha)
		{
			char *str = malloc(felder[i]->size + 1);
			char *qstr = malloc(felder[i]->size*2 + 1);
			BLOCK_COPY(str, felder[i]->size);
			str[felder[i]->size] = '\0';

			PXtoCSVString(qstr, str, felder[i]->type);
			PXtoQuotedString(qstr, qstr, felder[i]->type);
			printf("\"%s\"", qstr);

			free(qstr);
			free(str);
		}
		else if (felder[i]->type == PX_Field_Type_ShortInt)
		{
			unsigned short s;
			unsigned long long d;

			BLOCK_COPY(&s, felder[i]->size);

			switch(PXtoLong(s, &d, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%Ld", d );
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}

		}
		else if (felder[i]->type == PX_Field_Type_Logical)
		{
			unsigned char s;
			unsigned long long d;

			BLOCK_COPY(&s, felder[i]->size);

			switch(PXtoLong(s, &d, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%Lx", d);
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}
		}
		else if (felder[i]->type == PX_Field_Type_LongInt)
		{
			unsigned long s;
			unsigned long long d;

			BLOCK_COPY(&s, felder[i]->size);

			switch(PXtoLong(s, &d, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%Ld", d);
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}
		}
		else if (felder[i]->type == PX_Field_Type_Incremental)
		{
			unsigned long s;
			unsigned long long d;

			BLOCK_COPY(&s, felder[i]->size);

			switch(PXtoLong(s, &d, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%Ld", d);
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}
		}
		else if (felder[i]->type == PX_Field_Type_Number)
		{
			unsigned long long s;
			double d;

			BLOCK_COPY(&s, felder[i]->size);

			switch(PXtoDouble(s, &d, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%f", d );
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}

		}
		else if (felder[i]->type == PX_Field_Type_Currency)
		{
			unsigned long long s;
			double d;

			BLOCK_COPY(&s, felder[i]->size);

			switch(PXtoDouble(s, &d, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%f", d );
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}
		}
		else if (felder[i]->type == PX_Field_Type_Date)
		{
			unsigned long long s;
			struct tm _tm;

			BLOCK_COPY(&s, felder[i]->size);

			switch (PXtoTM(s, &_tm, felder[i]->type))
			{
			    case VALUE_OK:
				printf("'%04i-%02i-%02i'", _tm.tm_year+1900, _tm.tm_mon+1, _tm.tm_mday);
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}

		}
		else if (felder[i]->type == PX_Field_Type_Time)
		{
			unsigned long long s;
			struct tm _tm;

			BLOCK_COPY(&s, felder[i]->size);

			switch (PXtoTM(s, &_tm, felder[i]->type))
			{
			    case VALUE_OK:
				printf("%02i:%02i:%02i'",_tm.tm_hour, _tm.tm_min, _tm.tm_sec);
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}
		}
		else if (felder[i]->type == PX_Field_Type_Timestamp)
		{
			unsigned long long s;
			struct tm _tm;

			BLOCK_COPY(&s, felder[i]->size);

			switch (PXtoTM(s, &_tm, felder[i]->type))
			{
			    case VALUE_OK:
				printf("'%04i-%02i-%02i ", _tm.tm_year+1900, _tm.tm_mon+1, _tm.tm_mday);
				printf("%02i:%02i:%02i'",_tm.tm_hour, _tm.tm_min, _tm.tm_sec);
				break;
			    case VALUE_IS_NULL:
				printf("NULL");
				break;
			    default:
				break;
			}
		}
		else if (felder[i]->type == PX_Field_Type_MemoBLOB)
		{
			void *blob = malloc(felder[i]->size);
			char *s = NULL;

			BLOCK_COPY(blob, felder[i]->size);

			s = PXMEMOtoString(blob, felder[i]->size, blobname);

			if (s != NULL)
			{
				char *qstr = malloc(strlen(s)*2 + 1);
				PXtoCSVString(qstr, s, felder[i]->type);
				PXtoQuotedString(qstr, qstr, felder[i]->type);
				printf("\"%s\"",qstr);
				free(s);
				free(qstr);
			}
			else
			{
				char *qstr = malloc(strlen((char *)blob)*2 + 1);
				PXtoCSVString(qstr, (char *)blob, felder[i]->type);
				PXtoQuotedString(qstr, qstr, felder[i]->type);
				printf("\"%s\"",qstr);
				free(qstr);
			}
			free(blob);
		}
		else if (felder[i]->type == PX_Field_Type_Graphic ||
			 felder[i]->type == PX_Field_Type_BinBLOB)
		{
			void *blob = malloc(felder[i]->size);
			int s_size;
			void *s = NULL;

			BLOCK_COPY(blob, felder[i]->size);

			PXBLOBtoBinary(blob, felder[i]->size, blobname, &s, &s_size);

			if (s)
			{
				int fd;
				char fn[255];
				static int gra_cnt = 0;
				sprintf(fn, "/tmp/pxtools.%d-%d.bin", getpid(), gra_cnt++);
				if ((fd = open(fn,
					       O_WRONLY | O_CREAT,
					       S_IRWXU | S_IRGRP | S_IROTH
					       )) == -1)
				{
					fprintf(stderr, "%s.%d: can't open %s: %s\n",
						__FILE__, __LINE__,
						fn,
						strerror(errno));
				}
				else
				{
					write(fd, s, s_size);
					close(fd);
				}
				printf("\"file:/%s\"", fn);
			}
			else
			{
				fprintf(stderr, "%s.%d: block is empty !!\n",
					__FILE__, __LINE__);
			}

			free(blob);
		}
		else
		{
			fprintf(stderr, "\nUnknown: type: %d, size: %d\n",felder[i]->type, felder[i]->size);
			block_index += felder[i]->size;
			fprintf(stderr, "Name: %s\n", felder[i]->name);
		}
		//		fprintf(stderr, "\n");
	}
#undef BLOCK_COPY

	printf("\n");

	return 0;
}