Ejemplo n.º 1
0
 std::vector<typename LocalDataStoreEntry<QueryType, ValueType,
     EvaluatorTranslatorFilterType>::SequencedValue> LocalDataStoreEntry<
     QueryType, ValueType, EvaluatorTranslatorFilterType>::Load(
     const Query& query) const {
   std::vector<SequencedValue> matches;
   if(query.GetSnapshotLimit().GetSize() == 0) {
     return matches;
   }
   if(query.GetRange().GetStart() == Sequence::Present() ||
       query.GetRange().GetStart() == Sequence::Last()) {
     return matches;
   }
   auto& startPoint = query.GetRange().GetStart();
   auto& endPoint = query.GetRange().GetEnd();
   auto filter = m_translator(query.GetFilter());
   m_values.With(
     [&] (const typename ValueList::List& values) {
       if(query.GetSnapshotLimit().GetType() == SnapshotLimit::Type::TAIL) {
         for(const auto& value : boost::adaptors::reverse(values)) {
           if(RangePointGreaterOrEqual(value, startPoint) &&
               RangePointLesserOrEqual(value, endPoint) &&
               TestFilter(*filter, *value)) {
             matches.push_back(value);
             if(static_cast<int>(matches.size()) >=
                 query.GetSnapshotLimit().GetSize()) {
               break;
             }
           }
         }
       } else {
         for(const auto& value : values) {
           if(RangePointGreaterOrEqual(value, startPoint) &&
               RangePointLesserOrEqual(value, endPoint) &&
               TestFilter(*filter, *value)) {
             matches.push_back(value);
             if(static_cast<int>(matches.size()) >=
                 query.GetSnapshotLimit().GetSize()) {
               break;
             }
           }
         }
       }
     });
   if(query.GetSnapshotLimit().GetType() == SnapshotLimit::Type::TAIL) {
     std::reverse(matches.begin(), matches.end());
   }
   return matches;
 }
