- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
After downloading Cryptography_AES_Demostration example codes from Github, I have tried all AES ECB mode, CBC mode, and CFB mode, all of them works fine.
However, I got some trouble in calling Cy_Crypto_Core_Aes_Ctr. Specifically speaking, I have no idea how to provide the parameters of this API function.
Do you have any example codes to show me how to encrypt/decrypt by AES CTR mode?
Hardware : CY8KIT-062-BLE
ModusToolbox version: 2.4.0
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Scaber2001 :
Please find a crude example of encrypting "Hello World" and decrypting the same using AES counter mode. We only encrypt 1 block here as we have hardcoded the sizes to 16 bytes (128-bits).
In the attached main.c file example, we have done the following:
- srcOffset : This is set to 0. This is initially don't care or can be 0. This is updated by the AES counter API when the data stream (or plaintext) you want to encrypt is not a multiple of 16 bytes. For instance, if you send a plaintext of 50 bytes, this is set to 2 (50 % 16) by the API.
- streamBlock : This is currently unused in the crypto implementation, so it can just be a uint8_t variable and its address can be passed to the API. You can even pass NULL to this. This parameter is actually used in tandem with srcOffset to XOR the next stream of plaintext data. For instance, this buffer will contain the already calculated stream key, and it starts XOR from srcOffset of key stream (2) on next batch of plaintext.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Currently we do not have any examples related to this, but you can refer to the link.
I hope it clarifies the doubts you have regarding the parameters.
In case things aren't clear, feel free to reach us out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you please guide me how to give parameters "srcOffset" and "streamBlock"?
Does "srcOffset" is kind of variable like "count of block"?
What I should declare for "streamBlock"? Is it an unit8_t array and what size it should? What content I should give as default values?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Scaber2001 :
Please find a crude example of encrypting "Hello World" and decrypting the same using AES counter mode. We only encrypt 1 block here as we have hardcoded the sizes to 16 bytes (128-bits).
In the attached main.c file example, we have done the following:
- srcOffset : This is set to 0. This is initially don't care or can be 0. This is updated by the AES counter API when the data stream (or plaintext) you want to encrypt is not a multiple of 16 bytes. For instance, if you send a plaintext of 50 bytes, this is set to 2 (50 % 16) by the API.
- streamBlock : This is currently unused in the crypto implementation, so it can just be a uint8_t variable and its address can be passed to the API. You can even pass NULL to this. This parameter is actually used in tandem with srcOffset to XOR the next stream of plaintext data. For instance, this buffer will contain the already calculated stream key, and it starts XOR from srcOffset of key stream (2) on next batch of plaintext.