Skip to content
LibItsSecurity_Functions.ttcn 139 KiB
Newer Older
garciay's avatar
garciay committed
/**
 *  @author   ETSI / STF481 / STF507 / STF517 / STF538
garciay's avatar
garciay committed
 *  @version  $URL$
 *            $Id$
 *  @desc     Module containing functions for Security Protocol
garciay's avatar
garciay committed
 *  @copyright   ETSI Copyright Notification
 *               No part may be reproduced except as authorized by written permission.
 *               The copyright and the foregoing restriction extend to reproduction in all media.
 *               All rights reserved.
garciay's avatar
garciay committed
 *
 */
module LibItsSecurity_Functions {
    import from LibCommon_BasicTypesAndValues 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;
    
    // LibItsCommon
    import from LibItsCommon_Functions all;
    import from LibItsCommon_TypesAndValues all;
    
    // LibItsSecurity
    import from LibItsSecurity_TypesAndValues all;
    import from LibItsSecurity_Templates all;
    import from LibItsSecurity_Pixits all;
garciay's avatar
garciay committed
    import from LibItsSecurity_Pics all;
    import from LibItsSecurity_TestSystem all;
garciay's avatar
garciay committed
    
    group helpersFunctions {
garciay's avatar
garciay committed
         * @desc    Produces a 256-bit (32-byte) hash value
         * @param   p_toBeHashedData Data to be used to calculate the hash value
         * @return  The hash value
         */
garciay's avatar
garciay committed
                                  in octetstring p_toBeHashedData
            return fx_hashWithSha256(p_toBeHashedData);
        } // End of function f_hashWithSha256
garciay's avatar
garciay committed
         * @desc    Produces a 384-bit (48-byte) hash value
         * @param   p_toBeHashedData Data to be used to calculate the hash value
         * @return  The hash value
         */
        function f_hashWithSha384(
                                  in octetstring p_toBeHashedData
        ) return Oct48 {
            return fx_hashWithSha384(p_toBeHashedData);
        } // End of function f_hashWithSha256
        
