<?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>NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/109597/nrf_crypto-aesccm-and-python-aes-ccm-encryption-not-gives-the-same-output</link><description>Hi Nordic Team, 
 NRF crypto example AES CCM main.c code follows NIST standards and Pycryptodome library follows the same. I tried encryption on both platform but the results will be different, So How can I match the outputs. Suggest any methods to sync</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Mar 2024 06:13:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/109597/nrf_crypto-aesccm-and-python-aes-ccm-encryption-not-gives-the-same-output" /><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475798?ContentTypeID=1</link><pubDate>Tue, 26 Mar 2024 06:13:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33e5ef66-61e6-47a9-897e-38d2c685c546</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The error code corresponds to NRF_ERROR_CRYPTO_ALLOC_FAILED (0x8515), which indicates that the function failed to allocate memory for this crypto operation. I suggest you compare the memory allocator configuration between with your working project (NRF_CRYPTO_ALLOCATOR).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475681?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 14:08:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38ac3911-f974-48cb-8284-8c411cb0a2c6</guid><dc:creator>_YOGI</dc:creator><description>&lt;p&gt;Hi vidar&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One more doubt when I enable the softdevice, code is crashed in newly updated 256_info and the error code is&amp;nbsp;&amp;nbsp;app: ERROR 34069.&lt;/p&gt;
&lt;p&gt;Whether aesccm mbedtls work along with softdevice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475672?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 13:43:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20b9c222-c573-46c8-9844-963fc452a3d1</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I&amp;#39;m glad to hear that. Thank you for the update,&amp;nbsp;&lt;span&gt;Sriyogesh.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475671?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 13:42:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5131cba-a0a2-4295-9f23-00ec909b1528</guid><dc:creator>_YOGI</dc:creator><description>&lt;p&gt;Thanks Vidar, Now its works good, the outputs are perfectly matched.&lt;/p&gt;
&lt;p&gt;Best Regards&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sriyogesh Gopal&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475654?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 13:11:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0442b2bf-0fdc-4e58-8821-0e2f0225c3df</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I&amp;#39;m able to match&amp;nbsp;the output from the c code and the python script when using the original input you posted.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;ctype.h&amp;gt;


#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;nrf_drv_power.h&amp;quot;

#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_util.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;quot;boards.h&amp;quot;

#include &amp;quot;nrf_crypto.h&amp;quot;
#include &amp;quot;nrf_crypto_error.h&amp;quot;
#include &amp;quot;mem_manager.h&amp;quot;

#if NRF_MODULE_ENABLED(NRF_CRYPTO)
/**@file
 * @defgroup AES_CCM_example main.c
 *
 * @{
 *
 */

#define AES_MAC_SIZE                            (4)

#define NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE    (3)

#define AES_ERROR_CHECK(error)  \
    do {            \
        if (error)  \
        {           \
            NRF_LOG_RAW_INFO(&amp;quot;\r\nError = 0x%x\r\n%s\r\n&amp;quot;,           \
                             (error),                                \
                             nrf_crypto_error_string_get(error));    \
            return; \
        }           \
    } while (0);



/* Maximum allowed key = 256 bit */
static uint8_t m_key[32] = &amp;quot;kwb3IfPnbMx8RvGYm3yl4O6E2ZNZ4Gwq&amp;quot;;

/* Below text is used as plain text for encryption, decryption and MAC calculation. */
static char m_plain_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE] =
{
    &amp;quot;ABC&amp;quot;
};

static char m_encrypted_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE];
static char m_decrypted_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE];

static void text_print(char const* p_label, char const * p_text, size_t len)
{
    NRF_LOG_RAW_INFO(&amp;quot;----%s (len: %u) ----\r\n&amp;quot;, p_label, len);
    NRF_LOG_FLUSH();
    for(size_t i = 0; i &amp;lt; len; i++)
    {
        NRF_LOG_RAW_INFO(&amp;quot;%c&amp;quot;, p_text[i]);
        NRF_LOG_FLUSH();
    }
    NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
    NRF_LOG_RAW_INFO(&amp;quot;---- %s end ----\r\n\r\n&amp;quot;, p_label);
    NRF_LOG_FLUSH();
}

