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.

PROCESSOR-SDK-AM335X: AM335x Sitara HS HW Cryptography Accelerator

Part Number: PROCESSOR-SDK-AM335X

Hi there,

After have readed some documentation (www.ti.com/.../spry303d.pdf + www.ti.com/.../spry198a.pdf

I still have some questions :

Questions:
1. Can you share the hardware level documentation of the Sitara AM335X HW Cryptographic Accelerator ?

2. How can I link mbedTLS with HW Cryptographic Accelerator?

3. How can I speed test without using SDK ?

Best regards.

Thanks.

Alexis.

  • Hi Alexis,
    Per our off-line email exchange, we've shard AM335x Cryopto TRM with you.
    There's Linux kernel crypto driver support for your reference.
    software-dl.ti.com/.../Crypto.html
    Best,
    -Hong

  • Hi Hong,

    Thanks for your reply.

    I've downloaded Linux AM335X SDK Source code available on : software-dl.ti.com/.../Release_Specific_PLSDK_Release_Notes.html

    on git://git.ti.com/processor-sdk/processor-sdk-linux.git :  "branch processor-sdk-linux-04.03.00"

    I've found the Crypto driver in folder : /driver/crypto

    I need the source code of crypto driver for AM335X but I've several folders : which one is for AM335X?

  • Hi Alexis,
    Thanks for reaching out to us.
    AM335x crypto driver in folder:/drivers/crypto/omap-xxxx.c. For example, omap-sham.c, omap-aes.c...
    Plus /drivers/char/hw_random/omap-rng.c
    Best,
    -Hong

  • Thanks Hong for your Reply,

    Now I'm trying to implement SHAM driver (In a Bare Metal version : polling mode) following the AM335x Cryopto TRM.

    But when I'm trying to fill the DATA_IN buffer in memory : memory still with 0x00000000 value as show in this pict :

    I think it could be an initialisation problem but I can't found the issue.

    So I can't obtain a SHA1 digest :/

    Here the source code : 

    SHAMDriverTI.zip

    Could you quickly see the code and show me where should be the issue ? ;)

    Best Regards,

    Have a good day !

    Thanks for your help !

    Alexis

  • Nobody can help me?

    Thank you ;)

  • Hi Alexis,
    Sorry for delayed response. we're currently having severe weather causing power outage across Texas area.
    <Figure 3-4. Polling Mode> in the crypto TRM lists sequence for polling mode.
    Can we check the digest output registers (i.e. DIGEST_x) got updated upon the digest result becomes ready?
    Best,
    -Hong

  • Hi Hong,

    Thanks again for your help ! :)

    For MD5 for example :

    When I writte in DATA_I register it seem not to work (still at 0x000000000) value.

    •  I can see INPUT READY flag before filling data
    • Then at each loop : I can see SHA_S_LENGTH register decreasing from 64 to 0.
    • At the end of my loop : I can find and read a digest in IDIGEST register.
    • Output Flag is Ready
    • Then I read the memory

    I've bring modification in source code there were some issue in the old one : MD5drivers.zip

    When I'm read it :

    For example for (0x00000000)*16 data filling.

    I've got this hash:  ( HashMD5:91773174b767ab1fd08ea56eac1d1f03 ).

    IDIGEST_A Register: 0x031F1DAC

    IDIGEST_B_Register : 0x6EA58ED0 

    IDIGEST_C_Register : 0x1FAB67B7

    IDIGEST_D_Register : 0x74317791

    I can't understand where is my issue ;)

    Do you have an idea about it?

    PS : That is why I'm trying to compare with omap-sham.c in Linux Kernel but I've some difficulties to understand the code.

    Best regards.
    Alexis.

  • Hi Alexis,

    I tested MD5 hash using Linux crypto driver on AM335x GP EVM.

    I used the same testing input vector as yours, i.e., 16 "0x00000000", and verified that the MD5 hash calculated with HW crypto engine is the same as the one calculated with openssl SW implementation. I listed below the log captured from my test run for your reference.

    root@am335x-evm:/usr/openssl_test# ./md5_test_1.sh zero_64b.bin
    [   55.279297] cryptd: max_cpu_qlen set to 1000
    OpenSSL 1.0.2r  26 Feb 2019
    remove cryptodev => openssl SW implementation
    [   55.477639] cryptodev: driver unloaded.
    md5 w/ openssl SW implementation
    MD5(zero_64b.bin)= 3b5d3c7d207e37dceeedd301e35e2e58
    install cryptodev => openssl crypto HW engine
    [   55.543667] cryptodev: driver 1.9 loaded.
    md5 w/ openssl HW crypto engine implementation
    engine "cryptodev" set.
    MD5(zero_64b.bin)= 3b5d3c7d207e37dceeedd301e35e2e58
    root@am335x-evm:/usr/openssl_test#

    I also uploaded my testing script in attachment.

    BTW, have you tried using HIB2 or SHA_P_xxxx registers starting @0x53100000 ?

    Best,
    -Hong

    #!/bin/bash
    in_file_bin=$1
    
    openssl10 version
    
    echo "remove cryptodev => openssl SW implementation"
    modprobe -r cryptodev
    echo "md5 w/ openssl SW implementation"
    openssl10 dgst -md5 $in_file_bin
    
    echo "install cryptodev => openssl crypto HW engine"
    modprobe cryptodev
    echo "md5 w/ openssl HW crypto engine implementation"
    openssl10 dgst -md5 -engine cryptodev $in_file_bin
    

  • Hi Hong,

    Thanks for you script.

    I've the same result as you with cryptodev.

    I think OpenSSL is correct and OMAP-SHAM (with cryptodev is also correct) ;)

    But doesn't work with my soft :(

    SHA_P is the same as SHA_S :

    Same result : HashMD5:91773174b767ab1fd08ea56eac1d1f03

    It seem to have a problem in my soft but I don't know what 

    Best,

    Alexis.

  • In comparison with Linux Kernel Source Code : I think that I have to be carreful with endianess with the result.

    In the same time I'm also wondering why I am not be able to READ SHA_S_DATA_i_IN Register ...

    Best Regards.

    Alexis.

  • Hi Alexis,
    I captured two log files, and uploaded them in attachment for your reference:
    - am3_hash_md5_1_before.txt: SHA/MD5 registers are configured, just before filling SHA/MD5 input buffers
    - am3_hash_md5_1_after.tx: right after filling SHA/MD5 input buffers
    Note that in my testing
    - The same testing input vector as yours, i.e., 16 "0x00000000" @0x004016D8
    - SHA/MD5 register @0x53000000(Physical Addr) is mapped to 0xAFD00000(Virtual Addr)
    - SHA_S_DATA_i_IN/SHA_P_DATA_i_IN registers are not visible from JTAG debugger after filling in with input stream as shown in my testing

    Hope the attached two log files are helpful for debugging your bare-metal crypto code.
    Best,
    -Hong

    ===================================================
    22. Feb 2021
    21:14:52
    ===================================================
    SHA/MD5 input stream @0x004016D8
    SHA/MD5 Register @0x53000000(Physical Addr)/0xAFD00000(Virtual Addr)
    B::data.dump_0x004016D8++0x3F
    ________address|________0________4________8________C_0123456789ABCDEF
       ZSD:004016D0|                  >00000000 00000000         ........
       ZSD:004016E0| 00000000 00000000 00000000 00000000 ................
       ZSD:004016F0| 00000000 00000000 00000000 00000000 ................
       ZSD:00401700| 00000000 00000000 00000000 00000000 ................
       ZSD:00401710| 00000000 00000000                   ........
    B::data.dump_0xAFD00000++0x14F
    ________address|________0________4________8________C_0123456789ABCDEF
       ZSD:AFD00000|>00000000 00000000 00000000 00000000 ................
       ZSD:AFD00010| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00020| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00030| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00040| 00000000 00000018 00000040 00000000 ........@.......
       ZSD:AFD00050| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00060| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00070| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00080| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00090| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000A0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000B0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000C0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000D0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000E0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000F0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00100| 40000C03 00000000 00000000 00000000 ...@............
       ZSD:AFD00110| 00000021 00000001 00000002 00000007 !...............
       ZSD:AFD00120| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00130| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00140| 00000003 00000000 00000000 00000000 ................
    

    ===================================================
    22. Feb 2021
    21:15:02
    ===================================================
    SHA/MD5 input stream @0x004016D8
    SHA/MD5 Register @0x53000000(Physical Addr)/0xAFD00000(Virtual Addr)
    B::data.dump_0x004016D8++0x3F
    ________address|________0________4________8________C_0123456789ABCDEF
       ZSD:004016D0|                  >00000000 00000000         ........
       ZSD:004016E0| 00000000 00000000 00000000 00000000 ................
       ZSD:004016F0| 00000000 00000000 00000000 00000000 ................
       ZSD:00401700| 00000000 00000000 00000000 00000000 ................
       ZSD:00401710| 00000000 00000000                   ........
    B::data.dump_0xAFD00000++0x14F
    ________address|________0________4________8________C_0123456789ABCDEF
       ZSD:AFD00000|>00000000 00000000 00000000 00000000 ................
       ZSD:AFD00010| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00020| 7D3C5D3B DC377E20 01D3EDEE 582E5EE3 ;]<} ~7......^.X
       ZSD:AFD00030| F0E1D2C3 11155868 A78FF964 A44FFABE ....hX..d.....O.
       ZSD:AFD00040| 00000040 00000018 00000000 00000000 @...............
       ZSD:AFD00050| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00060| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00070| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00080| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00090| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000A0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000B0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000C0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000D0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000E0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD000F0| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00100| 40000C03 00000000 00000000 00000000 ...@............
       ZSD:AFD00110| 00000021 00000001 00000008 00000007 !...............
       ZSD:AFD00120| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00130| 00000000 00000000 00000000 00000000 ................
       ZSD:AFD00140| 00000003 00000000 00000000 00000000 ................
    

  • Hi Alexis,
    I took a closer look at your screen-shot from your test run, and noticed that the following change is needed:
    CLOSE_HASH bit or SHA_S_MODE[4] needs to be set to "1" to close the hash calculation in hash_final() call.
    Best,
    -Hong

  • Thanks you very much for your help Hong : Sorry for delayed reponse. I tried to find by myself before posting here again.

    What code are you using?

    I take into account your changement now it works halfways, I had the same memory as you except the CLOSE_HASH ;)

    It only work when the REGISTER_DATA_LENGHT is a multiple of 4 and less than 54.

    I notice I have to take into account part (3.3.6.1.3 Closing a Hash ) of TRM.

    For example this kind of thing work well :

    Data Written : 0x01010101 (SHA_DATA_0_IN)
    SHA_S_LENGHT : 4
    HashMD5: 3B5B9852567EF7618AAC7F5F2D74EF74

    In attachement my test : with different char* value (And a comparaison with True Hash) :

    Msg : Hell size : 4
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 4
    HashMD5: 1824E8E0307CBFDD1993511AB040075C
    TrueMD5: 1824e8e0307cbfdd1993511ab040075c
    
    Msg : Hello size : 5
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 5
    Data to write in memory : 0x0000006F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 5
    HashMD5: 631628770AA4A54C3A78AC2FBD064270
    TrueMD5 : 8b1a9953c4611296a827abf8c47804d7
    
    Msg : Hello size : 5
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 5
    Data to write in memory : 0x0000006F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 5
    HashMD5: 631628770AA4A54C3A78AC2FBD064270
    TrueMD5 : 4ac214eea0fed274d98fac96452d9bd4
    
    Msg : Hello size : 8
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 8
    Data to write in memory : 0x0000006F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 8
    HashMD5: 4AC214EEA0FED274D98FAC96452D9BD4
    TrueMD5 : 8b1a9953c4611296a827abf8c47804d7
    
    Msg : "\x48\x65\x6c\x6c\x6f\x00\x00\x00" (Hello) size : 8
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 8
    Data to write in memory : 0x0000006F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 8
    HashMD5: 4AC214EEA0FED274D98FAC96452D9BD4
    TrueMD5 : 8b1a9953c4611296a827abf8c47804d7
    
    Msg : Helloooo size : 8
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 8
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 8
    HashMD5: AA5CB4C38DBF3483BA58A2253362B676
    TrueMD5 : aa5cb4c38dbf3483ba58a2253362b676
    
    Msg : Helloooooooooooooooooooo size : 24
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 24
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 24
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_2_IN))
    SHA_S_LENGTH : 24
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_3_IN))
    SHA_S_LENGTH : 24
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_4_IN))
    SHA_S_LENGTH : 24
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_5_IN))
    SHA_S_LENGTH : 24
    HashMD5: 6FC80A445D8C56AC369B5D5E1496D64F
    TrueMD5 : 6fc80a445d8c56ac369b5d5e1496d64f
    
    Msg : Helloooooooooooooooooooooooooooooooooooooooooooooooo size : 52
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_2_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_3_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_4_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_5_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_6_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_7_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_8_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_9_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_10_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_11_IN))
    SHA_S_LENGTH : 52
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_12_IN))
    SHA_S_LENGTH : 52
    HashMD5: CCE1967D8649F9884A3B3436E2E1A1AD
    TrueMD5 :cce1967d8649f9884a3b3436e2e1a1ad
    
    Msg : Helloooooooooooooooooooooooooooooooooooooooooooooooooooo size : 56
    Data to write in memory : 0x6C6C6548 ((SHA_S_DATA_0_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_1_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_2_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_3_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_4_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_5_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_6_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_7_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_8_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_9_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_10_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_11_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_12_IN))
    SHA_S_LENGTH : 56
    Data to write in memory : 0x6F6F6F6F ((SHA_S_DATA_13_IN))
    SHA_S_LENGTH : 56
    HashMD5: BFF764E9B8AD553D08A6D47D35EB7F1E
    TrueMD5 : de3704c70e3c63f359f45e65c4cf4d5e
    
    
    
    
    
    

    I have also notice that, I've the same result when filling data with this 2 differents values (but uncorrect value twice) :

    Data Written : 0x01010101 (SHA_DATA_0_IN)
    SHA_S_LENGHT : 3
    HashMD5: 8C48867E7F374344AA6EE5BA9621453D

    Data Written : 0x00010101 (SHA_DATA_0_IN)
    SHA_S_LENGHT : 3
    HashMD5: 8C48867E7F374344AA6EE5BA9621453D

    Does it mean in my implementation : MSB(on left) is ignored when SHA_S_LENGHT != 4?

    My result is uncorrect and I don't find a solution about it (also in TRM)

     

    Work well with cryptodev :

    How can I fix it : I also need to have a correct digest for no 4 multiple byte data or more than 54 bytes?

    (Source code is nearly the same as the last post.)

    Thanks for support !

    Good day.

    Best Regards

    Alexis.

  • Hi Alexis,
    Thanks for your update, and good progress you made to have 32-bits aligned input stream MD5 working now...

    Alexis Llorente said:
    What code are you using?

    In order to mimic your bare-metal crypto driver porting effort based on the crypto TRM, I'm testing on EVM using bootrom built-in crypto functions combined with JTAG debugger for testing vector data stream input/output etc...In fact, the two log files with SHA/MD5 register dump information in my last reply are captured by JTAG debugger.
    I'll look into your non-working case (i.e., non 32-bit aligned input stream etc...), and get back to you next week.
    Best,
    -Hong

  • Thanks you for your help !

    Waiting for your news.

    Good Day !

    Alexis.

  • Hi Alexis,
    Yes, I'll spend time looking into your non-working case, and get back to you this week.
    In the mean time, please keep me posted with new findings from your side.
    Best,
    -Hong

  • Hi Hong,

    I am stuck on my problem but I am continuing my investigation : trying to debug omap-sham driver by debugging linux kernel on beaglebone black.

    For example when I asked a sha digest with linux I can see this logs in dmesg : (printk kernel debugging)

    By this way , we can understand witch function will be called. Find something on your side? Slight smile

    ./sha
    [ 144.560807] DEBUG: Passed omap_sham_cra_init 1475
    [ 144.565908] DEBUG: Passed omap_sham_cra_init_alg 1440
    [ 144.573423] DEBUG: Passed omap_sham_init 973
    Got sha1 with driver omap-sha1
    [ 144.585823] DEBUG: Passed omap_sham_init 973
    [ 144.599070] DEBUG: Passed omap_sham_update 1282
    [ 144.604988] DEBUG: Passed omap_sham_final 1336
    [ 144.610747] DEBUG: Passed omap_sham_final_shash 1315
    [ 144.617042] DEBUG: Passed omap_sham_cra_exit 1517
    digest: 2f:d4:e1:c6:7a:2d:28:fc:ed:84:9e:e1:bb:76:e7:39:1b:93:eb:12:

    BR.

    Alexis.

  • Hi Alexis,
    It is a very good approach to develop your bare-metal crypto driver by leveraging the Linux crypto driver as a reference.
    Best,
    -Hong