Ejemplo n.º 1
0
int main(){

		std::cout << "Test program of AEL launched ..." << std::endl << std::endl;

		//License information
		std::cout << "This program and all source files of the Advanced Encryption Library are under the Lesser General Public License (LGPL). See COPYING and LESSER.COPYING files which you should have with the source code." << std::endl << std::endl;

		//Test the AES-128Bits algorithm
		std::cout << "AES 128 Bits : ";
		ael::AES key_aes_128;
		key_aes_128.GenerateKey(128);
		std::string encrypt128 = key_aes_128.Encrypt("Test program ...");
		std::string decrypt128 = key_aes_128.Decrypt(encrypt128);

		if(decrypt128 == "Test program ..."){
			std::cout << "OK" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the AES-192Bits algorithm
		std::cout << "AES 192 Bits : ";
		ael::AES key_aes_192;
		key_aes_192.GenerateKey(192);
		std::string encrypt192 = key_aes_192.Encrypt("Test program ...");
		std::string decrypt192 = key_aes_192.Decrypt(encrypt192);

		if(decrypt192 == "Test program ..."){
			std::cout << "OK" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the AES-256Bits algorithm
		std::cout << "AES 256 Bits : ";
		ael::AES key_aes_256;
		key_aes_256.GenerateKey(256);
		std::string encrypt256 = key_aes_256.Encrypt("Test program ...");
		std::string decrypt256 = key_aes_256.Decrypt(encrypt256);

		if(decrypt256 == "Test program ..."){
			std::cout << "OK" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the MD5 algorithm
		std::cout << "MD5 : ";
		ael::MD5 md5("Hello world !");
		if(md5.asHexString() == "67c18d060479c5d867c9b91c80edeb4c"){
			std::cout << "OK" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

        //Test the Diffie-Hellman Key Exchange algorithm
		std::cout << "Diffie-Hellman Key Exchange : ";

		if(TestDiffieHellman()){
			std::cout << "OK" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		std::cout << "Press a touch to quit ..." << std::endl;
		std::getchar();

        return 0;

}
Ejemplo n.º 2
0
int main(){
		std::cout << "Test program of SEL launched ..." << std::endl << std::endl;

		//License information
		std::cout << "This project is licensed under the terms of the MIT license." << std::endl << std::endl;

        //Random generators initialization
        sel::randinit();

        //Checking all algorithms
        std::cout << "Checking all algorithms" << std::endl << std::endl;

		//Test the AES-128Bits algorithm
		std::cout << "AES 128 Bits : ";
		sel::AES key_aes_128;
		key_aes_128.GenerateKey(sel::AES::AES128);
		std::string encrypt128 = key_aes_128.Encrypt("Test program ...");
		std::string decrypt128 = key_aes_128.Decrypt(encrypt128);

		if(decrypt128 == "Test program ..."){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the AES-192Bits algorithm
		std::cout << "AES 192 Bits : ";
		sel::AES key_aes_192;
		key_aes_192.GenerateKey(sel::AES::AES192);
		std::string encrypt192 = key_aes_192.Encrypt("Test program ...");
		std::string decrypt192 = key_aes_192.Decrypt(encrypt192);

		if(decrypt192 == "Test program ..."){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the AES-256Bits algorithm
		std::cout << "AES 256 Bits : ";
		sel::AES key_aes_256;
		key_aes_256.GenerateKey(sel::AES::AES256);
		std::string encrypt256 = key_aes_256.Encrypt("Test program ...");
		std::string decrypt256 = key_aes_256.Decrypt(encrypt256);

		if(decrypt256 == "Test program ..."){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the MD5 algorithm
		std::cout << "MD5 : ";
		sel::MD5 md5("Hello world !");
		if(md5.asHexString() == "67c18d060479c5d867c9b91c80edeb4c"){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the CRC-1 algorithm
		std::cout << "CRC-1 : ";
		sel::CRC1 crc1("Hello world !");
		if(crc1.result() == true){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the CRC-16 algorithm
		std::cout << "CRC-16-IBM : ";
		sel::CRC16 crc16("Hello world !", sel::CRC16::CRC16_IBM);
		if(crc16.result() == 0x3A37){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		std::cout << "CRC-16-MODBUS : ";
		sel::CRC16 crc16_2("Hello world !", sel::CRC16::CRC16_MODBUS);
		if(crc16_2.result() == 0xD134){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test the CRC-32 algorithm
		std::cout << "CRC-32 : ";
		sel::CRC32 crc32("Hello world !", sel::CRC32::CRC32_NORMAL);
		if(crc32.result() == 0x070E2C40){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		//Test LargeInt class arithmetic
		std::cout << std::endl << "Checking arithmetic operations" << std::endl << std::endl;

		sel::LargeInt biginteger1("AF5263DED1648973"), biginteger2("1654973F1654328B");

		sel::LargeInt bigintegersum = biginteger1 + biginteger2, bigintegersumresult("C5A6FB1DE7B8BBFE");

		if(bigintegersum == bigintegersumresult){
            std::cout << "Addition : CHECKED" << std::endl;
		}
		else{
            std::cout << "Addition : FAILED" << std::endl;
		}

		sel::LargeInt bigintegersub = biginteger1 - biginteger2, bigintegersubresult("98FDCC9FBB1056E8");

		if(bigintegersub == bigintegersubresult){
            std::cout << "Subtraction : CHECKED" << std::endl;
		}
		else{
            std::cout << "Subtraction : FAILED" << std::endl;
		}

		sel::LargeInt bigintegermul = biginteger1 * biginteger2, bigintegermulresult("F4B0332B895186004E5BFFB502B1771");

		if(bigintegermul == bigintegermulresult){
            std::cout << "Multiplication : CHECKED" << std::endl;
		}
		else{
            std::cout << "Multiplication : FAILED" << std::endl;
		}

		sel::LargeInt bigintegermul_karatsuba(biginteger1.mul_karatsuba(biginteger2));

		if(bigintegermul_karatsuba == bigintegermulresult){
            std::cout << "Multiplication Karatsuba : CHECKED" << std::endl;
		}
		else{
            std::cout << "Multiplication Karatsuba : FAILED" << std::endl;
		}

		sel::LargeInt bigintegermod = biginteger1 % biginteger2, bigintegermodresult("13024125351727A6");

		if(bigintegermul == bigintegermulresult){
            std::cout << "Modulus : CHECKED" << std::endl;
		}
		else{
            std::cout << "Modulus : FAILED" << std::endl;
		}

        //Test the Diffie-Hellman Key Exchange algorithm
		std::cout << "Diffie-Hellman Key Exchange : ";

		if(TestDiffieHellman()){
			std::cout << "CHECKED" << std::endl;
		}
		else{
			std::cout << "FAILED" << std::endl;
		}

		std::cout << "Press a touch to quit ..." << std::endl;
		std::getchar();

        return 0;
}