Commit 529976e2 authored by berge's avatar berge
Browse files

Added fx_encrypt() and fx_decrypt()

parent 4d9a3d63
Loading
Loading
Loading
Loading
+33 −5
Original line number Diff line number Diff line
@@ -69,6 +69,24 @@
			 */	            	
            external function fx_decrypt3Des(in octetstring p_key, in octetstring p_data) return octetstring;

            /**
			 * @desc	Encrypt an octetstring using specified algorithm 
			 * @param	p_algorithm Algorithm to be used for encryption
			 * @param	p_key encryption key
			 * @param	p_data Data block to be encrypted
			 * @return 	Encrypted data
			 */	            	
            external function fx_encrypt(in EncryptionAlgorithm p_algorithm, in octetstring p_key, in octetstring p_data) return octetstring;

            /**
			 * @desc	Decrypt an octetstring using specified algorithm 
			 * @param	p_algorithm Algorithm to be used for decryption
			 * @param	p_key decryption key
			 * @param	p_data Data block to be encrypted
			 * @return 	Encrypted data
			 */	            	
            external function fx_decrypt(in EncryptionAlgorithm p_algorithm, in octetstring p_key, in octetstring p_data) return octetstring;
            	
        	/**
        	 * @desc	This method verifies if a candidate certificate is trusted by a root CA
        	 * @param	p_candidate The candidate certificate to verify
@@ -189,13 +207,23 @@
    	} // end f_cryptographicChecksum
    	
    	// TDES Encryption
    	function f_encrypt(in octetstring p_key, in octetstring p_data) 
    	function f_encrypt3Des(in octetstring p_key, in octetstring p_data) 
    	return octetstring {
 	    	return fx_encrypt3Des(p_key, p_data);
    	} // end f_encrypt
    	
    	function f_encrypt(in EncryptionAlgorithm p_algorithm, in octetstring p_key, in octetstring p_data) 
    	return octetstring {
 	    	return fx_encrypt(p_algorithm, p_key, p_data);
    	} // end f_encrypt
    	
    	function f_decrypt(in EncryptionAlgorithm p_algorithm, in octetstring p_key, in octetstring p_data) 
    	return octetstring {
 	    	return fx_decrypt(p_algorithm, p_key, p_data);
    	} // end f_decrypt
    	
    	// TDES Decryption
    	function f_decrypt(in octetstring p_key, in octetstring p_data)
    	function f_decrypt3Des(in octetstring p_key, in octetstring p_data)
    	return octetstring  {
 	    	return fx_decrypt3Des(p_key, p_data);
    	} // end f_decrypt
@@ -268,7 +296,7 @@
			}			
			
    		// b) Decrypt the cryptogram E_IFD.
			v_s := f_decrypt(f_build3DesKey(vc_simu.kEnc), v_encryptedIfd);	
			v_s := f_decrypt3Des(f_build3DesKey(vc_simu.kEnc), v_encryptedIfd);	

    		// c) Extract RND.ICC from S and check if IFD returned the correct value.
    		v_rndIfd := substr(v_s, 0, c_bacNonceSize);
@@ -286,7 +314,7 @@
    		v_r := p_rndIcc & v_rndIfd & v_keyIcc;
    		
    		// f) Compute the cryptogram E_ICC = E[K_ENC](R).
    		v_encryptedIcc := f_encrypt(f_build3DesKey(vc_simu.kEnc), v_r);
    		v_encryptedIcc := f_encrypt3Des(f_build3DesKey(vc_simu.kEnc), v_r);
    		
    		// g) Compute the checksum M_ICC = MAC[K_MAC](E_ICC).
    		v_macIcc := f_cryptographicChecksum(vc_simu.kMac, v_encryptedIcc);
@@ -336,7 +364,7 @@
			//FIXME
			
			// encrypt message representative
			return f_encrypt(vc_simu.kEnc, v_f);
			return f_encrypt(e_rsa, vc_simu.kEnc, v_f); //FIXME Algorithm!
	   	}
    	
    	function f_chipAuthentication(in octetstring p_publicKeyPcd) runs on MRTD {
+3 −3
Original line number Diff line number Diff line
@@ -491,7 +491,7 @@ module ePassport_Testcases {
				stop;
			}
			// Encrypt S with TDES key KENC as calculated in Annex E.2
			v_encryptedIfd := f_encrypt(f_build3DesKey(vc_simu.kEnc), v_S);
			v_encryptedIfd := f_encrypt3Des(f_build3DesKey(vc_simu.kEnc), v_S);
			log ("encryptedIfd: ", v_encryptedIfd);
			if (match(v_encryptedIfd, mw_encryptedIfd) == false) {
				setverdict(fail);
@@ -549,7 +549,7 @@ module ePassport_Testcases {
			v_computedMacIfd := f_cryptographicChecksum(vc_simu.kMac, v_encryptedIfd);
			
    		// b) Decrypt the cryptogram E_IFD.
			v_s := f_decrypt(f_build3DesKey(vc_simu.kEnc), v_encryptedIfd);	
			v_s := f_decrypt3Des(f_build3DesKey(vc_simu.kEnc), v_encryptedIfd);	

    		// c) Extract RND.ICC from S and check if IFD returned the correct value.
    		v_rndIfd := substr(v_s, 0, c_bacNonceSize);
@@ -601,7 +601,7 @@ module ePassport_Testcases {
    		}    			    		
    		
    		// f) Compute the cryptogram E_ICC = E[K_ENC](R).
    		v_encryptedIcc := f_encrypt(f_build3DesKey(vc_simu.kEnc), v_r);
    		v_encryptedIcc := f_encrypt3Des(f_build3DesKey(vc_simu.kEnc), v_r);
    		if(match(v_encryptedIcc, '46B9342A41396CD7386BF5803104D7CEDC122B9132139BAF2EEDC94EE178534F'O)) {
    			log("f) E_ICC correct");
    			setverdict(pass);
+11 −5
Original line number Diff line number Diff line
@@ -28,11 +28,17 @@ module ePassport_Types {
		}

		type enumerated HashAlgorithm {
			e_sha1,
			e_sha224,
			e_sha256,
			e_sha384,
			e_sha512
			e_sha1(0),
			e_sha224(1),
			e_sha256(2),
			e_sha384(3),
			e_sha512(4)
		}
		
		type enumerated EncryptionAlgorithm {
			e_rsa(0),
			e_dsa(1),
			e_ecdsa(2)	
		}

	}//end enumeratedTypes