cancel
Showing results for 
Search instead for 
Did you mean: 

WICED Studio Bluetooth

New Contributor II

Platform: CYW920719Q40EVB-01

IDE: Wiced Studio 6.2.1

Please provide any example code that uses "aes_cbc_encrypt" and "aes_cbc_decrypt" functions from wiced stack libraries.

Or please guide us how can we use AES-128 encryption in our project.

Does 423028-02 (chip - 20719) support AES128?

0 Likes
Reply
1 Solution
New Contributor II

AnjanaM_61

made little changes to example code and it worked..

But noted that each of the decrypted data in 6, 7, 14 and 15 places there is a garbage value on it. Everything else work properly.

0           6 7             14 15                                                       39

123456 ï : 90ABCD ∙   q  GHIJKLMNOPQRSTUVWXYZ1234

[0x31],[0x32],[0x33],[0x34],[0x35],[0x36],[0x8b],[0x3a],[0x39],[0x30],[0x41],[0x42],[0x43],[0x44],[0xf9],[0x71],[0x47],[0x48],[0x49],[0x4a],[0x4b],[0x4c],[0x4d],[0x4e],[0x4f],[0x50],[0x51],[0x52],[0x53],[0x54],[0x55],[0x56],[0x57],[0x58],[0x59],[0x5a],[0x31],[0x32],[0x33],[0x34]

Output LOG

============= AES Algorithm Starts now =================

Original data to be Encrypte 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234

AESkey(in ascii):1234abcd1234abcd

AESkey(in HEX):[0x31],[0x32],[0x33],[0x34],[0x61],[0x62],[0x63],[0x64],[0x31],[0x32],[0x33],[0x34],[0x61],[0x62],[0x63],[0x64]

[AES init function result : 0]

[AES_CBC_ENCRYPT function Result : 0]

(1)Received ENC data(in ascii): . )┬.Z

(2)ENC len: 6

(3)ENC data(in HEX):[0x2e],[0x1],[0x29],[0xc2],[0x2e],[0x5a]

[AES_CBC_DECRYPT function Result : 0]

(1)Received DEC data(in ascii): 123456ï:90ABCD∙qGHIJKLMNOPQRSTUVWXYZ1234

(2)DEC len: 40

(3)DEC data(in HEX):[0x31],[0x32],[0x33],[0x34],[0x35],[0x36],[0x8b],[0x3a],[0x39],[0x30],[0x41],[0x42],[0x43],[0x44],[0xf9],[0x71],[0x47],[0x48],[0x49],[0x4a],[0x4b],[0x4c],[0x4d],[0x4e],[0x4f],[0x50],[0x51],[0x52],[0x53],[0x54],[0x55],[0x56],[0x57],[0x58],[0x59],[0x5a],[0x31],[0x32],[0x33],[0x34]

View solution in original post

0 Likes
Reply
4 Replies
Moderator
Moderator

HI ns_4270701

I am sorry there is no plans to add support for the AES encrypt APIs in WICED. 

You may have to use an open source lib.

Below threads would be helpful for referring open source AES.

- https://community.cypress.com/message/12884#12884

- https://community.cypress.com/message/27198#27198

Regards,

Anjana

0 Likes
Reply
New Contributor II

AnjanaM_61

Yes I have already noticed the threads you have sent me.

But I have seen aes.c and aes.h files in wiced studio 6.4 version , and checked with the quick custom code.

What I have noticed was aes_encrypt and aes_decrypt APIs worked,  but in my project I want to use aes CBC.

I think there is minor changes required to below routine, but I could figure out how do I fix that issue.

return_type aes_cbc_decrypt( const unsigned char *in, unsigned char *out,

                        int n_block, unsigned char iv[N_BLOCK], const aes_context ctx[1] )

{

    while(n_block--)

    {  uint_8t tmp[N_BLOCK];

      

        memcpy(tmp, in, N_BLOCK);

        if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS)

return EXIT_FAILURE;

        xor_block(out, iv);

        memcpy(iv, tmp, N_BLOCK);

        in += N_BLOCK;

        out += N_BLOCK;

    }

    return EXIT_SUCCESS;

}

return_type aes_cbc_decrypt( const unsigned char *in, unsigned char *out,

                         int n_block, unsigned char iv[N_BLOCK], const aes_context ctx[1] )

{  

    while(n_block--)

    {   uint_8t tmp[N_BLOCK];

       

        memcpy(tmp, in, N_BLOCK);

        if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS)

return EXIT_FAILURE;

        xor_block(out, iv);

        memcpy(iv, tmp, N_BLOCK);

        in += N_BLOCK;

        out += N_BLOCK;

    }

    return EXIT_SUCCESS;

}

Because of the uploading file size constraint, I can't attach aes files from wiced SDK.  So please find the files from below path in Wiced 6.4 And guide me how do i use aes CBC.

* \WICED-Studio-6.4\common\apps\snip\mesh\peerapps\Android\src\MeshApp\meshcore\src\main\jni\mesh_libs

0 Likes
Reply
New Contributor II

AnjanaM_61

made little changes to example code and it worked..

But noted that each of the decrypted data in 6, 7, 14 and 15 places there is a garbage value on it. Everything else work properly.

0           6 7             14 15                                                       39

123456 ï : 90ABCD ∙   q  GHIJKLMNOPQRSTUVWXYZ1234

[0x31],[0x32],[0x33],[0x34],[0x35],[0x36],[0x8b],[0x3a],[0x39],[0x30],[0x41],[0x42],[0x43],[0x44],[0xf9],[0x71],[0x47],[0x48],[0x49],[0x4a],[0x4b],[0x4c],[0x4d],[0x4e],[0x4f],[0x50],[0x51],[0x52],[0x53],[0x54],[0x55],[0x56],[0x57],[0x58],[0x59],[0x5a],[0x31],[0x32],[0x33],[0x34]

Output LOG

============= AES Algorithm Starts now =================

Original data to be Encrypte 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234

AESkey(in ascii):1234abcd1234abcd

AESkey(in HEX):[0x31],[0x32],[0x33],[0x34],[0x61],[0x62],[0x63],[0x64],[0x31],[0x32],[0x33],[0x34],[0x61],[0x62],[0x63],[0x64]

[AES init function result : 0]

[AES_CBC_ENCRYPT function Result : 0]

(1)Received ENC data(in ascii): . )┬.Z

(2)ENC len: 6

(3)ENC data(in HEX):[0x2e],[0x1],[0x29],[0xc2],[0x2e],[0x5a]

[AES_CBC_DECRYPT function Result : 0]

(1)Received DEC data(in ascii): 123456ï:90ABCD∙qGHIJKLMNOPQRSTUVWXYZ1234

(2)DEC len: 40

(3)DEC data(in HEX):[0x31],[0x32],[0x33],[0x34],[0x35],[0x36],[0x8b],[0x3a],[0x39],[0x30],[0x41],[0x42],[0x43],[0x44],[0xf9],[0x71],[0x47],[0x48],[0x49],[0x4a],[0x4b],[0x4c],[0x4d],[0x4e],[0x4f],[0x50],[0x51],[0x52],[0x53],[0x54],[0x55],[0x56],[0x57],[0x58],[0x59],[0x5a],[0x31],[0x32],[0x33],[0x34]

View solution in original post

0 Likes
Reply
Moderator
Moderator

Hi ns_4270701 ,

Thanks for sharing your test results.

Regards,

Anjana

0 Likes
Reply