static void hex_text_print(char const* p_label, char const * p_text, size_t len)
{
    NRF_LOG_RAW_INFO(&amp;quot;---- %s (len: %u) ----\r\n&amp;quot;, p_label, len);
    NRF_LOG_FLUSH();

    // Handle partial line (left)
    for (size_t i = 0; i &amp;lt; len; i++)
    {
        if (((i &amp;amp; 0xF) == 0) &amp;amp;&amp;amp; (i &amp;gt; 0))
        {
            NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
            NRF_LOG_FLUSH();
        }

        NRF_LOG_RAW_INFO(&amp;quot;%02x &amp;quot;, p_text[i]);
        NRF_LOG_FLUSH();
    }
    NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
    NRF_LOG_RAW_INFO(&amp;quot;---- %s end ----\r\n\r\n&amp;quot;, p_label);
    NRF_LOG_FLUSH();
}



static void plain_text_print(void)
{
    text_print(&amp;quot;Plain text&amp;quot;, m_plain_text, strlen(m_plain_text));
    hex_text_print(&amp;quot;Plain text (hex)&amp;quot;, m_plain_text, strlen(m_plain_text));
}

static void encrypted_text_print(char const * p_text, size_t encrypted_len)
{
    hex_text_print(&amp;quot;Encrypted text (hex)&amp;quot;, p_text, encrypted_len);
}

static void decrypted_text_print(char const * p_text, size_t decrypted_len)
{
    text_print(&amp;quot;Decrypted text&amp;quot;, p_text, decrypted_len);
    hex_text_print(&amp;quot;Decrypted text (hex)&amp;quot;, p_text, decrypted_len);
}

static void mac_print(uint8_t const * p_buff, uint8_t mac_size)
{
    hex_text_print(&amp;quot;MAC (hex)&amp;quot;, (char const*)p_buff, mac_size);
}

static void crypt_ccm(void)
{
    uint32_t    len;
    ret_code_t  ret_val;

    static uint8_t     mac[AES_MAC_SIZE];
    static uint8_t     nonce[13];
    static uint8_t     adata[] = {0xAA, 0xBB, 0xCC, 0xDD};

    static nrf_crypto_aead_context_t ccm_ctx;

    memset(mac,   0, sizeof(mac));
    memset(nonce, 0, sizeof(nonce));

    plain_text_print();

    len = strlen((char const *)m_plain_text);

    /* Init encrypt and decrypt context */
    ret_val = nrf_crypto_aead_init(&amp;amp;ccm_ctx,
                                   &amp;amp;g_nrf_crypto_aes_ccm_256_info,
                                   m_key);
    AES_ERROR_CHECK(ret_val);

    /* encrypt and tag text */
    ret_val = nrf_crypto_aead_crypt(&amp;amp;ccm_ctx,
                                    NRF_CRYPTO_ENCRYPT,
                                    nonce,
                                    sizeof(nonce),
                                    adata,
                                    sizeof(adata),
                                    (uint8_t *)m_plain_text,
                                    len,
                                    (uint8_t *)m_encrypted_text,
                                    mac,
                                    sizeof(mac));
    AES_ERROR_CHECK(ret_val);

    encrypted_text_print(m_encrypted_text, len);
    mac_print(mac, sizeof(mac));

    /* decrypt text */
    ret_val = nrf_crypto_aead_crypt(&amp;amp;ccm_ctx,
                                    NRF_CRYPTO_DECRYPT,
                                    nonce,
                                    sizeof(nonce),
                                    adata,
                                    sizeof(adata),
                                    (uint8_t *)m_encrypted_text,
                                    len,
                                    (uint8_t *)m_decrypted_text,
                                    mac,
                                    sizeof(mac));
    AES_ERROR_CHECK(ret_val);

    ret_val = nrf_crypto_aead_uninit(&amp;amp;ccm_ctx);
    AES_ERROR_CHECK(ret_val);

    decrypted_text_print(m_decrypted_text, len);

    if (memcmp(m_plain_text, m_decrypted_text, strlen(m_plain_text)) == 0)
    {
        NRF_LOG_RAW_INFO(&amp;quot;AES CCM example executed successfully.\r\n&amp;quot;);
    }
    else
    {
        NRF_LOG_RAW_INFO(&amp;quot;AES CCM example failed!!!.\r\n&amp;quot;);
    }
}

