示例#1
0
void Controls_SecondaryMouseDown()
{
    btVector3 from = engine_camera.m_pos;
    btVector3 to = from + btVector3(engine_camera.m_viewDir[0], engine_camera.m_viewDir[1], engine_camera.m_viewDir[2]) * 32768.0;

    std::shared_ptr<EngineContainer> cam_cont = std::make_shared<EngineContainer>();
    cam_cont->room = engine_camera.m_currentRoom;

    BtEngineClosestRayResultCallback cbc(cam_cont);
    //cbc.m_collisionFilterMask = btBroadphaseProxy::StaticFilter | btBroadphaseProxy::KinematicFilter;
    bt_engine_dynamicsWorld->rayTest(from, to, cbc);
    if(cbc.hasHit())
    {
        extern GLfloat cast_ray[6];

        btVector3 place;
        place.setInterpolate3(from, to, cbc.m_closestHitFraction);
        std::copy(place+0, place+3, cast_ray);
        cast_ray[3] = cast_ray[0] + 100.0f * cbc.m_hitNormalWorld[0];
        cast_ray[4] = cast_ray[1] + 100.0f * cbc.m_hitNormalWorld[1];
        cast_ray[5] = cast_ray[2] + 100.0f * cbc.m_hitNormalWorld[2];

        if(EngineContainer* c0 = static_cast<EngineContainer*>(cbc.m_collisionObject->getUserPointer()))
        {
            if(c0->object_type == OBJECT_BULLET_MISC)
            {
                btCollisionObject* obj = const_cast<btCollisionObject*>(cbc.m_collisionObject);
                btRigidBody* body = btRigidBody::upcast(obj);
                if(body && body->getMotionState())
                {
                    delete body->getMotionState();
                }
                if(body && body->getCollisionShape())
                {
                    delete body->getCollisionShape();
                }

                if(body)
                {
                    body->setUserPointer(nullptr);
                }
                c0->room = nullptr;
                delete c0;

                bt_engine_dynamicsWorld->removeCollisionObject(obj);
                delete obj;
            }
            else
            {
                last_cont = c0;
            }
        }
    }
}
示例#2
0
文件: des_R.c 项目: kgadek/kpfp
int main(int argc, char** args) {
	if(argc!=5 || (strcmp(args[1], "cbc") && strcmp(args[1], "ecb")) || (strcmp(args[2], "encrypt") && strcmp(args[2], "decrypt"))) {
		printf("uzycie: des cbc/ecb encrypt/decrypt plik.in plik.key\ndane wyjsciowe przekierowywane sa do pliku plik.out\n");
		return 1;
	}
	FILE* in = fopen(args[3], "r");
	if(!in) {
		printf("blad przy otwieraniu pliku...\n");
		return 1;
	}
	FILE* key;
	if(strcmp(args[2], "encrypt"))
		key = fopen(args[4], "r");
	else 
		key = fopen(args[4], "w");
	DES_key_schedule klucz;
	DES_cblock sekwencja;
	DES_random_key(&sekwencja);
	
	if(DES_set_key_checked(&sekwencja, &klucz)<0) {
		printf("blad przy generacji klucza!\n");
		return 1;
	}

	if(strcmp(args[1], "cbc")) {
		if(strcmp(args[2], "encrypt"))
			ecb(in, key, klucz, 0);
		else 
			ecb(in, key, klucz, 1);
	} else {
		if(strcmp(args[2], "encrypt"))
			cbc(in, key, klucz, 0); 
		else 
			cbc(in, key, klucz, 1);
	}
	fclose(in); fclose(key);
	return 0;
}
示例#3
0
//DllExport int
int
sam_cbc(
		ChannelInfo channelInfo[],
        int	nch,
		int sampleRateIdx,	
		int outputformat,
		int signal_type,
		int	windowShape,
		int num_window_groups,
		int	window_group_length[],
		short *swb_offset[],
		int	*scalefac[][8],
		int	*quant[][8],
		int	maxSfb,
		int stereo_mode,
		int	*stereo_info[],
		int frame_length,
		int wflag,
		int isExtended,
		int channelIdx,
		int numChannels,
		int mc_present,
		int extended_bytes,
		AV3EncFramePtr hEncoder)
{
	int frameSize;

	frameSize = cbc(channelInfo, nch,
					sampleRateIdx, outputformat, 
					signal_type, windowShape, 
		            num_window_groups, window_group_length, 
					swb_offset, scalefac,
					quant, maxSfb, 
					stereo_mode, stereo_info, 
					frame_length, wflag, 
					isExtended, channelIdx, 
					numChannels, mc_present,
					extended_bytes, hEncoder);

	return frameSize;
}
示例#4
0
int
main (int argc, char **argv)
{
  int i;
  blowfish c;
  u_int32_t l, r;

  setprogname (argv[0]);

  for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) {
    c.setkey (variable_key[i], 8);
    l = plaintext_l[i];
    r = plaintext_r[i];
    c.encipher (&l, &r);
    if (l != ciphertext_l[i] || r != ciphertext_r[i])
      panic ("variable_key encryption failed on test %d\n", i + 1);
    c.decipher (&l, &r);
    if (l != plaintext_l[i] || r != plaintext_r[i])
      panic ("variable_key decryption failed on test %d\n", i + 1);
  }

  for (i = NUM_VARIABLE_KEY_TESTS;
       i < NUM_VARIABLE_KEY_TESTS + NUM_SET_KEY_TESTS; i++) {
    int len = i - NUM_VARIABLE_KEY_TESTS + 1;
    c.setkey (set_key, len);
    l = plaintext_l[i];
    r = plaintext_r[i];
    c.encipher (&l, &r);
    if (l != ciphertext_l[i] || r != ciphertext_r[i])
      panic ("set_key encryption failed on test %d\n", len);
    c.decipher (&l, &r);
    if (l != plaintext_l[i] || r != plaintext_r[i])
      panic ("set_key decryption failed on test %d\n", len);
  }

  u_int32_t buf[256];
  for (i = 0; i < 256; i++)
    buf[i] = i;

  cbc64iv cbc (c);

  cbc.setiv (0, 0);
  cbc.encipher_words (buf, sizeof (buf));
  cbc.setiv (0, 0);
  cbc.decipher_words (buf, sizeof (buf));
  for (i = 0; i < 256; i++)
    if (int (buf[i]) != i)
      panic ("CBC test 1 failed\n");

  cbc.setiv (0, 0);
  cbc.encipher_words (buf, sizeof (buf) / 2);
  cbc.encipher_words (buf + 128, sizeof (buf) / 2);
  cbc.setiv (0, 0);
  cbc.decipher_words (buf, sizeof (buf) / 2);
  cbc.decipher_words (buf + 128, sizeof (buf) / 2);
  for (i = 0; i < 256; i++)
    if (int (buf[i]) != i)
      panic ("CBC test 2 failed\n");

  cbc.setiv (0, 0);
  cbc.encipher_bytes (buf, sizeof (buf));
  cbc.setiv (0, 0);
  cbc.decipher_bytes (buf, sizeof (buf));
  for (i = 0; i < 256; i++)
    if (int (buf[i]) != i)
      panic ("CBC test 3 failed\n");

  cbc.setiv (0, 0);
  cbc.encipher_bytes (buf, sizeof (buf) / 2);
  cbc.encipher_bytes (buf + 128, sizeof (buf) / 2);
  cbc.setiv (0, 0);
  cbc.decipher_bytes (buf, sizeof (buf) / 2);
  cbc.decipher_bytes (buf + 128, sizeof (buf) / 2);
  for (i = 0; i < 256; i++)
    if (int (buf[i]) != i)
      panic ("CBC test 4 failed\n");

  return 0;
}
示例#5
0
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// DrmAesCrypto::DrmAesEncryptL
// Encrypt data using a given key and insert initial vector on beginning
// -----------------------------------------------------------------------------
//
EXPORT_C HBufC8* DrmAesCrypto::DrmAesEncryptL(
    const TDesC8& aKey,
    const TDesC8& aIV,
    const TBool aAddPadding,
    const TDesC8& aData )
    {

    HBufC8* retBuf( NULL );

    CModeCBCEncryptor* cbc( NULL );
    TInt lastBlockStart( 0 );
    TPtr8 data( NULL, 0, 0 );

    if( aIV.Length() != KDCFKeySize || aKey.Length() != KDCFKeySize )
        {
        User::Leave( KErrArgument );
        }

    cbc = CModeCBCEncryptor::NewL( CAESEncryptor::NewLC( aKey ), aIV );
    CleanupStack::Pop(); // CAESEncryptor, owned by cbc.
    CleanupStack::PushL( cbc );

    retBuf = HBufC8::NewLC( aData.Size() + aIV.Size() + KDCFKeySize );
    data.Set( retBuf->Des() );
    data.Copy( aIV );
    data.Append( aData );

    lastBlockStart = data.Length() - ( data.Length() % KDCFKeySize );
    // Loop through the data, excluding aIV
    for ( TInt i = KDCFKeySize; i  < lastBlockStart; i+= KDCFKeySize )
        {
        data.Set( retBuf->Des().MidTPtr( i, KDCFKeySize ) );

        cbc->Transform( data );
        }

    if ( aAddPadding )
        {
        TInt dataLength = retBuf->Length();
        TUint8 padding( static_cast< TUint8 >
            ( lastBlockStart + KDCFKeySize - dataLength ) );

        __ASSERT_DEBUG( lastBlockStart + KDCFKeySize - dataLength <= KDCFKeySize,
            User::Invariant() );

        retBuf->Des().SetLength( lastBlockStart + KDCFKeySize );

        for ( TInt i = dataLength; i < retBuf->Length(); ++i )
            {
            retBuf->Des()[ i ] = padding;
            }

        data.Set( retBuf->Des().MidTPtr( lastBlockStart, KDCFKeySize ) );
        cbc->Transform( data );
        }

    CleanupStack::Pop( retBuf );
    CleanupStack::PopAndDestroy( cbc );
    return retBuf;

    }