Protect Models to Conceal Contents - MATLAB & Simulink (original) (raw)

When you want to share a model with a third party without revealing intellectual property, protect the model. Protecting a model conceals the implementation details of the original model by compiling it into a referenced model. The protected model includes derived files to support the optional functionalities that you specify.

When you protect a model by using Simulink® Coder™, you can allow the user of the protected model to:

You can optionally password-protect each option. If you choose password protection for one of these options, the software protects the supporting files by using AES-256 encryption. Before you create a protected model, consider how the third party will use the model and these Best Practices for Creating Protected Models.

When you create a protected model:

This example shows how to create a protected model from a referenced model for read-only viewing, simulation, or code generation.

Prepare the Parent Model

Optionally, configure the Model blocks in the parent model to refer to the original referenced model. This step prevents the Model blocks from becoming protected references when you create the protected model.

  1. Open the parent model that references the model you want to protect. For this example, open the model named [sldemo_mdlref_basic](https://mdsite.deno.dev/matlab:openExample%28'sldemo%5Fmdlref%5Fbasic'%29).
  2. For each Model block, open the Block Parameters dialog box and specify the extension .slx in the Model name field.
    When both the model and the protected model exist in the same folder,.slxp takes precedence over .slx. If you do not specify an extension, the original Model block refers to the protected model instead of the original model.
  3. Click OK.

Protect the Referenced Model

In the sldemo_mdlref_basic model, click any of the three Model blocks. On the Simulink toolstrip, on the Model Block tab, clickProtect.

The Protected Model Creator opens.

Protected Model Creator opened for sldemo_mdlref_counter

On the General tab, specify the functionality to support.

  1. Select Simulation and Code generation. These options allow the protected model user to simulate and generate code for a model that references the protected model. If you want to password-protect the functionality of the protected model, enter a password with a minimum of eight characters. Each option can have a unique password.
    Tip
    The Protected Model Creator caches your settings for a model during a MATLAB® session. If you close and reopen the dialog box, the settings persist. Passwords and tunable parameter selections are not cached. To restore the default settings, clickReset. (since R2023b)
  2. If you have an Embedded Coder license and the model specifies an ERT-based system target file, for example, ert.tlc, the Code interface field is visible.
    In this example, sldemo_mdlref_basic does not specify an ERT-based system target file, therefore the Code interface options are not available in the Protected Model Creator.
  3. From the Content type list, selectObfuscated source code to conceal the source code purpose and logic of the protected model. For more information on the model protection options, see Content type.
  4. Optionally, specify a custom text tag in the Identifier tag box. For example, to store file provenance information in a protected model, specify the job number, Git™ commit, or continuous integration system tag associated with creating the protected model. (since R2024b)

On the Simulation Options tab, specify the parameters that users of the protected model can tune during simulation.

  1. To compile the model and list tunable parameters, in the Tunable parameters for simulation section, click Refresh (since R2023b).
  2. Select the parameters that you want the protected model user to be able to tune during simulation.
    In this example, sldemo_mdlref_basic does not have any tunable parameters.

On the Save Options tab, specify where to save the protected model, whether to save the protected model in a project with its supporting files, and whether to create a harness model.

  1. In the Destination folder box, specify the folder path for the protected model. The default value is the current working folder.
  2. To automatically collect, create, and package supporting files with the protected model, select Package protected model with dependencies in a project.
    Note
    Before sharing the project, check whether the project contains the necessary supporting files. If supporting files are missing, simulating or generating code for the related harness model can help identify the missing files. Add the missing dependencies to the project and update the harness model as needed.
  3. Selecting Package protected model with dependencies in a project selects Create harness model for protected model. The harness model is included in the project and provides an isolated environment for the Model block that references the protected model.
    Harness model with Model block that references the protected model sldemo_mdlref_counter.slxp

To further customize your protected model, you can:

To create the protected model, click Create.

A project archive (.mlproj) that contains the protected model, harness model, and supporting files appears in the specified destination folder. To test the protected model, extract the contents of the project archive by double-clicking it in the Files panel and specifying the destination folder. Alternatively, right-click the project archive. Then, click Extract Here. The project opens, and the extracted files are in a new folder named after the project archive.

You can test the protected model to compare it to the original model. For more information, see Test Protected Models.

To use the protected model in a model hierarchy, reference it through aModel block such as the one included in the harness model. TheSimulation mode for Model blocks that reference a protected model is set to Accelerator. You cannot change the mode. For more information, see Reference Protected Models from Third Parties.

Other Methods of Protecting Models

To create a protected model from the top model in the current model hierarchy, use one of these options:

To create a protected model programmatically, use the Simulink.ModelReference.protect function.

Protected Model Report

When you create the protected model from the Simulink Editor, a protected model report is generated and is included as part of the protected model. For this example, to view the protected model report, double-click the protected model or right-click the protected-model badge icon on the block in the harness model and select .

Protected model report for sldemo_mdlref_counter

The report contains:

The report does not contain other sections that appear in a code generation report for non-protected models, such as a code metrics report and traceability report, because these reports include more information about the model design.

To get information about the protected model programmatically, use the slxpinfo function.

Protected Model Requirements and Limitations

When you create a protected model, consider these following requirements:

The model must also meet the requirements listed in Model Reference Requirements and Limitations.

Code Generation Requirements and Limitations

To create a protected model that supports code generation, the model being protected must meet these requirements:

To avoid an error during code generation of a model that includes a protected model:

Nested Protected Model Requirements and Limitations

To enable a recipient of your protected model to protect a model that references it, your protected model must:

If the model that you want to protect references a protected model, the referenced protected model must meet the preceding requirements.

When you protect a model that references a protected model, you must specify the tunable parameters of the referenced protected model as tunable for the model you are protecting.

Note

A protected model that you create with the HDL code generation option selected allows encryption and support for simulation and HDL code generation from a model that references the protected model. You cannot obfuscate the HDL source code, have callbacks, or use nested protected models with this option. To learn more about HDL code generation limitations, see Protected Model Restrictions for HDL Code Generation (HDL Coder).

See Also

Protected Model Creator

Topics