int main(void)
{
    ret_code_t ret;

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_RAW_INFO(&amp;quot;AES CCM example started.\r\n\r\n&amp;quot;);
    NRF_LOG_FLUSH();

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    nrf_drv_clock_lfclk_request(NULL);

    ret = nrf_crypto_init();
    APP_ERROR_CHECK(ret);

    ret = nrf_mem_init();
    APP_ERROR_CHECK(ret);

    crypt_ccm();
    while (true)
    {
        NRF_LOG_FLUSH();
        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
    }
}

/** @} */
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;AES CCM example started.

----Plain text (len: 3) ----
ABC
---- Plain text end ----

---- Plain text (hex) (len: 3) ----
41 42 43 
---- Plain text (hex) end ----

---- Encrypted text (hex) (len: 3) ----
E1 29 D1 
---- Encrypted text (hex) end ----

---- MAC (hex) (len: 4) ----
BC 3A B0 C8 
---- MAC (hex) end ----

----Decrypted text (len: 3) ----
ABC
---- Decrypted text end ----

---- Decrypted text (hex) (len: 3) ----
41 42 43 
---- Decrypted text (hex) end ----

AES CCM example executed successfully.&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475648?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 13:06:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b66c829-b6a4-445f-8fe9-67562cb543fc</guid><dc:creator>_YOGI</dc:creator><description>&lt;p&gt;I just tried with 128 bit key the output is not same. I tried one example from NIST_800_38C document&amp;nbsp; example 1. In python library gives the same output&amp;nbsp;but nrf52840 gives different output.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt="Clipped From NIST 800-38c" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/6403.Screenshot-_2800_1_2900_.png" /&gt;&lt;/p&gt;
&lt;p&gt;My constraints is not to match the 128 0r 256 bit. I need to match the nrf52840 and python script output.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475643?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 12:52:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bf58259-41c0-48df-b4f8-38428203c13c</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;You are selecting a 128-bit chipher in your init function here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    ret_val = nrf_crypto_aead_init(&amp;amp;ccm_ctx,
                                   &amp;amp;g_nrf_crypto_aes_ccm_128_info,
                                   m_key);
    AES_ERROR_CHECK(ret_val);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you want to use a 256-bit chipher, you need to change&amp;nbsp;g_nrf_crypto_aes_ccm_128_info to&amp;nbsp;g_nrf_crypto_aes_ccm_256_info and enable the mbedtls AES backend by setting&amp;nbsp;NRF_CRYPTO_BACKEND_CC310_AES_CCM_ENABLED to &amp;#39;0&amp;#39; and&amp;nbsp;NRF_CRYPTO_BACKEND_MBEDTLS_AES_CCM_ENABLED to &amp;#39;1&amp;#39;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475640?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 12:49:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8d26a47-7b80-4e5c-8e78-50f0229521b2</guid><dc:creator>_YOGI</dc:creator><description>&lt;p&gt;Hi Vedar&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In nrf5 sdk 17.0.2-&amp;gt;examples-&amp;gt;crypto-&amp;gt;nrf_crypto-&amp;gt;aes-&amp;gt;aes_ccm this location had on main.c file&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;ctype.h&amp;gt;


#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;nrf_drv_power.h&amp;quot;

#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_util.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;quot;boards.h&amp;quot;

#include &amp;quot;nrf_crypto.h&amp;quot;
#include &amp;quot;nrf_crypto_error.h&amp;quot;
#include &amp;quot;mem_manager.h&amp;quot;

#if NRF_MODULE_ENABLED(NRF_CRYPTO)
/**@file
 * @defgroup AES_CCM_example main.c
 *
 * @{
 *
 */

