TestCodec_SecuredFuntions.ttcn 29.1 KB
Newer Older
garciay's avatar
garciay committed
/*
 * @author
 *     
 * @version
 *     1.0
 * @desc
 *     
 * @remark
 *     
 * @see
 *     
 */ 
module TestCodec_SecuredFuntions {
    
    // LibCommon
    import from LibCommon_BasicTypesAndValues all;
    import from LibCommon_DataStrings all;
    
    // LibIts
    import from IEEE1609dot2BaseTypes language "ASN.1:1997" all;
    import from IEEE1609dot2 language "ASN.1:1997" all;
    import from EtsiTs103097Module language "ASN.1:1997" all;
    
    // LibItsSecurity
    import from LibItsSecurity_EncdecDeclarations all;
    import from LibItsSecurity_TypesAndValues all;
    import from LibItsSecurity_Templates all;
    import from LibItsSecurity_Functions all;
    import from LibItsSecurity_Pixits all;
    
    // TestCodec
    import from TestCodec_TestAndSystem all;

    testcase tc_load_certificates() runs on TCType system TCType {

      if (fx_loadCertificates(PX_CERTIFICATE_POOL_PATH, PX_IUT_SEC_CONFIG_NAME) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
    } // End of testcase tc_load_certificates

    testcase tc_read_certificate_1() runs on TCType system TCType {
      var octetstring v_certificate;
      
      if (fx_loadCertificates(PX_CERTIFICATE_POOL_PATH, PX_IUT_SEC_CONFIG_NAME) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }

      if (fx_readCertificate("CERT_IUT_A_RCA", v_certificate) == false) {
        setverdict(fail);
      } else {
        log("v_certificate: ", v_certificate);
        setverdict(pass);
      }
    } // End of testcase tc_read_certificates_1

    testcase tc_read_certificate_2() runs on TCType system TCType {
      var octetstring v_certificate;
      
      if (fx_loadCertificates(PX_CERTIFICATE_POOL_PATH, PX_IUT_SEC_CONFIG_NAME) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }

      if (fx_readCertificate("CERT_IUT_A_RCA", v_certificate) == false) {
        setverdict(fail);
      } else {
        var bitstring v_oct2bit;
        var EtsiTs103097Certificate v_dec_certificate;
                    
        log("v_certificate: ", v_certificate);
        v_oct2bit := oct2bit(v_certificate);
        if (0 == decvalue(v_oct2bit,  v_dec_certificate)) {
          log("v_certificate: ",  v_dec_certificate);
          setverdict(pass);
        } else {
          setverdict(fail);
        }
      }
    } // End of testcase tc_load_certificates_2

    testcase tc_read_certificate_digest() runs on TCType system TCType {
      if (fx_loadCertificates(PX_CERTIFICATE_POOL_PATH, PX_IUT_SEC_CONFIG_NAME) == false) {
        setverdict(fail);
      } else {
        var octetstring v_digest;
        if (fx_readCertificateDigest("CERT_IUT_A_RCA", v_digest) == false) {
          setverdict(fail);
        } else {
          log("v_digest = ", v_digest);
          setverdict(pass);
        }
      }
    } // End of testcase tc_load_certificates_digest

    testcase tc_read_certificate_hash() runs on TCType system TCType {
      if (fx_loadCertificates(PX_CERTIFICATE_POOL_PATH, PX_IUT_SEC_CONFIG_NAME) == false) {
        setverdict(fail);
      } else {
        var octetstring v_hash;
        if (fx_readCertificateHash("CERT_IUT_A_RCA", v_hash) == false) {
          setverdict(fail);
        } else {
          log("v_hash = ", v_hash);
          setverdict(pass);
        }
      }
    } // End of testcase tc_load_certificates_digest

garciay's avatar
garciay committed
    testcase tc_sha256_1() runs on TCType system TCType {
      var octetstring v_test := '616263'O;
garciay's avatar
garciay committed
      var Oct32 v_exp_hash := 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'O;
garciay's avatar
garciay committed
      var Oct32 v_hash;

      v_hash := f_hashWithSha256(v_test);

      if (match(v_hash, v_exp_hash) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_sha256_1
garciay's avatar
garciay committed

    testcase tc_sha256_2() runs on TCType system TCType {
      var octetstring v_test := ''O;
      var Oct32 v_exp_hash := 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'O; /* Hash of empty string */
      var Oct32 v_hash;

      v_hash := f_hashWithSha256(v_test);

      if (match(v_hash, v_exp_hash) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
    } // End of testcase tc_sha256_2

garciay's avatar
garciay committed
    testcase tc_sha384_1() runs on TCType system TCType {
      var octetstring v_test := '616263'O;
      var Oct48 v_exp_hash := 'CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7'O;
      var Oct48 v_hash;

      v_hash := f_hashWithSha384(v_test);

      if (match(v_hash, v_exp_hash) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_sha384_1
    testcase tc_sha384_2() runs on TCType system TCType {
      var octetstring v_test := ''O;
      var Oct48 v_exp_hash := '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'O; /* Hash of empty string */
      var Oct48 v_hash;

      v_hash := f_hashWithSha384(v_test);

      if (match(v_hash, v_exp_hash) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
    } // End of testcase tc_sha384_2

garciay's avatar
garciay committed
    testcase tc_f_generate_key_pair_1() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
      if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
garciay's avatar
garciay committed
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_generate_key_pair_1
garciay's avatar
garciay committed
    testcase tc_f_generate_key_pair_2() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
      if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
garciay's avatar
garciay committed
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_generate_key_pair_2
garciay's avatar
garciay committed

    testcase tc_f_generate_key_pair_3() runs on TCType system TCType {
      var Oct48 v_private_key;
      var Oct48 v_publicKeyX;
      var Oct48 v_publicKeyY;
      var Oct48 v_publicKeyCompressed;
      var integer v_compressedMode;
      if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
garciay's avatar
garciay committed
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_generate_key_pair_3
garciay's avatar
garciay committed
    testcase tc_f_signWithEcdsaNistp256WithSha256_1() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var Oct32 v_publicKeyY;
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_signWithEcdsaNistp256WithSha256_1
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaNistp256WithSha256_1() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaNistp256WithSha256_1
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaNistp256WithSha256_2() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
      var octetstring v_private_key_wrong;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
garciay's avatar
garciay committed
      
      v_private_key_wrong := v_private_key;
        
      v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      } else {
        setverdict(pass);
      }
      
      v_private_key_wrong[2] := 'AA'O;
      v_private_key_wrong[3] := 'BB'O;
      v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key_wrong);  
      if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyCompressed, v_compressedMode) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
garciay's avatar
garciay committed
      }
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaNistp256WithSha256_2
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaNistp256WithSha256_3() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;
      var octetstring v_sig_wrong := ''O;
      var Oct32 v_publicKeyX_wrong;
      var Oct32 v_publicKeyY_wrong;

      if (f_generate_key_pair_nistp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaNistp256WithSha256_1('0A0A0A0A'O, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      
      v_sig_wrong := v_sig;
      v_sig_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_sig_wrong, v_publicKeyCompressed, v_compressedMode) == true) {
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig_wrong, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      
      v_publicKeyX_wrong := v_publicKeyCompressed;
      v_publicKeyX_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaNistp256WithSha256(v_encMsg, int2oct(10, 32), v_sig_wrong, v_publicKeyCompressed, v_compressedMode) == true) {
garciay's avatar
garciay committed
      v_publicKeyX_wrong := v_publicKeyX;
      v_publicKeyX_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX_wrong, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      
      v_publicKeyY_wrong := v_publicKeyY;
      v_publicKeyY_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaNistp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY_wrong) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaNistp256WithSha256_3
garciay's avatar
garciay committed
    testcase tc_f_signWithEcdsaBrainpoolp256WithSha256_1() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_signWithEcdsaBrainpoolp256WithSha256_1
garciay's avatar
garciay committed
    testcase tc_f_signWithEcdsaBrainpoolp384WithSha384_1() runs on TCType system TCType {
      var Oct48 v_private_key;
      var Oct48 v_publicKeyX;
      var Oct48 v_publicKeyY;
      var Oct48 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_signWithEcdsaBrainpoolp384WithSha384_1
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_1() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_1
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_2() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
      var octetstring v_private_key_wrong;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
garciay's avatar
garciay committed
      
      v_private_key_wrong := v_private_key;
        
      v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      
      v_private_key_wrong[2] := 'AA'O;
      v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key_wrong);  
      if (f_verifyWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyCompressed, v_compressedMode) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_2
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_3() runs on TCType system TCType {
      var Oct32 v_private_key;
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var Oct32 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;
      var octetstring v_sig_wrong := ''O;
      var Oct32 v_publicKeyX_wrong;
      var Oct32 v_publicKeyY_wrong;

      if (f_generate_key_pair_brainpoolp256(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_encMsg, int2oct(10, 32), v_private_key);  
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1('0A0A0A0A'O, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      v_sig_wrong := v_sig;
      v_sig_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig_wrong, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      v_publicKeyX_wrong := v_publicKeyX;
      v_publicKeyX_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX_wrong, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      v_publicKeyY_wrong := v_publicKeyY;
      v_publicKeyY_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp256WithSha256_1(v_encMsg, int2oct(10, 32), v_sig, v_publicKeyX, v_publicKeyY_wrong) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaBrainpoolp256WithSha256_3
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_1() runs on TCType system TCType {
      var Oct48 v_private_key;
      var Oct48 v_publicKeyX;
      var Oct48 v_publicKeyY;
      var Oct48 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_1
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_2() runs on TCType system TCType {
      var Oct48 v_private_key;
      var Oct48 v_publicKeyX;
      var Oct48 v_publicKeyY;
      var Oct48 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var Oct48 v_private_key_wrong;
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;

      if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
garciay's avatar
garciay committed
      
      v_private_key_wrong := v_private_key;
        
      v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_private_key);  
garciay's avatar
garciay committed
      if (lengthof(v_sig) == 0) {
        setverdict(fail);
        stop;
      }
      
      if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
      
      v_private_key_wrong[2] := 'AA'O;
      v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_private_key_wrong);  
      if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyCompressed, v_compressedMode) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      } else {
        setverdict(pass);
      }
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_2
garciay's avatar
garciay committed

    testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_3() runs on TCType system TCType {
      var Oct48 v_private_key;
      var Oct48 v_publicKeyX;
      var Oct48 v_publicKeyY;
      var Oct48 v_publicKeyCompressed;
      var integer v_compressedMode;
garciay's avatar
garciay committed
      var octetstring v_encMsg := '0A0A0102030405060708090A0B0C0D0E0F0A0A'O; 
      var octetstring v_sig := ''O;
      var octetstring v_sig_wrong := ''O;
      var Oct48 v_publicKeyX_wrong;
      var Oct48 v_publicKeyY_wrong;

      if (f_generate_key_pair_brainpoolp384(v_private_key, v_publicKeyX, v_publicKeyY, v_publicKeyCompressed, v_compressedMode) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
        stop;
      }
      log("v_private_key = ", v_private_key);
      log("v_public_key X= ", v_publicKeyX);
      log("v_public_key Y= ", v_publicKeyY);
      log("v_public_key compressed= ", v_publicKeyCompressed, v_compressedMode);
      v_sig := f_signWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_private_key);  
      if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyCompressed, v_compressedMode) == false) {
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX, v_publicKeyY) == false) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1('0A0A0A0A'O, int2oct(10, 48), v_sig, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      v_sig_wrong := v_sig;
      v_sig_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig_wrong, v_publicKeyX, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      v_publicKeyX_wrong := v_publicKeyCompressed;
      v_publicKeyX_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp384WithSha384(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX_wrong, v_compressedMode) == true) {
garciay's avatar
garciay committed
      v_publicKeyX_wrong := v_publicKeyX;
      v_publicKeyX_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX_wrong, v_publicKeyY) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      v_publicKeyY_wrong := v_publicKeyY;
      v_publicKeyY_wrong[0] := 'FF'O;
      if (f_verifyWithEcdsaBrainpoolp384WithSha384_1(v_encMsg, int2oct(10, 48), v_sig, v_publicKeyX, v_publicKeyY_wrong) == true) {
garciay's avatar
garciay committed
        setverdict(fail);
      }
      
      setverdict(pass);
garciay's avatar
garciay committed
    } // End of testcase tc_f_verifyWithEcdsaBrainpoolp384WithSha384_3
    
    control {
        execute(tc_sha256_1());
        execute(tc_sha384_1());
        execute(tc_f_generate_key_pair_1());
        execute(tc_f_generate_key_pair_2());
        execute(tc_f_generate_key_pair_3());
        execute(tc_f_signWithEcdsaNistp256WithSha256_1());
        execute(tc_f_verifyWithEcdsaNistp256WithSha256_1());
        execute(tc_f_verifyWithEcdsaNistp256WithSha256_2());
        execute(tc_f_verifyWithEcdsaNistp256WithSha256_3());
        execute(tc_f_signWithEcdsaBrainpoolp256WithSha256_1());
        execute(tc_f_signWithEcdsaBrainpoolp384WithSha384_1());
        execute(tc_f_verifyWithEcdsaBrainpoolp256WithSha256_1());
        execute(tc_f_verifyWithEcdsaBrainpoolp256WithSha256_2());
        execute(tc_f_verifyWithEcdsaBrainpoolp256WithSha256_3());
        execute(tc_f_verifyWithEcdsaBrainpoolp384WithSha384_1());
        execute(tc_f_verifyWithEcdsaBrainpoolp384WithSha384_2());
        execute(tc_f_verifyWithEcdsaBrainpoolp384WithSha384_3());
    }
    
garciay's avatar
garciay committed
} // End of module TestCodec_SecuredFuntions