<?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>How to implement software AES-CTR in nRF52832 + S132 v2.0 + SDK11?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90008/how-to-implement-software-aes-ctr-in-nrf52832-s132-v2-0-sdk11</link><description>How to implement software AES-CTR in nRF52832 + S132 v2.0 + SDK11?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 19 Jul 2022 07:40:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90008/how-to-implement-software-aes-ctr-in-nrf52832-s132-v2-0-sdk11" /><item><title>RE: How to implement software AES-CTR in nRF52832 + S132 v2.0 + SDK11?</title><link>https://devzone.nordicsemi.com/thread/377526?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 07:40:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56e299d8-1913-4ca6-a1d7-5dae31afccb4</guid><dc:creator>Changhai Liao</dc:creator><description>&lt;p&gt;Thank you for your reply.&lt;/p&gt;
&lt;p&gt;I finished it a few days ago.&lt;/p&gt;
&lt;p&gt;Maybe the code is not perfect.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t AESCTR_Encrypt(uint8_t *pPlain, uint16_t usPLen, uint8_t *pEncrypted, uint16_t usELen, uint16_t *pEValidLen,
                       uint8_t *aIv, uint8_t *aKey)
{
    if (usELen &amp;lt; usPLen)
    {
        return (uint8_t)-1;
    }
    (void)nrf_ecb_init();
    nrf_ecb_set_key(aKey);
    uint8_t aIvOri[AESCTR_IV_LEN] = {0};
    uint8_t aIvEcb[AESCTR_IV_LEN] = {0};
    memcpy(aIvOri, aIv, AESCTR_IV_LEN);
    (void)nrf_ecb_crypt(aIvEcb, aIvOri);

    for (uint16_t usI = 0; usI &amp;lt; usPLen; usI++)
    {
        pEncrypted[usI] = pPlain[usI] ^ aIvEcb[usI &amp;amp; 0x0F];
        if ((usI &amp;amp; 0x0F) == 0x0F)
        {
            for (uint8_t ucJ = AESCTR_IV_LEN - 1; ucJ &amp;gt; 0; ucJ--)
            {
                if (++aIvOri[ucJ] != 0)
                {
                    break;
                }
            }
            (void)nrf_ecb_crypt(aIvEcb, aIvOri);
        }
    }
    *pEValidLen = usPLen;
    return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement software AES-CTR in nRF52832 + S132 v2.0 + SDK11?</title><link>https://devzone.nordicsemi.com/thread/377523?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 07:27:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bad3cdae-9613-4696-a691-4edc342dc39e</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
&lt;p&gt;It seems that the nrf5 SDK v11 does not support AES-CTR out of the box, only AES-ECB and AES-CCB which are implemented in hardware. The later SDK versions includes the crypto component which adds support for CTR (and many other modes) because it allows the usage of software implemented crypto for AES. Unfortunately I can&amp;#39;t help you with this, besides recommending you to use a newer version of the SDK.&lt;/p&gt;
&lt;p&gt;I should mention that it &lt;em&gt;might technically&lt;/em&gt; be possible for you to add support for CTR based on our ECB mode, but I would &lt;strong&gt;not&lt;/strong&gt; recommend this.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement software AES-CTR in nRF52832 + S132 v2.0 + SDK11?</title><link>https://devzone.nordicsemi.com/thread/377174?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2022 11:30:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40a0e2f7-c7ed-4b70-920a-d35fc1c8b08d</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I will get back to you on this. Note that w&lt;/span&gt;&lt;span&gt;e have entered the summer holiday period in Norway so staffing is low, some delayed response time should be expected.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Elfving&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>