        /**
garciay's avatar
garciay committed
         * @desc    Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature
garciay's avatar
garciay committed
         * @param   p_toBeSignedSecuredMessage    The data to be signed
         * @return  The signature value
         */
        function f_signWithEcdsaNistp256WithSha256(
                                                   in octetstring p_toBeSignedSecuredMessage,
                                                   in Oct32 p_privateKey
        ) return octetstring {
            return fx_signWithEcdsaNistp256WithSha256(
                p_toBeSignedSecuredMessage,
        } // End of function f_signWithEcdsaNistp256WithSha256
garciay's avatar
garciay committed
        /**
         * @desc    Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature
         * @param   p_toBeSignedSecuredMessage    The data to be signed
         * @param   p_privateKey                  The private key
garciay's avatar
garciay committed
         * @return  The signature value
         */
        function f_signWithEcdsaBrainpoolp256WithSha256(
                                                        in octetstring p_toBeSignedSecuredMessage,
                                                        in Oct32 p_privateKey
        ) return octetstring {
garciay's avatar
garciay committed
            return fx_signWithEcdsaBrainpoolp256WithSha256(
                p_toBeSignedSecuredMessage,
                p_privateKey
            );
            
        } // End of function f_signWithEcdsaBrainpoolp256WithSha256
        
garciay's avatar
garciay committed
        /**
         * @desc    Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature
         * @param   p_toBeSignedSecuredMessage    The data to be signed
         * @param   p_privateKey                  The private key
garciay's avatar
garciay committed
         * @return  The signature value
         */
        function f_signWithEcdsaBrainpoolp384WithSha384(
                                                        in octetstring p_toBeSignedSecuredMessage,
                                                        in Oct48 p_privateKey
        ) return octetstring {
garciay's avatar
garciay committed
            return fx_signWithEcdsaBrainpoolp384WithSha384(
                p_toBeSignedSecuredMessage,
                p_privateKey
            );
            
        } // End of function f_signWithEcdsaBrainpoolp384WithSha384
        
        function f_decrypt(
                           in EtsiTs103097Data    p_encrypedSecuredMessage,
                           out EtsiTs103097Data   p_decrypedSecuredMessage
        ) return boolean {
            if (not(ischosen(p_encrypedSecuredMessage.content.encryptedData))) {
                var PKRecipientInfo v_pKRecipientInfo;
                var RecipientInfo v_recipientInfo := p_encrypedSecuredMessage.content.encryptedData.recipients[0];
                
                if (ischosen(v_recipientInfo.certRecipInfo)) {
                    v_pKRecipientInfo := p_encrypedSecuredMessage.content.encryptedData.recipients[0].certRecipInfo;
                    // Read the certificate based on the recipientId
                } else if (ischosen(v_recipientInfo.signedDataRecipInfo)) {
                    v_pKRecipientInfo := p_encrypedSecuredMessage.content.encryptedData.recipients[0].signedDataRecipInfo;
                    // Read the certificate based on the recipientId
                } else {
                    return false;
                }
                
                /*if (ischosen(v_pKRecipientInfo.encKey.eciesNistP256)) {
                    var octetstring v_encryptedSecuredMessage;
                    var SymmetricCiphertext v_ciphertext := p_encrypedSecuredMessage.content.encryptedData.ciphertext;
                    f_decryptWithEciesNistp256WithSha256(
                                                      v_ciphertext.aes128ccm.ccmCiphertext,
                                                      ,
                                                      ,
                                                      v_pKRecipientInfo.encKey.eciesNistP256.c,
                                                      v_ciphertext.aes128ccm.nonce,
                                                      v_pKRecipientInfo.encKey.eciesNistP256.t); 
                } else if (ischosen(v_pKRecipientInfo.encKey.eciesBrainpoolP256r1)) {
                }*/
            }
            
            return false;
        } // End of function f_signWithEcdsaBrainpoolp384WithSha384
        /**
         * @desc    Produces a Elliptic Curve Digital Encrytion Algorithm (ECIES) encryption
         * @param   p_toBeEncryptedSecuredMessage    The data to be encrypted
         * @return  The encrypted value
         */
        function f_encryptWithEciesNistp256WithSha256(
                                                      in octetstring p_toBeEncryptedSecuredMessage,
                                                      in Oct32 p_peerPublicKeyX,
                                                      in Oct32 p_peerPublicKeyY,
                                                      out Oct32 p_publicEncKeyX, 
                                                      out Oct32 p_publicEncKeyY,
                                                      out Oct16 p_hmac,
                                                      out Oct16 p_authentication_vector,
                                                      out Oct12 p_nonce
        ) return octetstring {
            return fx_encryptWithEciesNistp256WithSha256(
                p_toBeEncryptedSecuredMessage, 
                p_peerPublicKeyX,
                p_peerPublicKeyY,
                p_publicEncKeyX,
                p_publicEncKeyY,
                p_hmac,
                p_authentication_vector,
                p_nonce
            );
        } // End of function f_encryptWithEciesNistp256WithSha256
        
        /**
         * @desc    Produces a Elliptic Curve Digital Encrytion Algorithm (ECIES) decryption
         * @param   p_encryptedSecuredMessage    The data to be decrypted
         * @return  The decrypted value
         */
        function f_decryptWithEciesNistp256WithSha256(
                                                      in octetstring p_encryptedSecuredMessage,
                                                      in Oct32 p_publicKeyX,
                                                      in Oct32 p_publicKeyY,
                                                      in Oct12 p_nonce,
                                                      in Oct12 p_tag                                                      
        ) return octetstring {
            return fx_decryptWithEciesNistp256WithSha256(
                p_encryptedSecuredMessage,
                p_publicKeyX, 
                p_publicKeyY, 
                p_nonce, 
                p_tag
            );
            
        } // End of function f_decryptWithEcdsaNistp256WithSha256
        
garciay's avatar
garciay committed
         * @desc Compute the HashedId8 value from the hash value
         * @param p_hash The hash value
         * @return The HashedId8 value
         * @verdict
         */
        function f_HashedId8FromSha256( 
garciay's avatar
garciay committed
                                       in Oct32 p_hash
Loading full blame...