<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/111076/aes-encryption-and-decryption-using-ccm-mode</link><description>I am trying to write and code of aes encryption and decryption using ccm mode for my application on nrf52832 controller. I have went through some example on Github for the same and took the function from there the git link is &amp;quot; https://github.com/NordicPlayground</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 20 May 2024 03:16:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/111076/aes-encryption-and-decryption-using-ccm-mode" /><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/484893?ContentTypeID=1</link><pubDate>Mon, 20 May 2024 03:16:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8a1c858-4d6b-48fb-a11a-3288619c7417</guid><dc:creator>PK424</dc:creator><description>&lt;p style="background-color:#f3f3f3;color:rgba(0, 0, 0, 0.894);font-family:SegoeUIVariable, SegoeUI, &amp;#39;Segoe UI&amp;#39;, &amp;#39;Helvetica Neue&amp;#39;, Helvetica, &amp;#39;Microsoft YaHei&amp;#39;, &amp;#39;Meiryo UI&amp;#39;, Meiryo, &amp;#39;Arial Unicode MS&amp;#39;, sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;padding:0px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;"&gt;Hi Hieu,&lt;/p&gt;
&lt;p style="background-color:#f3f3f3;color:rgba(0, 0, 0, 0.894);font-family:SegoeUIVariable, SegoeUI, &amp;#39;Segoe UI&amp;#39;, &amp;#39;Helvetica Neue&amp;#39;, Helvetica, &amp;#39;Microsoft YaHei&amp;#39;, &amp;#39;Meiryo UI&amp;#39;, Meiryo, &amp;#39;Arial Unicode MS&amp;#39;, sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;margin:8px 0px 0px;padding:0px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;"&gt;Thank you for your response. I understand that you will be partially out of office and I appreciate your heads-up about potential delays in follow-up.&lt;/p&gt;
&lt;p style="background-color:#f3f3f3;color:rgba(0, 0, 0, 0.894);font-family:SegoeUIVariable, SegoeUI, &amp;#39;Segoe UI&amp;#39;, &amp;#39;Helvetica Neue&amp;#39;, Helvetica, &amp;#39;Microsoft YaHei&amp;#39;, &amp;#39;Meiryo UI&amp;#39;, Meiryo, &amp;#39;Arial Unicode MS&amp;#39;, sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;margin:8px 0px 0px;padding:0px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;"&gt;I have indeed switched to the latest version of the SDK as you suggested. I have also gone through the Cryptography examples in the nRF5 SDK and the Cryptography Library&amp;rsquo;s documentation. They were quite helpful.&lt;/p&gt;
&lt;p style="background-color:#f3f3f3;color:rgba(0, 0, 0, 0.894);font-family:SegoeUIVariable, SegoeUI, &amp;#39;Segoe UI&amp;#39;, &amp;#39;Helvetica Neue&amp;#39;, Helvetica, &amp;#39;Microsoft YaHei&amp;#39;, &amp;#39;Meiryo UI&amp;#39;, Meiryo, &amp;#39;Arial Unicode MS&amp;#39;, sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;margin:8px 0px 0px;padding:0px;text-align:left;text-indent:0px;text-transform:none;white-space:normal;"&gt;PK424&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/483510?ContentTypeID=1</link><pubDate>Wed, 15 May 2024 12:58:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff3707e5-721c-41f4-92c0-232bc927a311</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi PK424,&lt;/p&gt;
&lt;p&gt;We have a short holiday coming soon, and I am partially out of office from now and for the working days before and after that. Thus, it will be hard to schedule debugging.&lt;/p&gt;
&lt;p&gt;Have you tried to look at &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/nrf_crypto_aes_example.html"&gt;the Cryptography examples&lt;/a&gt;&amp;nbsp;in the nRF5 SDK? It might be helpful to also go over &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_crypto.html"&gt;the Cryptography Library&amp;#39;s documentation&lt;/a&gt; before and after you do.&lt;/p&gt;
&lt;p&gt;Which version of the SDK are you using? I hope you have moved to the latest version.&lt;/p&gt;
&lt;p&gt;By the way, due to the above-mentioned unavailability, please excuse some delay in further follow up. I am sorry for the inconvenience.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/483382?ContentTypeID=1</link><pubDate>Wed, 15 May 2024 05:59:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3785c286-79a7-4bef-af57-c022bd82dbca</guid><dc:creator>PK424</dc:creator><description>&lt;p&gt;Hi Hieu &lt;br /&gt;&lt;br /&gt;I have written the code for AES encryption and decryption for nrf52832 the code is&lt;/p&gt;
&lt;div style="background-color:#ffffff;padding:0px 0px 0px 2px;"&gt;
&lt;div style="background-color:#ffffff;color:#000000;font-family:&amp;#39;Consolas&amp;#39;;font-size:10pt;white-space:pre;"&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;font-weight:bold;"&gt;main&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Define the key, &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;nonce&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;, and input data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#005032;"&gt;aes_nonce_key_t&lt;/span&gt;&lt;span style="color:#000000;"&gt; nk = {&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; .&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;key&lt;/span&gt;&lt;span style="color:#000000;"&gt; = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; .&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;nonce&lt;/span&gt;&lt;span style="color:#000000;"&gt; = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C},&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; .&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;scratch&lt;/span&gt;&lt;span style="color:#000000;"&gt; = {0} &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Initialize scratch area&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; };&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt; input[16] = &lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;Hello, World!&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt; encrypted[20];&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt; decrypted[16];&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;/* &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;Bootloader&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; code */&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;/* Initialize the system clock */&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; InitSysClock();&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;/* Initialize the system &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;gpios&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; */&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; InitSysGpio();&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;/* Initialize the UARTE0 */&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; InitHostCon();&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Encrypt the data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; aes_encrypt(&amp;amp;nk, input, encrypted);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;Decrypt&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; the data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; aes_decrypt(&amp;amp;nk, encrypted, decrypted, &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;sizeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;(decrypted));&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Print the input data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; print_data(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;Input&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, input, &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;sizeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;(input));&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Print the encrypted data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; print_data(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;Encrypted&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, encrypted, &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;sizeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;(encrypted));&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Print the &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;decrypted&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; print_data(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#2a00ff;text-decoration:underline;"&gt;Decrypted&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, decrypted, &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;sizeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;(decrypted));&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Verify that the &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;decrypted&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; data matches the input data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#642880;font-weight:bold;"&gt;memcmp&lt;/span&gt;&lt;span style="color:#000000;"&gt;(input, decrypted, &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;sizeof&lt;/span&gt;&lt;span style="color:#000000;"&gt;(input)) == 0) {&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Success: The &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;decrypted&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; data matches the input&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#642880;font-weight:bold;"&gt;printf&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;Decryption successful: &lt;/span&gt;&lt;span style="color:#2a00ff;text-decoration:underline;"&gt;Decrypted&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt; data matches input.\n&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; } &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;else&lt;/span&gt;&lt;span style="color:#000000;"&gt; {&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Error: The &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;decrypted&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; data does not match the input&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#642880;font-weight:bold;"&gt;printf&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;Decryption failed: &lt;/span&gt;&lt;span style="color:#2a00ff;text-decoration:underline;"&gt;Decrypted&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt; data does not match input.\n&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; }&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#3f7f5f;"&gt;// Function to generate key-stream&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;font-weight:bold;"&gt;aes_generate_keystream&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#005032;"&gt;aes_nonce_key_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* nk){&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Enable the CCM&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;ENABLE&lt;/span&gt;&lt;span style="color:#000000;"&gt; = CCM_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; CCM_ENABLE_ENABLE_Pos;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set the key and &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;nonce&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;CNFPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) nk;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set the scratch pointer for temporary key-stream storage&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;SCRATCHPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) nk-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;scratch&lt;/span&gt;&lt;span style="color:#000000;"&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Start key-stream generation&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;TASKS_KSGEN&lt;/span&gt;&lt;span style="color:#000000;"&gt; = 1;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Wait for key-stream generation to complete&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;while&lt;/span&gt;&lt;span style="color:#000000;"&gt; (NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;EVENTS_ENDKSGEN&lt;/span&gt;&lt;span style="color:#000000;"&gt; == 0);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#3f7f5f;"&gt;// Function to encrypt data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;font-weight:bold;"&gt;aes_encrypt&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#005032;"&gt;aes_nonce_key_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* nk, &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* input, &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* output){&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Generate key-stream&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; aes_generate_keystream(nk);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set the input and output pointers&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;INPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) input;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;OUTPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) output;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set mode to encryption&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;MODE&lt;/span&gt;&lt;span style="color:#000000;"&gt; = CCM_MODE_MODE_Encryption;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Start the encryption&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;TASKS_CRYPT&lt;/span&gt;&lt;span style="color:#000000;"&gt; = 1;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Wait for the encryption to complete&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;while&lt;/span&gt;&lt;span style="color:#000000;"&gt; (NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;EVENTS_ENDCRYPT&lt;/span&gt;&lt;span style="color:#000000;"&gt; == 0);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#3f7f5f;"&gt;// Function to &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;decrypt&lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt; data&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#000000;font-weight:bold;"&gt;aes_decrypt&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#005032;"&gt;aes_nonce_key_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* nk, &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* input, &lt;/span&gt;&lt;span style="color:#005032;"&gt;uint8_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;* output, &lt;/span&gt;&lt;span style="color:#005032;"&gt;size_t&lt;/span&gt;&lt;span style="color:#000000;"&gt; len){&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Ensure CCM is enabled and configured correctly&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;ENABLE&lt;/span&gt;&lt;span style="color:#000000;"&gt; = CCM_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; CCM_ENABLE_ENABLE_Pos;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set the key and &lt;/span&gt;&lt;span style="color:#3f7f5f;text-decoration:underline;"&gt;nonce&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;CNFPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) nk;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set the input and output pointers&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;INPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) input;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;OUTPTR&lt;/span&gt;&lt;span style="color:#000000;"&gt; = (&lt;/span&gt;&lt;span style="color:#005032;"&gt;uint32_t&lt;/span&gt;&lt;span style="color:#000000;"&gt;) output;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;MODE&lt;/span&gt;&lt;span style="color:#000000;"&gt; = CCM_MODE_MODE_Decryption; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set mode to decryption&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Set the packet length&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;MODE&lt;/span&gt;&lt;span style="color:#000000;"&gt; &amp;amp;= ~CCM_MODE_LENGTH_Msk;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;MODE&lt;/span&gt;&lt;span style="color:#000000;"&gt; |= ((len &amp;lt;&amp;lt; CCM_MODE_LENGTH_Pos) &amp;amp; CCM_MODE_LENGTH_Msk);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Start the decryption&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;TASKS_CRYPT&lt;/span&gt;&lt;span style="color:#000000;"&gt; = 1;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;while&lt;/span&gt;&lt;span style="color:#000000;"&gt; (NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;EVENTS_ENDCRYPT&lt;/span&gt;&lt;span style="color:#000000;"&gt; == 0); &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Wait for the decryption to complete&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#3f7f5f;"&gt;// Check MIC status&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt; (NRF_CCM-&amp;gt;&lt;/span&gt;&lt;span style="color:#0000c0;"&gt;MICSTATUS&lt;/span&gt;&lt;span style="color:#000000;"&gt; != 0) {&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#642880;font-weight:bold;"&gt;printf&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;MIC check failed.\n&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; } &lt;/span&gt;&lt;span style="color:#7f0055;font-weight:bold;"&gt;else&lt;/span&gt;&lt;span style="color:#000000;"&gt; {&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#642880;font-weight:bold;"&gt;printf&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#2a00ff;"&gt;&amp;quot;MIC check passed.\n&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;);&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt; }&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;span style="color:#3f7f5f;"&gt;/* --------------------------------------------------------------------------------*/&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;br /&gt;The output of code is &lt;br /&gt;&lt;br /&gt;00&amp;gt; MIC check passed.&lt;br /&gt;00&amp;gt; Input: 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 21 00 00 00 &lt;br /&gt;00&amp;gt; Encrypted: 04 d5 9c e9 86 7c 36 17 36 b1 f4 a5 79 21 ff 7b 50 48 00 b0 &lt;br /&gt;00&amp;gt; Decrypted: 48 65 6c 6c 6f 2c 20 57 f3 39 ec 1a 05 af 66 51 &lt;br /&gt;00&amp;gt; Decryption failed: Decrypted data does not match input.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The output which is generating the decrypted data do not match with the input data.&lt;br /&gt;Can you pleas guide me with this what is wrong in the code.&lt;/p&gt;
&lt;p style="margin:0;"&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/483184?ContentTypeID=1</link><pubDate>Tue, 14 May 2024 08:28:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:898fa7c9-9a51-47d4-bd7e-ef96679fa0ee</guid><dc:creator>PK424</dc:creator><description>&lt;p&gt;Hi Hieu&lt;/p&gt;
&lt;p&gt;Thank you for the link the link is working, but can you guide me with how can I use hardware ccm method &lt;strong&gt;without using nRF Connect SDK for encryption and decryption of data.&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;PK424&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/483176?ContentTypeID=1</link><pubDate>Tue, 14 May 2024 08:00:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:967b3836-45f6-4eae-9f10-73f2957dd93a</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi PK424,&lt;/p&gt;
&lt;p&gt;It looks like the comma character got combined into the link. Sorry for the inconvenience. Please use this link:&lt;br /&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/index.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/index.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I will also fix the previous link.&lt;/p&gt;
&lt;p&gt;In the nRF Connect SDK, the crypto library is setup so that, by default, if the hardware supports the crypto operation, then it will be done by hardware. Otherwise, a software library will be used.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/483056?ContentTypeID=1</link><pubDate>Mon, 13 May 2024 13:01:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70d85663-689a-484b-adf4-e749d5bc2db5</guid><dc:creator>PK424</dc:creator><description>&lt;p&gt;Hi Hieu &lt;/p&gt;
&lt;p&gt;Thank you for the guidance but can you guide me with how can I use hardware ccm method for&lt;strong&gt; encryption and decryption of data without using the nordic&amp;#39;s SDK&lt;/strong&gt; and also the links you provided this link &amp;quot; &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/index.html,"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/index.html,&lt;/a&gt;&amp;quot; is out of use it says &amp;#39;Page not found&amp;#39;.&lt;/p&gt;
&lt;p&gt;PK424&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: AES Encryption and Decryption using CCM mode</title><link>https://devzone.nordicsemi.com/thread/482952?ContentTypeID=1</link><pubDate>Mon, 13 May 2024 08:01:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7a224c6-6424-43c2-9d94-94f195851b1d</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi PK424,&lt;/p&gt;
&lt;p&gt;The example you followed is very old. It is based on the nRF5 SDK, which is in &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/nrf-connect-sdk-and-nrf5-sdk-statement"&gt;maintenance mode&lt;/a&gt; and is not recommended on any new project. Not only that, but it is also based on an old version of the SDK.&lt;/p&gt;
&lt;p&gt;Unless you have a strong reason to use the nRF5 SDK, I&amp;nbsp;highly recommend you move to the nRF Connect SDK. &lt;br /&gt;You can find the documentation here:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/index.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/index.html&lt;/a&gt;,&amp;nbsp;and&lt;br /&gt;cryptography samples for the SDK here:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/samples/crypto.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/samples/crypto.html&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>