Ejemplo n.º 2
0
bool TestModeIV(SymmetricCipher &e, SymmetricCipher &d)
{
	SecByteBlock lastIV, iv(e.IVSize());
	StreamTransformationFilter filter(e, new StreamTransformationFilter(d));
	byte plaintext[20480];

	for (unsigned int i=1; i<sizeof(plaintext); i*=2)
	{
		e.GetNextIV(GlobalRNG(), iv);
		if (iv == lastIV)
			return false;
		else
			lastIV = iv;

		e.Resynchronize(iv);
		d.Resynchronize(iv);

		unsigned int length = STDMAX(GlobalRNG().GenerateWord32(0, i), (word32)e.MinLastBlockSize());
		GlobalRNG().GenerateBlock(plaintext, length);

		if (!TestFilter(filter, plaintext, length, plaintext, length))
			return false;
	}

	return true;
}
Ejemplo n.º 3
0
// Our main test program
int 
main(int argc,TCHAR* argv[], TCHAR* /*envp[]*/)
{
  int nRetCode = 0;

  HMODULE hModule = ::GetModuleHandle(NULL);
  InitializeCriticalSection(&std_stream);

  if(hModule == NULL)
  {
    _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
    nRetCode = 1;
  }
  else
  {
    // initialize MFC and print and error on failure
    if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    {
      _tprintf(_T("Fatal Error: MFC initialization failed\n"));
      nRetCode = 1;
    }
    else
    {
      printf("TESTPROGAM: MARLIN SERVER\n");
      printf("=========================\n");
      printf("\n");
      printf("Version string: %s\n",MARLIN_SERVER_VERSION);
      printf("----------------------------------\n");
      printf("\n");

      // See if we must do the standalone WebServiceServer test
      // Or that we should do the flat HTTPServer tests
      if(argc >= 2)
      {
        if(_stricmp(argv[1],"/ws") == 0)
        {
          CString contract = "http://interface.marlin.org/testing/";
          printf("WebServiceServer test for \"%s\"\n",contract.GetString());
          printf("----------------------------------------------------------------\n");
          printf("\n");

          // Test the Interface
          nRetCode = TestWebServiceServer(NULL,contract,logLevel);
        }
      }
      else
      {
        HTTPServer*   server  = nullptr;
        LogAnalysis*  logfile = nullptr;

        if(StartServer(server,logfile))
        {
          // Fire up all of our test sites
          int errors = 0;

          // Individual tests
          errors += Test_CrackURL();
          errors += Test_HTTPTime();
          errors += TestThreadPool(server->GetThreadPool());

          // HTTP tests
          errors += TestBaseSite(server);
          errors += TestSecureSite(server);
          errors += TestClientCertificate(server,true);
          errors += TestCookies(server);
          errors += TestFormData(server);
          errors += TestJsonData(server);
          errors += TestInsecure(server);
          errors += TestPushEvents(server);
          errors += TestBodySigning(server);
          errors += TestBodyEncryption(server);
          errors += TestMessageEncryption(server);
          errors += TestReliable(server);
          errors += TestReliableBA(server);
          errors += TestToken(server);
          errors += TestSubSites(server);
          errors += TestFilter(server);
          errors += TestPatch(server);
          errors += TestCompression(server);
          errors += TestAsynchrone(server);
          errors += TestWebSocket(server);

         // Test the WebServiceServer program generation
         CString contract = "http://interface.marlin.org/testing/";
         errors += TestJsonServer(server,contract,logLevel);
         errors += TestWebServiceServer(server,contract,logLevel);

          // See if we should wait for testing to occur
          if(errors)
          {
            printf("\n"
                   "SERVER (OR PROGRAMMING) IN ERROR STATE!!\n"
                   "%d sites not correctly started\n"
                   "\n",errors);
          }
          else
          {
            printf("\n"
                   "Server running....\n"
                   "Waiting to be called by test clients...\n"
                   "\n");
            // Wait for key to occur
            WaitForKey();
          }

          // Try to stop the WebSocket
//           errors += StopWebSocket();
// 
          // Try to stop the subsites
          errors += StopSubsites(server);

          // Testing the errorlog function
          server->ErrorLog(__FUNCTION__,5,"Not a real error message, but a test to see if it works :-)");

          printf("Stopping the server\n");
          server->StopServer();

          // See if the server is indeed in stopped state
          printf("The server is %s\n",server->GetIsRunning() ? "still running!\n" : "stopped.\n");

          // Remember for a cmd shell
          nRetCode = errors;
        }
        else
        {
          totalErrors = 1;
          printf("HTTPServer in error state in : Error %lu: %s\n"
                 ,server->GetLastError()
                 ,(LPCTSTR)GetLastErrorAsString(GetLastError()));
        }
        CleanupServer(server,logfile);
      }
    }
    printf("\n");
    printf("SUMMARY OF ALL SERVER TESTS\n");
    printf("===========================\n");
    if(totalErrors)
    {
      printf("ERRORS: %d\n",nRetCode += totalErrors);
    }
    else
    {
      printf("ALL OK !!!! YIPEEEE!!!!\n");
    }
    WaitForKey();
    WaitForKey();
  }
  DeleteCriticalSection(&std_stream);

  return nRetCode;
}
Ejemplo n.º 4
0
struct descriptor_xd *MdsFilter(float *in_data, float *in_dim, int *size, float *cut_off, int *num_in_poles)
{ 
    static struct descriptor_xd out_xd = {0, DTYPE_DSC, CLASS_XD, 0, 0};

    DESCRIPTOR_A(data_d, sizeof(float), DTYPE_FLOAT, 0, 0);
    DESCRIPTOR_SIGNAL(signal_d, 1, 0, 0);
    DESCRIPTOR_DIMENSION(dimension_d, 0, 0);
    DESCRIPTOR_WINDOW(window_d, 0, 0, 0);
    DESCRIPTOR_RANGE(range_d, 0, 0, 0);

    struct descriptor
	start_d = {sizeof(float), DTYPE_FLOAT, CLASS_S, 0},
	end_d = {sizeof(float), DTYPE_FLOAT, CLASS_S, 0},
	delta_d = {sizeof(float), DTYPE_FLOAT, CLASS_S, 0},
	start_idx_d = {sizeof(int), DTYPE_L, CLASS_S, 0},
	end_idx_d = {sizeof(int), DTYPE_L, CLASS_S, 0},
	time_at_0_d = {sizeof(float), DTYPE_FLOAT, CLASS_S, 0};

	
    int num_samples, num_poles, start_idx, end_idx, i;
    float fc, delta, dummy, *filtered_data, start, end, time_at_0;
    float phs_steep, delay;
    float *mod, *phs;
    static Filter *filter;

    if(*num_in_poles > 0)
    	num_poles = *num_in_poles;
    else
    	num_poles = 10;

