SystemC Code Generation for Advanced Encryption Standard
This example shows how to generate SystemC code from MATLAB® code that implements an AES (Advanced Encryption Standard) algorithm.
AES MATLAB Design
AES is a symmetric block cipher that encrypts and decrypts confidential data using the same cipher key. You can design complicated algorithms such as AES using MATLAB code and then generate their equivalent System C code.
In this example, the mlhdlc_aes
function implements the AES encryption algorithm. This function accepts plain text to encrypt and a cipher key as inputs and outputs encrypted text. The mlhdlc_aesd function decrypts the encrypted text to plain text.
Set up the AES model for this example.
mlhdlc_demo_setup('aes');
To review the MATLAB code for encryption and decryption of text, open the files mlhdlc_aes.m
and mlhdlc_aesd.m
.
open('mlhdlc_aes'); open('mlhdlc_aesd');
You can also review the MATLAB test bench file.
open('mlhdlc_aes_tb')
Test the MATLAB Algorithm
To avoid run-time errors, simulate the design by using the test bench.
mlhdlc_aes_tb
1 Plain Text: D1 E8 21 EA A2 19 47 8C F5 F7 28 F8 F5 7C CD 24 Cipher Key: 6C EA CB F6 A8 09 D9 EF AE C2 BE 64 A8 2C B5 08 Cipher Text: 1F 9D 05 17 7B B0 5F 87 99 7A AE F3 9E 82 51 CC Decrypted Plain Text:D1 E8 21 EA A2 19 47 8C F5 F7 28 F8 F5 7C CD 24 !!!!!Decrypted plain text matches the original text.!!!!! 2 Plain Text: 47 0C 19 D3 B2 51 F3 09 70 62 C4 CC 30 7D 72 A5 Cipher Key: B6 C1 47 AE A8 2A 1E 80 F6 57 96 39 C0 41 82 B3 Cipher Text: 2D CF CD F1 30 B8 A0 34 BB B1 BD 26 0B 0C 9D A0 Decrypted Plain Text:47 0C 19 D3 B2 51 F3 09 70 62 C4 CC 30 7D 72 A5 !!!!!Decrypted plain text matches the original text.!!!!! 3 Plain Text: E4 F6 8C 23 26 42 D7 41 D0 3E EE 5A 32 40 9E 79 Cipher Key: 5A D5 96 8D EB 49 C2 C1 61 91 13 0E 88 C7 EF 21 Cipher Text: 65 76 0D 70 C8 3A 59 D9 FD AD F0 E4 B5 61 3B 28 Decrypted Plain Text:E4 F6 8C 23 26 42 D7 41 D0 3E EE 5A 32 40 9E 79 !!!!!Decrypted plain text matches the original text.!!!!! 4 Plain Text: 92 78 03 56 2A CB 50 87 2A 9A 43 A7 B0 C0 73 15 Cipher Key: 3B EA 27 D3 8A FF 14 71 1B F6 01 C6 D1 DE 16 66 Cipher Text: 9B 77 32 8F 14 FD A5 F7 BB 2B 5B 45 CD 87 59 E5 Decrypted Plain Text:92 78 03 56 2A CB 50 87 2A 9A 43 A7 B0 C0 73 15 !!!!!Decrypted plain text matches the original text.!!!!! 5 Plain Text: 43 CD 6E E9 2F 44 25 23 DF 94 8D 25 DA 9F 5A 83 Cipher Key: 67 13 3D 20 2F 3D 6B 0D E7 F2 7E 7D 56 E6 5F 1C Cipher Text: 96 9C D7 D1 FB 3C 26 B4 31 0F 7C 64 1A DE 4B BB Decrypted Plain Text:43 CD 6E E9 2F 44 25 23 DF 94 8D 25 DA 9F 5A 83 !!!!!Decrypted plain text matches the original text.!!!!!
Generate SystemC Code by Using HDL Workflow Advisor
SystemC code generation with the HDL Workflow Advisor has the following basic steps:
At the MATLAB command line, set up the high-level synthesis (HLS) tool path for SystemC code generation by using the function
hdlsetuphlstoolpath
.Create a HDL Coder project by adding the
mlhdlc_aes.m
design file andmlhdlc_aes_tb.m
test bench file to the HDL workflow advisor.Launch the HDL Workflow Advisor to generate SystemC code. Do not run floating point to fixed point conversion on this design, as the AES MATLAB code is already in fixed point and suitable for SystemC code generation.
For detailed information about these steps, see Get Started with MATLAB to SystemC Workflow Using the Command Line Interface or Get Started with MATLAB to SystemC Workflow Using HDL Coder App.