static HB_BOOL hb_i18n_headercheck( const char * pBuffer, HB_SIZE nLen ) { if( nLen < HB_I18N_HEADER_SIZE ) return HB_FALSE; nLen -= HB_I18N_HEADER_SIZE; return memcmp( pBuffer, s_signature, HB_I18N_SIG_SIZE ) == 0 && ( nLen == 0 || ( HB_GET_LE_UINT32( &pBuffer[ HB_I18N_SIZE_OFFSET ] ) == nLen && HB_GET_LE_UINT32( &pBuffer[ HB_I18N_CRC_OFFSET ] ) == hb_crc32( 0, pBuffer + HB_I18N_HEADER_SIZE, nLen ) ) ); }
void hb_xfree( void * pMem ) /* frees fixed memory */ { if( pMem ) { #ifdef HB_FM_STATISTICS PHB_MEMINFO pMemBlock = ( PHB_MEMINFO ) ( ( HB_BYTE * ) pMem - HB_MEMINFO_SIZE ); if( pMemBlock->Signature != HB_MEMINFO_SIGNATURE ) hb_errInternal( HB_EI_XFREEINV, "hb_xfree called with an invalid pointer", NULL, NULL ); if( HB_GET_LE_UINT32( ( ( HB_BYTE * ) pMem ) + pMemBlock->nSize ) != HB_MEMINFO_SIGNATURE ) hb_errInternal( HB_EI_XMEMOVERFLOW, "Memory buffer overflow", NULL, NULL ); s_nMemoryConsumed -= pMemBlock->nSize; s_nMemoryBlocks--; if( s_pMemBlocks == pMemBlock ) s_pMemBlocks = pMemBlock->pNextBlock; else pMemBlock->pPrevBlock->pNextBlock = pMemBlock->pNextBlock; if( pMemBlock->pNextBlock ) pMemBlock->pNextBlock->pPrevBlock = pMemBlock->pPrevBlock; pMemBlock->Signature = 0; HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pMem ) + pMemBlock->nSize, 0 ); pMem = ( HB_BYTE * ) pMem - HB_MEMINFO_SIZE; #endif free( pMem ); } else hb_errInternal( HB_EI_XFREENULL, "hb_xfree called with a NULL pointer", NULL, NULL ); }
void * hb_xrealloc( void * pMem, HB_SIZE nSize ) /* reallocates memory */ { #ifdef HB_FM_STATISTICS PHB_MEMINFO pMemBlock; HB_SIZE nMemSize; void * pResult; if( nSize == 0 ) { if( pMem ) hb_xfree( pMem ); return NULL; } else if( ! pMem ) return hb_xgrab( nSize ); pMemBlock = ( PHB_MEMINFO ) ( ( HB_BYTE * ) pMem - HB_MEMINFO_SIZE ); nMemSize = pMemBlock->nSize; if( pMemBlock->Signature != HB_MEMINFO_SIGNATURE ) hb_errInternal( HB_EI_XREALLOCINV, "hb_xrealloc called with an invalid pointer", NULL, NULL ); if( HB_GET_LE_UINT32( ( ( HB_BYTE * ) pMem ) + nMemSize ) != HB_MEMINFO_SIGNATURE ) hb_errInternal( HB_EI_XMEMOVERFLOW, "Memory buffer overflow", NULL, NULL ); HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pMem ) + nMemSize, 0 ); pResult = realloc( pMemBlock, nSize + HB_MEMINFO_SIZE + sizeof( HB_U32 ) ); if( pResult ) { if( s_pMemBlocks == pMemBlock ) s_pMemBlocks = ( PHB_MEMINFO ) pResult; else ( ( PHB_MEMINFO ) pResult )->pPrevBlock->pNextBlock = ( PHB_MEMINFO ) pResult; if( ( ( PHB_MEMINFO ) pResult )->pNextBlock ) ( ( PHB_MEMINFO ) pResult )->pNextBlock->pPrevBlock = ( PHB_MEMINFO ) pResult; s_nMemoryConsumed += ( nSize - nMemSize ); if( s_nMemoryMaxConsumed < s_nMemoryConsumed ) s_nMemoryMaxConsumed = s_nMemoryConsumed; ( ( PHB_MEMINFO ) pResult )->nSize = nSize; /* size of the memory block */ HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pResult ) + nSize + HB_MEMINFO_SIZE, HB_MEMINFO_SIGNATURE ); pResult = ( HB_BYTE * ) pResult + HB_MEMINFO_SIZE; } #else void * pResult = realloc( pMem, nSize ); #endif if( ! pResult && nSize ) hb_errInternal( HB_EI_XREALLOC, "hb_xrealloc can't reallocate memory", NULL, NULL ); return pResult; }
/** * salsa20_8(B): * Apply the salsa20/8 core to the provided block. */ static void salsa20_8(uint8_t B[64]) { uint32_t B32[16]; uint32_t x[16]; size_t i; /* Convert little-endian values in. */ for (i = 0; i < 16; i++) B32[i] = HB_GET_LE_UINT32(&B[i * 4]); /* Compute x = doubleround^4(B32). */ for (i = 0; i < 16; i++) x[i] = B32[i]; for (i = 0; i < 8; i += 2) { #define R(a,b) (((a) << (b)) | ((a) >> (32 - (b)))) /* Operate on columns. */ x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9); x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18); x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9); x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18); x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9); x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18); x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9); x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18); /* Operate on rows. */ x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9); x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18); x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9); x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18); x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9); x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18); x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9); x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18); #undef R } /* Compute B32 = B32 + x. */ for (i = 0; i < 16; i++) B32[i] += x[i]; /* Convert little-endian values out. */ for (i = 0; i < 16; i++) HB_PUT_LE_UINT32(&B[4 * i], B32[i]); }
int main( void ) { char buf[ 16 ]; int n, i, l, f, iRet = 0; printf( "\nStandard C types:\n" ); printf( "\t sizeof(void*)=%d\n", ( int ) sizeof( void * ) ); printf( "\t sizeof(char)=%d\n", ( int ) sizeof( char ) ); printf( "\t sizeof(short int)=%d\n", ( int ) sizeof( short int ) ); printf( "\t sizeof(int)=%d\n", ( int ) sizeof( int ) ); printf( "\t sizeof(long int)=%d\n", ( int ) sizeof( long int ) ); #if defined( HB_OS_WIN ) && ! defined( __GNUC__ ) printf( "\t sizeof(__int64)=%d\n", ( int ) sizeof( __int64 ) ); #else printf( "\tsizeof(long long int)=%d\n", ( int ) sizeof( long long int ) ); #endif printf( "\t sizeof(float)=%d\n", ( int ) sizeof( float ) ); printf( "\t sizeof(double)=%d\n", ( int ) sizeof( double ) ); printf( "\t sizeof(long double)=%d\n", ( int ) sizeof( long double ) ); printf( "\nHarbour types:\n" ); printf( "\t sizeof(HB_BYTE)=%d %s\n", ( int ) sizeof( HB_BYTE ), sizeof( HB_BYTE ) == 1 ? "OK" : "BAD" ); printf( "\t sizeof(HB_SHORT)=%d %s\n", ( int ) sizeof( HB_SHORT ), sizeof( HB_SHORT ) == 2 ? "OK" : "BAD" ); printf( "\t sizeof(HB_UINT)=%d %s\n", ( int ) sizeof( HB_UINT ), sizeof( HB_UINT ) == 4 || sizeof( HB_UINT ) == 8 ? "OK" : "BAD" ); printf( "\t sizeof(HB_LONG)=%d %s\n", ( int ) sizeof( HB_LONG ), sizeof( HB_LONG ) == 4 || sizeof( HB_LONG ) == 8 ? "OK" : "BAD" ); printf( "\tsizeof(HB_LONGLONG)=%d %s\n", ( int ) sizeof( HB_LONGLONG ), sizeof( HB_LONGLONG ) == 8 ? "OK" : "BAD" ); printf( "\t sizeof(double)=%d %s\n", ( int ) sizeof( double ), sizeof( double ) == 8 ? "OK" : "BAD" ); if( sizeof( HB_BYTE ) != 1 || sizeof( HB_SHORT ) != 2 || ( sizeof( HB_LONG ) != 4 && sizeof( HB_LONG ) != 8 ) || sizeof( HB_LONGLONG ) != 8 || sizeof( double ) != 8 ) iRet = 1; n = 0x31323334; memcpy( buf, &n, sizeof( n ) ); buf[ sizeof( n ) ] = '\0'; i = atoi( buf ); #if defined( HB_PDP_ENDIAN ) l = 2143; #elif defined( HB_BIG_ENDIAN ) l = 1234; #else l = 4321; #endif printf( "\nn=0x%x -> \"%s\" (%s endian) %s\n", n, buf, i == 1234 ? "big" : i == 2143 ? "pdp" : i == 4321 ? "little" : "unknown", i == l ? "OK" : "BAD" ); if( i != l ) iRet = 1; buf[ 0 ] = 0x12; buf[ 1 ] = 0x34; buf[ 2 ] = 0x56; buf[ 3 ] = 0x78; buf[ 4 ] = 0x65; i = ( HB_GET_BE_UINT32( buf ) == 0x12345678L && HB_GET_LE_UINT32( buf ) == 0x78563412L ); if( ! i ) iRet = 1; printf( "byte order translation: %s\n", i ? "OK" : "BAD" ); for( l = 0; l < 4; l++ ) { n = HB_GET_BE_UINT16( &buf[ l ] ); f = n == ( buf[ l ] * 256 + buf[ l + 1 ] ) ? 1 : 0; if( ! f ) iRet = 1; printf( "HB_GET_BE_UINT16(%x,%x) = %x -> %s\n", buf[ l ], buf[ l + 1 ], n, f ? "OK" : "BAD" ); n = HB_GET_LE_UINT16( &buf[ l ] ); f = n == ( buf[ l ] + 256 * buf[ l + 1 ] ) ? 1 : 0; if( ! f ) iRet = 1; printf( "HB_GET_LE_UINT16(%x,%x) = %x -> %s\n", buf[ l ], buf[ l + 1 ], n, f ? "OK" : "BAD" ); } n = ( char ) 255; printf( "n=%d -> (char) type is %ssigned\n", n, n < 0 ? "" : "un" ); if( iRet ) printf( "\nHarbour cannot be compiled !!!\n" ); else printf( "\nBasic test is correct, try to compile Harbour.\n" ); return iRet; }