    signal_d.data = (struct descriptor *)&data_d;
    signal_d.dimensions[0] = (struct descriptor *)&dimension_d;
    dimension_d.window = (struct descriptor *)&window_d;
    dimension_d.axis = (struct descriptor *)&range_d;
    window_d.startidx = (struct descriptor *)&start_idx_d;
    window_d.endingidx = (struct descriptor *)&end_idx_d;
    window_d.value_at_idx0 = (struct descriptor *)&time_at_0_d;
    start_idx_d.pointer = (char*)&start_idx;
    end_idx_d.pointer = (char *)&end_idx;
    time_at_0_d.pointer = (char *)&time_at_0;
    range_d.begin = (struct descriptor *)&start_d;
    range_d.ending = (struct descriptor *)&end_d;
    range_d.deltaval = (struct descriptor *)&delta_d;
    start_d.pointer = (char *)&start;
    end_d.pointer = (char *)&end;
    delta_d.pointer = (char *)&delta;
    

    num_samples = *size;

    fc = 1/ (in_dim[1] - in_dim[0]);
    filter = ButtwInvar(cut_off, &dummy, &dummy, &dummy, &fc, &num_poles);
    
    filtered_data = (float *)malloc(num_samples * sizeof(float));
    mod = (float *)malloc(sizeof(float) * 1000);
    phs = (float *)malloc(sizeof(float) * 1000);
    TestFilter(filter, fc, 1000, mod, phs);

    for(i = 1; i < 1000 - 1  && !isnan(phs[i]) && !isnan(phs[i+1]) && phs[i] > phs[i+1]; i++);


    if(i > 1 && i < 1000)
    {
    	phs_steep = (phs[1] - phs[i])/((i/1000.) * fc/2.);
       	delay = phs_steep/(2*PI);
	
    }


    free((char *)mod);
    free((char *)phs);
    
    
    DoFilter(filter, in_data, filtered_data, &num_samples);
    FreeFilter(filter);
    data_d.pointer = (char *)filtered_data;
    data_d.arsize = num_samples * sizeof(float);
    start = in_dim[0]-delay;
    end = in_dim[num_samples - 1]-delay;
    delta = in_dim[1] - in_dim[0];
    start_idx = 0;
    end_idx = num_samples - 1;
    time_at_0 = in_dim[0] - delay;