#define AES_MAC_SIZE                            (16)

#define NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE    (100)

#define AES_ERROR_CHECK(error)  \
    do {            \
        if (error)  \
        {           \
            NRF_LOG_RAW_INFO(&amp;quot;\r\nError = 0x%x\r\n%s\r\n&amp;quot;,           \
                             (error),                                \
                             nrf_crypto_error_string_get(error));    \
            return; \
        }           \
    } while (0);



/* Maximum allowed key = 256 bit */
static uint8_t m_key[32] = {&amp;#39;N&amp;#39;, &amp;#39;O&amp;#39;, &amp;#39;R&amp;#39;, &amp;#39;D&amp;#39;, &amp;#39;I&amp;#39;, &amp;#39;C&amp;#39;, &amp;#39; &amp;#39;,
                            &amp;#39;S&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;M&amp;#39;, &amp;#39;I&amp;#39;, &amp;#39;C&amp;#39;, &amp;#39;O&amp;#39;, &amp;#39;N&amp;#39;, &amp;#39;D&amp;#39;, &amp;#39;U&amp;#39;, &amp;#39;C&amp;#39;, &amp;#39;T&amp;#39;, &amp;#39;O&amp;#39;, &amp;#39;R&amp;#39;,
                            &amp;#39;A&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;S&amp;#39;, &amp;#39;&amp;amp;&amp;#39;, &amp;#39;M&amp;#39;, &amp;#39;A&amp;#39;, &amp;#39;C&amp;#39;, &amp;#39; &amp;#39;, &amp;#39;T&amp;#39;, &amp;#39;E&amp;#39;, &amp;#39;S&amp;#39;, &amp;#39;T&amp;#39;};

/* Below text is used as plain text for encryption, decryption and MAC calculation. */
static char m_plain_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE] =
{
    &amp;quot;Example string used to demonstrate basic usage of AES CCM mode.&amp;quot;
};

static char m_encrypted_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE];
static char m_decrypted_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE];

static void text_print(char const* p_label, char const * p_text, size_t len)
{
    NRF_LOG_RAW_INFO(&amp;quot;----%s (len: %u) ----\r\n&amp;quot;, p_label, len);
    NRF_LOG_FLUSH();
    for(size_t i = 0; i &amp;lt; len; i++)
    {
        NRF_LOG_RAW_INFO(&amp;quot;%c&amp;quot;, p_text[i]);
        NRF_LOG_FLUSH();
    }
    NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
    NRF_LOG_RAW_INFO(&amp;quot;---- %s end ----\r\n\r\n&amp;quot;, p_label);
    NRF_LOG_FLUSH();
}

static void hex_text_print(char const* p_label, char const * p_text, size_t len)
{
    NRF_LOG_RAW_INFO(&amp;quot;---- %s (len: %u) ----\r\n&amp;quot;, p_label, len);
    NRF_LOG_FLUSH();

    // Handle partial line (left)
    for (size_t i = 0; i &amp;lt; len; i++)
    {
        if (((i &amp;amp; 0xF) == 0) &amp;amp;&amp;amp; (i &amp;gt; 0))
        {
            NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
            NRF_LOG_FLUSH();
        }

        NRF_LOG_RAW_INFO(&amp;quot;%02x &amp;quot;, p_text[i]);
        NRF_LOG_FLUSH();
    }
    NRF_LOG_RAW_INFO(&amp;quot;\r\n&amp;quot;);
    NRF_LOG_RAW_INFO(&amp;quot;---- %s end ----\r\n\r\n&amp;quot;, p_label);
    NRF_LOG_FLUSH();
}



static void plain_text_print(void)
{
    text_print(&amp;quot;Plain text&amp;quot;, m_plain_text, strlen(m_plain_text));
    hex_text_print(&amp;quot;Plain text (hex)&amp;quot;, m_plain_text, strlen(m_plain_text));
}

static void encrypted_text_print(char const * p_text, size_t encrypted_len)
{
    hex_text_print(&amp;quot;Encrypted text (hex)&amp;quot;, p_text, encrypted_len);
}

