Other Parts Discussed in Thread: CCSTUDIO
Tool/software: Linux
i am having a hard time finding any code examples for using the TI drivers for the AES HW encryption.
i did find this:

but it did not include any code examples.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
Check {PSDK}/example-applications/ti-crypto-examples-git/AES/
http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Examples_and_Demos.html#cryptography
Regards,
Pavel
i did find that shortly after i posted. it seems to be what i am looking for.
FYI i am using code composer in ubuntu 16.04
2 things about adding in the code and libraries:
1) now when i run my debug gdb session it doesn't automatically load to main. i get this output:
GNU gdb (Linaro GDB) 7.8-2014.09
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-arago-linux --target=arm-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<
>.
Find the GDB manual and other documentation resources online at:
<
>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
0xb6fd79c0 in _start () from /opt/ti-processor-sdk-linux-am437x-evm-04.03.00.05/targetNFS/lib/ld-linux-armhf.so.3
Program received signal SIGILL, Illegal instruction.
Cannot access memory at address 0x0
0xb6eef9a8 in ?? () from /opt/ti-processor-sdk-linux-am437x-evm-04.03.00.05/targetNFS/usr/lib/libcrypto.so.1.0.0
and when i hit run THEN i hit my temporary breakpoint at main and then i run like i normall do
2) i am trying to interface with an existing system so i need to be in ecb mode, when i do i get a crash every time when i try to encrypt where as when i tried it with cbc it worked fine. here is my failure message:
Program received signal SIGSEGV, Segmentation fault.
0xb6e850c4 in EVP_EncryptUpdate () from /opt/ti-processor-sdk-linux-am437x-evm-04.03.00.05/targetNFS/usr/lib/libcrypto.so.1.0.0
here is my code:
void aes_init(void)
{
/****************Enabling use of a hardware engine******************/
ENGINE *e;
ENGINE_load_builtin_engines();
if (!(e = ENGINE_by_id("cryptodev")))
fprintf(stderr, "Error finding specified ENGINE\n");
else if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
fprintf(stderr, "Error using ENGINE\n");
else
fprintf(stderr, "Engine successfully enabled\n");
/*******************************************************************/
EVP_CIPHER_CTX_init(&en);
EVP_EncryptInit_ex(&en, EVP_aes_256_ecb(), e, AesKey, NULL); //sets up cipher context e_ctx for encryption with aes_256_ecb cipher type
EVP_CIPHER_CTX_init(&de);
EVP_DecryptInit_ex(&de, EVP_aes_256_ecb(), e, AesKey, NULL); //sets up cipher context d_ctx for decryption with aes_256_ecb cipher type
/* Release the structural reference from ENGINE_by_id() */
ENGINE_free(e);
}
/********************************************************************
* AES encryption function
*********************************************************************/
int aes_encrypt(unsigned char *input, unsigned char *output, unsigned int len)
{
int c_len = 0;
int ret_len = 0;
int EncLen = 0;
EVP_EncryptInit_ex(&en, NULL, NULL, NULL, NULL);
//encryption works on factors of 16, if there are any stragglers we have to round up to a x16 value
if((len & 0x0F) != 0)
{
EncLen = (len & 0xFFF0) + 0x10;
}
else
{
EncLen = len;
}
EVP_EncryptUpdate(&en, output, &c_len, input, EncLen);
ret_len = c_len;
return ret_len;
}
/********************************************************************
* AES decryption function
*********************************************************************/
int aes_decrypt(unsigned char *input, unsigned char *output, unsigned int len)
{
int c_len = 0;
int ret_len = 0;
EVP_DecryptInit_ex(&de, NULL, NULL, NULL, NULL);
EVP_DecryptUpdate(&de, output, &c_len, input, len);
ret_len = c_len;
return ret_len;
}
Linaro GCC toolchain 6.2.1 2016.11 hard-float comes with AM437x PSDK v4.03:
ti-processor-sdk-linux-am437x-evm-04.03.00.05/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc-6.2.1
Or you can download it separate from PSDK from below location:
releases.linaro.org/.../gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz
Refer also to below links for more info regarding cross compile applications with GCC ARM Linaro toolchain.



Regards,
Pavel
cobsonchael said:2) i am trying to interface with an existing system so i need to be in ecb mode, when i do i get a crash every time when i try to encrypt where as when i tried it with cbc it worked fine. here is my failure message:
Program received signal SIGSEGV, Segmentation fault.
0xb6e850c4 in EVP_EncryptUpdate () from /opt/ti-processor-sdk-linux-am437x-evm-04.03.00.05/targetNFS/usr/lib/libcrypto.so.1.0.0
From what I can find, only AES CBC mode is implemented in PSDK/example-applications/ti-crypto-examples-git/AES/
You should modify that application to add ECB support also.
Can you provide what is your output of the below command?
root@am437x-evm:~# openssl help
See also below e2e thread regarding ECB testing from user space:
Regards,
Pavel
Part Number: AM4378
Tool/software: Linux
so when i start the GDBServer and start my debug configuration in code composer i get this error before i even attempt to run any code:
Program received signal SIGILL, Illegal instruction.
Cannot access memory at address 0x0
0xb6f4b9a8 in ?? () from /opt/ti-processor-sdk-linux-am437x-evm-04.03.00.05/targetNFS/usr/lib/libcrypto.so.1.0.0
if i try to run from this point i will make it to the temporary breakpoint in main i expected to hit initially. from there i am able to run my program.
if i do not include crypto and ssl libraries it starts at main no problem.
in the related thread Pavel Botev stated i should be using "Linaro GCC toolchain 6.2.1 2016.11 hard-float" which comes with the SDK 4.03.0.05, which i have installed. so it should be used, right?
did i miss something i needed to add when i added in the libraries?
cobsonchael said:so when i start the GDBServer and start my debug configuration in code composer i get this error before i even attempt to run any code:
Program received signal SIGILL, Illegal instruction.
Cannot access memory at address 0x0
0xb6f4b9a8 in ?? () from /opt/ti-processor-sdk-linux-am437x-evm-04.03.00.05/targetNFS/usr/lib/libcrypto.so.1.0.0
This might be a SW bug if your application. Can you reproduce this issue with the example applications that are coming with PSDK package? See also below e2e thread:

Make sure also you are align with below instructions when using GDBServer:


cobsonchael said:in the related thread Pavel Botev stated i should be using "Linaro GCC toolchain 6.2.1 2016.11 hard-float" which comes with the SDK 4.03.0.05, which i have installed. so it should be used, right?
From what I understand you are building your application from within CCStudio. Make sure for cross compiler path you have "<SDK INSTALL DIR>/linux-devkit/sysroot/x86_64-arago-linux/usr/bin" and for cross compiler prefix you have "arm-linux-gnueabihf-"
http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components.html#ccs-compiling
Regards,
Pavel
yes it does it for the AES example project as well. i don't see how it would be a software problem on my end when it happens before i even get to main.
my cross compiler is set to the right values