    MdsCopyDxXd((struct descriptor *)&signal_d, &out_xd);
    free((char *)filtered_data);
    
    
    
    
    return &out_xd;
}
Ejemplo n.º 5
0
bool ValidateCipherModes()
{
	cout << "\nTesting DES modes...\n\n";
	const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
	const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
	const byte plain[] = {	// "Now is the time for all " without tailing 0
		0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
		0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
		0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
	DESEncryption desE(key);
	DESDecryption desD(key);
	bool pass=true, fail;

	{
		// from FIPS 81
		const byte encrypted[] = {
			0x3f, 0xa4, 0x0e, 0x8a, 0x98, 0x4d, 0x48, 0x15,
			0x6a, 0x27, 0x17, 0x87, 0xab, 0x88, 0x83, 0xf9,
			0x89, 0x3d, 0x51, 0xec, 0x4b, 0x56, 0x3b, 0x53};

		ECB_Mode_ExternalCipher::Encryption modeE(desE);
		fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "ECB encryption" << endl;
		
		ECB_Mode_ExternalCipher::Decryption modeD(desD);
		fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "ECB decryption" << endl;
	}
	{
		// from FIPS 81
		const byte encrypted[] = {
			0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
			0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F, 
			0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6};

		CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with no padding" << endl;
		
		CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with no padding" << endl;

		fail = !TestModeIV(modeE, modeD);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC mode IV generation" << endl;
	}
	{
		// generated with Crypto++, matches FIPS 81
		// but has extra 8 bytes as result of padding
		const byte encrypted[] = {
			0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
			0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F, 
			0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6, 
			0x62, 0xC1, 0x6A, 0x27, 0xE4, 0xFC, 0xF2, 0x77};

		CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with PKCS #7 padding" << endl;
		
		CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with PKCS #7 padding" << endl;
	}
	{
		// generated with Crypto++ 5.2, matches FIPS 81
		// but has extra 8 bytes as result of padding
		const byte encrypted[] = {
			0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
			0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F, 
			0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6, 
			0xcf, 0xb7, 0xc7, 0x64, 0x0e, 0x7c, 0xd9, 0xa7};

		CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with one-and-zeros padding" << endl;

		CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with one-and-zeros padding" << endl;
	}
	{
		const byte plain[] = {'a', 0, 0, 0, 0, 0, 0, 0};
		// generated with Crypto++
		const byte encrypted[] = {
			0x9B, 0x47, 0x57, 0x59, 0xD6, 0x9C, 0xF6, 0xD0};

		CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(),
			plain, 1, encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with zeros padding" << endl;

		CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with zeros padding" << endl;
	}
	{
		// generated with Crypto++, matches FIPS 81
		// but with last two blocks swapped as result of CTS
		const byte encrypted[] = {
			0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
			0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6, 
			0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F};

		CBC_CTS_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with ciphertext stealing (CTS)" << endl;
		
		CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with ciphertext stealing (CTS)" << endl;

		fail = !TestModeIV(modeE, modeD);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC CTS IV generation" << endl;
	}
	{
		// generated with Crypto++
		const byte decryptionIV[] = {0x4D, 0xD0, 0xAC, 0x8F, 0x47, 0xCF, 0x79, 0xCE};
		const byte encrypted[] = {0x12, 0x34, 0x56};

		byte stolenIV[8];

		CBC_CTS_Mode_ExternalCipher::Encryption modeE(desE, iv);
		modeE.SetStolenIV(stolenIV);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, 3, encrypted, sizeof(encrypted));
		fail = memcmp(stolenIV, decryptionIV, 8) != 0 || fail;
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with ciphertext and IV stealing" << endl;
		
		CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, stolenIV);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, 3);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with ciphertext and IV stealing" << endl;
	}
	{
		const byte encrypted[] = {	// from FIPS 81
			0xF3,0x09,0x62,0x49,0xC7,0xF4,0x6E,0x51,
			0xA6,0x9E,0x83,0x9B,0x1A,0x92,0xF7,0x84,
			0x03,0x46,0x71,0x33,0x89,0x8E,0xA6,0x22};

		CFB_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CFB encryption" << endl;

		CFB_Mode_ExternalCipher::Decryption modeD(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CFB decryption" << endl;

		fail = !TestModeIV(modeE, modeD);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CFB mode IV generation" << endl;
	}
	{
		const byte plain[] = {	// "Now is the." without tailing 0
			0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,0x68,0x65};
		const byte encrypted[] = {	// from FIPS 81
			0xf3,0x1f,0xda,0x07,0x01,0x14,0x62,0xee,0x18,0x7f};

		CFB_Mode_ExternalCipher::Encryption modeE(desE, iv, 1);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CFB (8-bit feedback) encryption" << endl;

		CFB_Mode_ExternalCipher::Decryption modeD(desE, iv, 1);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CFB (8-bit feedback) decryption" << endl;

		fail = !TestModeIV(modeE, modeD);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CFB (8-bit feedback) IV generation" << endl;
	}
	{
		const byte encrypted[] = {	// from Eric Young's libdes
			0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
			0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
			0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3};

		OFB_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "OFB encryption" << endl;

		OFB_Mode_ExternalCipher::Decryption modeD(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "OFB decryption" << endl;

		fail = !TestModeIV(modeE, modeD);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "OFB IV generation" << endl;
	}
	{
		const byte encrypted[] = {	// generated with Crypto++
			0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x6E, 0x51, 
			0x16, 0x3A, 0x8C, 0xA0, 0xFF, 0xC9, 0x4C, 0x27, 
			0xFA, 0x2F, 0x80, 0xF4, 0x80, 0xB8, 0x6F, 0x75};

		CTR_Mode_ExternalCipher::Encryption modeE(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
			plain, sizeof(plain), encrypted, sizeof(encrypted));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "Counter Mode encryption" << endl;

		CTR_Mode_ExternalCipher::Decryption modeD(desE, iv);
		fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
			encrypted, sizeof(encrypted), plain, sizeof(plain));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "Counter Mode decryption" << endl;

		fail = !TestModeIV(modeE, modeD);
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "Counter Mode IV generation" << endl;
	}
	{
		const byte plain[] = {	// "7654321 Now is the time for "
			0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, 
			0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, 
			0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, 
			0x66, 0x6f, 0x72, 0x20};
		const byte mac1[] = {	// from FIPS 113
			0xf1, 0xd3, 0x0f, 0x68, 0x49, 0x31, 0x2c, 0xa4};
		const byte mac2[] = {	// generated with Crypto++
			0x35, 0x80, 0xC5, 0xC4, 0x6B, 0x81, 0x24, 0xE2};

		CBC_MAC<DES> cbcmac(key);
		HashFilter cbcmacFilter(cbcmac);
		fail = !TestFilter(cbcmacFilter, plain, sizeof(plain), mac1, sizeof(mac1));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "CBC MAC" << endl;

		DMAC<DES> dmac(key);
		HashFilter dmacFilter(dmac);
		fail = !TestFilter(dmacFilter, plain, sizeof(plain), mac2, sizeof(mac2));
		pass = pass && !fail;
		cout << (fail ? "FAILED   " : "passed   ") << "DMAC" << endl;
	}

	return pass;
}
Ejemplo n.º 6
0
bool ValidateBaseCode()
{
	bool pass = true, fail;
	byte data[255];
	for (unsigned int i=0; i<255; i++)
		data[i] = i;
	const char *hexEncoded = 
"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627"
"28292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"
"505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071727374757677"
"78797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"
"A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7"
"C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"
"F0F1F2F3F4F5F6F7F8F9FAFBFCFDFE";
	const char *base32Encoded = 
"AAASEA2EAWDAQCAJBIFS2DIQB6IBCESVCSKTNF22DEPBYHA7D2RUAIJCENUCKJTHFAWUWK3NFWZC8NBT"
"GI3VIPJYG66DUQT5HS8V6R4AIFBEGTCFI3DWSUKKJPGE4VURKBIXEW4WKXMFQYC3MJPX2ZK8M7SGC2VD"
"NTUYN35IPFXGY5DPP3ZZA6MUQP4HK7VZRB6ZW856RX9H9AEBSKB2JBNGS8EIVCWMTUG27D6SUGJJHFEX"
"U4M3TGN4VQQJ5HW9WCS4FI7EWYVKRKFJXKX43MPQX82MDNXVYU45PP72ZG7MZRF7Z496BSQC2RCNMTYH"
"3DE6XU8N3ZHN9WGT4MJ7JXQY49NPVYY55VQ77Z9A6HTQH3HF65V8T4RK7RYQ55ZR8D29F69W8Z5RR8H3"
"9M7939R8";
	const char *base64AndHexEncoded = 
"41414543417751464267634943516F4C4441304F4478415245684D554652595847426B6147787764"
"486838674953496A4A43556D4A7967704B6973734C5334764D4445794D7A51310A4E6A63344F546F"
"375044302B50304242516B4E4552555A4853456C4B5330784E546B395155564A5456465657563168"
"5A576C746358563566594746695932526C5A6D646F615770720A6247317562334278636E4E306458"
"5A3365486C3665337839666E2B4167594B44684957476834694A696F754D6A5936506B4A47536B35"
"53566C7065596D5A71626E4A32656E3643680A6F714F6B7061616E714B6D717136797472712B7773"
"624B7A744C573274376935757275387662362F774D484377385446787366497963724C7A4D334F7A"
"39445230745055316462580A324E6E6132397A6433742F6734654C6A354F586D352B6A7036757673"
"3765377638504879382F5431397666342B6672372F50332B0A";

	cout << "\nBase64, base32 and hex coding validation suite running...\n\n";

	fail = !TestFilter(HexEncoder().Ref(), data, 255, (const byte *)hexEncoded, strlen(hexEncoded));
	cout << (fail ? "FAILED    " : "passed    ");
	cout << "Hex Encoding\n";
	pass = pass && !fail;

	fail = !TestFilter(HexDecoder().Ref(), (const byte *)hexEncoded, strlen(hexEncoded), data, 255);
	cout << (fail ? "FAILED    " : "passed    ");
	cout << "Hex Decoding\n";
	pass = pass && !fail;

	fail = !TestFilter(Base32Encoder().Ref(), data, 255, (const byte *)base32Encoded, strlen(base32Encoded));
	cout << (fail ? "FAILED    " : "passed    ");
	cout << "Base32 Encoding\n";
	pass = pass && !fail;

	fail = !TestFilter(Base32Decoder().Ref(), (const byte *)base32Encoded, strlen(base32Encoded), data, 255);
	cout << (fail ? "FAILED    " : "passed    ");
	cout << "Base32 Decoding\n";
	pass = pass && !fail;

	fail = !TestFilter(Base64Encoder(new HexEncoder).Ref(), data, 255, (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded));
	cout << (fail ? "FAILED    " : "passed    ");
	cout << "Base64 Encoding\n";
	pass = pass && !fail;

	fail = !TestFilter(HexDecoder(new Base64Decoder).Ref(), (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded), data, 255);
	cout << (fail ? "FAILED    " : "passed    ");
	cout << "Base64 Decoding\n";
	pass = pass && !fail;

	return pass;
}