Commit f14617db authored by Yann Garcia's avatar Yann Garcia
Browse files

Add decrypt functions with uncompressed public key

parent dd305e71
Loading
Loading
Loading
Loading
+208 −131
Original line number Diff line number Diff line
@@ -318,6 +318,9 @@ module LibItsSecurity_Functions {
                } else if (ischosen(v_recipientInfo.signedDataRecipInfo)) {
                  v_pKRecipientInfo := p_encrypedSecuredMessage.content.encryptedData.recipients[0].signedDataRecipInfo;
                  // Read the certificate based on the recipientId
                } else if (ischosen(v_recipientInfo.rekRecipInfo)) {
                  v_pKRecipientInfo := p_encrypedSecuredMessage.content.encryptedData.recipients[0].rekRecipInfo;
                  // No certificate based 
                } else {
                  log("*** " & testcasename() & ":ERROR: Unsupported RecipientInfo variant ***");
                  return false;
@@ -353,6 +356,18 @@ module LibItsSecurity_Functions {
                                                                                              p_salt,
                                                                                              p_aes_sym_enc_key
                                                                                              );
                        } else if (ischosen(v_pKRecipientInfo.encKey.eciesNistP256.v.uncompressedP256)) {
                            v_decryptedSecuredMessage := f_decryptWithEciesNistp256WithSha256_1(
                                                                                                v_ciphertext.aes128ccm.ccmCiphertext,
                                                                                                p_encryptPrivateKey,
                                                                                                v_pKRecipientInfo.encKey.eciesNistP256.v.uncompressedP256.x,
                                                                                                v_pKRecipientInfo.encKey.eciesNistP256.v.uncompressedP256.y,
                                                                                                v_pKRecipientInfo.encKey.eciesNistP256.c,
                                                                                                v_pKRecipientInfo.encKey.eciesNistP256.t,
                                                                                                v_ciphertext.aes128ccm.nonce,
                                                                                                p_salt,
                                                                                                p_aes_sym_enc_key
                                                                                                );
                        } else {
                            log("*** " & testcasename() & ":ERROR: Non canonical ephemeral encryption keys ***");
                            return false;
@@ -390,6 +405,18 @@ module LibItsSecurity_Functions {
                                                                                                     p_salt,
                                                                                                     p_aes_sym_enc_key
                                                                                                     );
                        } else if (ischosen(v_pKRecipientInfo.encKey.eciesBrainpoolP256r1.v.uncompressedP256)) {
                            v_decryptedSecuredMessage := f_decryptWithEciesBrainpoolp256r1WithSha256_1(
                                                                                                       v_ciphertext.aes128ccm.ccmCiphertext,
                                                                                                       p_encryptPrivateKey,
                                                                                                       v_pKRecipientInfo.encKey.eciesBrainpoolP256r1.v.uncompressedP256.x,
                                                                                                       v_pKRecipientInfo.encKey.eciesBrainpoolP256r1.v.uncompressedP256.y,
                                                                                                       v_pKRecipientInfo.encKey.eciesBrainpoolP256r1.c,
                                                                                                       v_pKRecipientInfo.encKey.eciesBrainpoolP256r1.t,
                                                                                                       v_ciphertext.aes128ccm.nonce,
                                                                                                       p_salt,
                                                                                                       p_aes_sym_enc_key
                                                                                                       );
                        } else {
                            log("*** " & testcasename() & ":ERROR: Non canonical ephemeral encryption keys ***");
                            return false;
@@ -496,6 +523,30 @@ module LibItsSecurity_Functions {
                                                       );
        } // End of function f_decryptWithEcdsaNistp256WithSha256

        function f_decryptWithEciesNistp256WithSha256_1(
                                                        in octetstring p_encryptedSecuredMessage,
                                                        in Oct32 p_privateEncKey,
                                                        in Oct32 p_publicEphemeralKeyX,
                                                        in Oct32 p_publicEphemeralKeyY,
                                                        in Oct16 p_encrypted_sym_key,
                                                        in Oct16 p_authentication_vector,
                                                        in Oct12 p_nonce,
                                                        in Oct32 p_salt,
                                                        out Oct16 p_aes_sym_enc_key
                                                        ) return octetstring {
          return fx_decryptWithEciesNistp256WithSha256_1(
                                                         p_encryptedSecuredMessage,
                                                         p_privateEncKey,
                                                         p_publicEphemeralKeyX, 
                                                         p_publicEphemeralKeyY,
                                                         p_encrypted_sym_key,
                                                         p_authentication_vector,
                                                         p_nonce,
                                                         p_salt,
                                                         p_aes_sym_enc_key
                                                         );
        } // End of function f_decryptWithEcdsaNistp256WithSha256_1

        /**
         * @desc    Produces a Elliptic Curve Digital Encrytion Algorithm (ECIES) encryption using Brainpool-P256 algorithm
         * @param   p_toBeEncryptedSecuredMessage    The data to be encrypted
@@ -574,6 +625,30 @@ module LibItsSecurity_Functions {
                                                              );
        } // End of function f_decryptWithEcdsaBrainpoolp256r1WithSha256

        function f_decryptWithEciesBrainpoolp256r1WithSha256_1(
                                                               in octetstring p_encryptedSecuredMessage,
                                                               in Oct32 p_privateEncKey,
                                                               in Oct32 p_publicEphemeralKeyX, 
                                                               in Oct32 p_publicEphemeralKeyY,
                                                               in Oct16 p_encrypted_sym_key,
                                                               in Oct16 p_authentication_vector,
                                                               in Oct12 p_nonce,
                                                               in Oct32 p_salt,
                                                               out Oct16 p_aes_sym_enc_key
                                                               ) return octetstring {
          return fx_decryptWithEciesBrainpoolp256r1WithSha256_1(
                                                                p_encryptedSecuredMessage,
                                                                p_privateEncKey,
                                                                p_publicEphemeralKeyX, 
                                                                p_publicEphemeralKeyY,
                                                                p_encrypted_sym_key,
                                                                p_authentication_vector,
                                                                p_nonce,
                                                                p_salt,
                                                                p_aes_sym_enc_key
                                                                );
        } // End of function f_decryptWithEcdsaBrainpoolp256r1WithSha256

        /**
         * @desc    Produces a Elliptic Curve Digital Encrytion Algorithm (ECIES) encryption using Sm2-P256 algorithm
         * @param   p_toBeEncryptedSecuredMessage    The data to be encrypted
@@ -3571,6 +3646,7 @@ module LibItsSecurity_Functions {
             * @return  The decrypted message
             */
            external function fx_decryptWithEciesNistp256WithSha256(in octetstring p_encryptedSecuredMessage, in Oct32 p_privateEncKey, in Oct32 p_publicEphemeralKeyCompressed, in integer p_ephemeralKeyModeCompressed, in Oct16 p_encrypted_sym_key, in Oct16 p_authentication_vector, in Oct12 p_nonce, in Oct32 p_salt, out Oct16 p_aes_sym_enc_key) return octetstring;
            external function fx_decryptWithEciesNistp256WithSha256_1(in octetstring p_encryptedSecuredMessage, in Oct32 p_privateEncKey, in Oct32 p_publicEphemeralKeyX, in Oct32 p_publicEphemeralKeyY, in Oct16 p_encrypted_sym_key, in Oct16 p_authentication_vector, in Oct12 p_nonce, in Oct32 p_salt, out Oct16 p_aes_sym_enc_key) return octetstring;

            /**
             * @desc    Produces a Elliptic Curve Digital Encrytion Algorithm (ECIES) encryption using Brainpool-P256 algorithm
@@ -3599,6 +3675,7 @@ module LibItsSecurity_Functions {
             * @return  The decrypted message
             */
            external function fx_decryptWithEciesBrainpoolp256r1WithSha256(in octetstring p_encryptedSecuredMessage, in Oct32 p_privateEncKey, in Oct32 p_publicEphemeralKeyCompressed, in integer p_ephemeralKeyModeCompressed, in Oct16 p_encrypted_sym_key, in Oct16 p_authentication_vector, in Oct12 p_nonce, in Oct32 p_salt, out Oct16 p_aes_sym_enc_key) return octetstring;
            external function fx_decryptWithEciesBrainpoolp256r1WithSha256_1(in octetstring p_encryptedSecuredMessage, in Oct32 p_privateEncKey, in Oct32 p_publicEphemeralKeyX, in Oct32 p_publicEphemeralKeyY, in Oct16 p_encrypted_sym_key, in Oct16 p_authentication_vector, in Oct12 p_nonce, in Oct32 p_salt, out Oct16 p_aes_sym_enc_key) return octetstring;

             /**
             * @desc    Produces a Elliptic Curve Digital Encrytion Algorithm (ECIES) encryption using Sm2-P256 algorithm