<?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 -CCM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48021/aes--ccm</link><description>Hello, I am using AES -CCM encryption in my program. I want to know about memory like does it need any dynamic RAM ? In example code I found &amp;#39;nrf_mem_init()&amp;#39; but unable to get exact functionality of it. 
 Also can we use AES when Soft Device is used?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 03 Jun 2019 09:38:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48021/aes--ccm" /><item><title>RE: AES -CCM</title><link>https://devzone.nordicsemi.com/thread/190456?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 09:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d257b8f7-07f8-41c6-b778-443442716b1a</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;The nrf_crypto library uses&amp;nbsp;NRF_CRYPTO_ALLOC and NRF_CRYPTO_FREE, which is are wrapper for&amp;nbsp;nrf_malloc() and nrf_free() respectively. The allocated memory is used to store context variables for the cryptograpic operation, see&amp;nbsp;nrf_crypto_aes_crypt below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t nrf_crypto_aes_crypt(nrf_crypto_aes_context_t * const    p_context,
                                nrf_crypto_aes_info_t const * const p_info,
                                nrf_crypto_operation_t              operation,
                                uint8_t *                           p_key,
                                uint8_t *                           p_iv,
                                uint8_t *                           p_data_in,
                                size_t                              data_size,
                                uint8_t *                           p_data_out,
                                size_t *                            p_data_out_size)
{
    ret_code_t ret_val;
    void *     p_allocated_context = NULL;

    nrf_crypto_aes_context_t * p_ctx = p_context;

    VERIFY_TRUE(p_info != NULL, NRF_ERROR_CRYPTO_INPUT_NULL);

    if (p_ctx == NULL)
    {
        p_allocated_context = NRF_CRYPTO_ALLOC(p_info-&amp;gt;context_size);
        if (p_allocated_context == NULL)
        {
            return NRF_ERROR_CRYPTO_ALLOC_FAILED;
        }
        p_ctx = (nrf_crypto_aes_context_t *)p_allocated_context;
    }

    ret_val = nrf_crypto_aes_init(p_ctx, p_info, operation);
    NRF_CRYPTO_VERIFY_SUCCESS_DEALLOCATE(ret_val, p_allocated_context);

    ret_val = nrf_crypto_aes_key_set(p_ctx, p_key);
    NRF_CRYPTO_VERIFY_SUCCESS_DEALLOCATE(ret_val, p_allocated_context);

    ret_val = nrf_crypto_aes_iv_set(p_ctx, p_iv);
    /* not all AES modes support IV */
    if (ret_val != NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE)
    {
        NRF_CRYPTO_VERIFY_SUCCESS_DEALLOCATE(ret_val, p_allocated_context);
    }

    ret_val = nrf_crypto_aes_finalize(p_ctx,
                                      p_data_in,
                                      data_size,
                                      p_data_out,
                                      p_data_out_size);
    if (ret_val != NRF_SUCCESS)
    {
        /* Context was not successfully deinitialized in nrf_crypto_aes_finalize */
        UNUSED_RETURN_VALUE(nrf_crypto_aes_uninit(p_ctx));
    }

    if (p_allocated_context != NULL)
    {
        NRF_CRYPTO_FREE(p_allocated_context);
    }

    return ret_val;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The AES-CCM peripheral is blocked when the SoftDevice is enabled, please see the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/sd_resource_reqs/sd_resource_reqs.html"&gt;System on Chip resource requirements&lt;/a&gt;&amp;nbsp;in the S132 SoftDevice specification. It is possible to access the blocked peripherals by using the Timeslot API, see&amp;nbsp;&lt;a title="Concurrent multiprotocol implementation using the Radio Timeslot API" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/concurrent_multiprotocol_tsl_api/concurrent_multiprotocol_tsl_api.html?cp=3_4_1_0_8_1"&gt;Concurrent multiprotocol implementation using the Radio Timeslot API&lt;/a&gt;&amp;nbsp;in the SoftDevice specification.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>