static void decrypted_text_print(char const * p_text, size_t decrypted_len)
{
    text_print(&amp;quot;Decrypted text&amp;quot;, p_text, decrypted_len);
    hex_text_print(&amp;quot;Decrypted text (hex)&amp;quot;, p_text, decrypted_len);
}

static void mac_print(uint8_t const * p_buff, uint8_t mac_size)
{
    hex_text_print(&amp;quot;MAC (hex)&amp;quot;, (char const*)p_buff, mac_size);
}

static void crypt_ccm(void)
{
    uint32_t    len;
    ret_code_t  ret_val;

    static uint8_t     mac[AES_MAC_SIZE];
    static uint8_t     nonce[13];
    static uint8_t     adata[] = {0xAA, 0xBB, 0xCC, 0xDD};

    static nrf_crypto_aead_context_t ccm_ctx;

    memset(mac,   0, sizeof(mac));
    memset(nonce, 0, sizeof(nonce));

    plain_text_print();

    len = strlen((char const *)m_plain_text);

    /* Init encrypt and decrypt context */
    ret_val = nrf_crypto_aead_init(&amp;amp;ccm_ctx,
                                   &amp;amp;g_nrf_crypto_aes_ccm_128_info,
                                   m_key);
    AES_ERROR_CHECK(ret_val);

    /* encrypt and tag text */
    ret_val = nrf_crypto_aead_crypt(&amp;amp;ccm_ctx,
                                    NRF_CRYPTO_ENCRYPT,
                                    nonce,
                                    sizeof(nonce),
                                    adata,
                                    sizeof(adata),
                                    (uint8_t *)m_plain_text,
                                    len,
                                    (uint8_t *)m_encrypted_text,
                                    mac,
                                    sizeof(mac));
    AES_ERROR_CHECK(ret_val);

    encrypted_text_print(m_encrypted_text, len);
    mac_print(mac, sizeof(mac));

    /* decrypt text */
    ret_val = nrf_crypto_aead_crypt(&amp;amp;ccm_ctx,
                                    NRF_CRYPTO_DECRYPT,
                                    nonce,
                                    sizeof(nonce),
                                    adata,
                                    sizeof(adata),
                                    (uint8_t *)m_encrypted_text,
                                    len,
                                    (uint8_t *)m_decrypted_text,
                                    mac,
                                    sizeof(mac));
    AES_ERROR_CHECK(ret_val);

    ret_val = nrf_crypto_aead_uninit(&amp;amp;ccm_ctx);
    AES_ERROR_CHECK(ret_val);

    decrypted_text_print(m_decrypted_text, len);

    if (memcmp(m_plain_text, m_decrypted_text, strlen(m_plain_text)) == 0)
    {
        NRF_LOG_RAW_INFO(&amp;quot;AES CCM example executed successfully.\r\n&amp;quot;);
    }
    else
    {
        NRF_LOG_RAW_INFO(&amp;quot;AES CCM example failed!!!.\r\n&amp;quot;);
    }
}

int main(void)
{
    ret_code_t ret;

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_RAW_INFO(&amp;quot;AES CCM example started.\r\n\r\n&amp;quot;);
    NRF_LOG_FLUSH();

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    nrf_drv_clock_lfclk_request(NULL);

    ret = nrf_crypto_init();
    APP_ERROR_CHECK(ret);

    ret = nrf_mem_init();
    APP_ERROR_CHECK(ret);

    crypt_ccm();
    while (true)
    {
        NRF_LOG_FLUSH();
        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
    }
}

/** @} */
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO)

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I worked on this file for aes ccm encryption and decryption. In this file key size is 256bit only. So how can I sync the output of device and python/android app. Is there is any other file to encrypt the data via aes ccm?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output</title><link>https://devzone.nordicsemi.com/thread/475628?ContentTypeID=1</link><pubDate>Mon, 25 Mar 2024 12:14:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:562c81bd-8e73-4e45-aa5d-7d8f7e8edbef</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Did you modify main.c and sdk_config.h to use an AES 256-bit cipher? Note: cc310 does not support 256-bit keys.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>