cli::Error_e cmdRHash( CLIARGS args, cli::Param_t prm) { ValStore<char> VS; MemBuf mb; std::string s; UINT uint4 = 0; __int64 uint8 = 0; char bindata[] = "ABCDEFGHIJKLM" ; VS.SetVal( "binary", (PBYTE)bindata, strlen(bindata) ); VS.SetVal( "uint4" , (UINT)12345678 ); VS.SetVal( "uint8" , (__int64)12345678901234L ); VS.SetVal( "string", "Hello World!" ); VS.GetVal( "binary", mb ); printf( "binary = %s\n", FmtHex( s, mb, mb.size() )); VS.GetVal( "uint4" , uint4 ); printf( "uint4 = %u\n", uint4 ); VS.GetVal( "uint8" , uint8 ); printf( "uint8 = %I64u\n", uint8 ); VS.GetVal( "string", s ); printf( "string = %s\n", s.c_str() ); VS.Serialize ( "valStore000" ); VS.Deserialize( "valStore000" ); VS.GetVal( "binary", mb ); printf( "binary = %s\n", FmtHex( s, mb, mb.size() )); VS.GetVal( "uint4" , uint4 ); printf( "uint4 = %u\n", uint4 ); VS.GetVal( "uint8" , uint8 ); printf( "uint8 = %I64u\n", uint8 ); VS.GetVal( "string", s ); printf( "string = %s\n", s.c_str() ); return cli::ERR_NOERROR; }
// ---------------------------------------------------------------------------- // Password-based key derivation algorithm. // - text : typically, a user-entered password or phrase // - salt : caller's "entropy" // - count : number of times to iterate the hashing loop. // - length: the desired number of bytes in the returned byte array // - out : memory buffer filled with the requested number of bytes // ---------------------------------------------------------------------------- BYTE *PBKDF2(PCBYTE text, int textlen, PCBYTE salt, int saltlen, int count, int length, BYTE *out) { // Loop until we've generated the requested number of bytes. UINT more = length; for (int i=1; 0<more; i++) { // Where the magic happens. MemBuf outF; F( MemBuf( text, (UINT)textlen ), MemBuf( salt, (UINT)saltlen), count, i, outF ); // Append as many bytes of hash as needed to the key buffer. UINT nCopyCount = min(more, outF.size()); memcpy( &out[length-more], outF, nCopyCount); // Reduce the "more" counter by the number of bytes we just copied. more -= nCopyCount; } return out; }
/*# @method CreateCursor SDL @brief Gets currently active cursor. @param mbData MemBuf containing visual bit data. @param mbMask Membuf containing visibility mask data. @param width Width of the cursor. @param height Height of the cursor. @param Xspot X position of the cursor hotspot. @param Yspot Y position of the cursor hotspot. @raise SDLError if the cursor couldn't be created. See SDL_CreateCursor documentation. Method @a SDL.MakeCursor is probably simpler to use. */ FALCON_FUNC sdl_CreateCursor( ::Falcon::VMachine *vm ) { Item *i_data, *i_mask; Item *i_width, *i_height, *i_xspot, *i_yspot; if( vm->paramCount() < 6 || ! (i_data = vm->param(0) )->isMemBuf() || ! (i_mask = vm->param(1) )->isMemBuf() || ! (i_width = vm->param(2) )->isOrdinal() || ! (i_height = vm->param(3) )->isOrdinal() || ! (i_xspot = vm->param(4) )->isOrdinal() || ! (i_yspot = vm->param(5) )->isOrdinal() ) { throw new ParamError( ErrorParam( e_inv_params, __LINE__ ). extra( "M,M,N,N,N,N" ) ) ; return; } MemBuf *data = i_data->asMemBuf(); MemBuf *mask = i_mask->asMemBuf(); // we are not interested in their word size. if( data->size() || data->size() != mask->size() ) { throw new ParamError( ErrorParam( e_param_type, __LINE__ ). extra( "Membuf must be of same size" ) ) ; return; } int width = (int) i_width->forceInteger(); int height = (int) i_height->forceInteger(); int xspot = (int) i_xspot->forceInteger(); int yspot = (int) i_yspot->forceInteger(); if( width < 8 || height < 1 || width % 8 != 0 ) { throw new ParamError( ErrorParam( e_param_type, __LINE__ ). extra( "Invalid sizes" ) ) ; return; } if( data->size() != (uint32)( width/8 * height ) ) { throw new ParamError( ErrorParam( e_param_type, __LINE__ ). extra( "Membuf doesn't match width and height" ) ) ; return; } if( xspot < 0 || xspot >= width || yspot < 0 || yspot >= height ) { throw new ParamError( ErrorParam( e_param_type, __LINE__ ). extra( "Hotspot outside cursor" ) ) ; return; } // ok, all fine ::SDL_Cursor *cursor = SDL_CreateCursor( (Uint8 *) data->data(), (Uint8 *) mask->data(), width, height, xspot, yspot ); if ( cursor == 0 ) { throw new SDLError( ErrorParam( FALCON_SDL_ERROR_BASE + 11, __LINE__ ) .desc( "SDL Create Cursor" ) .extra( SDL_GetError() ) ) ; return; } Item *cls = vm->findWKI( "SDLCursor" ); fassert( cls != 0 ); CoreObject *obj = cls->asClass()->createInstance(); obj->setUserData( new SDLCursorCarrier( cursor, true ) ); vm->retval( obj ); }