<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Secure AuthenticationのトピックSE050E aead encryption</title>
    <link>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1691417#M1309</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to implement aead encryption using the SE050E. As I checked the&amp;nbsp;AES-GCM algorithm is supported by this version of SE. I am using plug and trust middleware and examples to implement a simple firmware doing the following steps:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1- Creating a key object of AES type&lt;/P&gt;&lt;P&gt;2- Storing it in the key-store&lt;/P&gt;&lt;P&gt;3- initializing the aead context&lt;/P&gt;&lt;P&gt;4. Doing aead encryption in one go.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do so, I am using sss api in the plug and trust middleware and I am using the se05x api methods to implement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following qustions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Is there an example for aead encryption and decryption for secure element?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I am using the symmetric example in the plug and trust middleware and modify it to my use. I have changed the&amp;nbsp;&lt;SPAN&gt;algorithm -&amp;gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;kAlgorithm_SSS_AES_GCM and used&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_aead_context_init and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_aead_one_go instead of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_symmetric_context_init and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_cipher_one_go, respectively. I am getting an error in&amp;nbsp;sss_se05x_aead_one_go outpu ( could be that&amp;nbsp; the symmetric initialization does not match aead functions?). I am confused on how to implement the aead encryption, could you please give me some hints and guidance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Looking forward to your support. Thanks a lot in advance!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jul 2023 13:55:41 GMT</pubDate>
    <dc:creator>Zarein94</dc:creator>
    <dc:date>2023-07-24T13:55:41Z</dc:date>
    <item>
      <title>SE050E aead encryption</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1691417#M1309</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to implement aead encryption using the SE050E. As I checked the&amp;nbsp;AES-GCM algorithm is supported by this version of SE. I am using plug and trust middleware and examples to implement a simple firmware doing the following steps:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1- Creating a key object of AES type&lt;/P&gt;&lt;P&gt;2- Storing it in the key-store&lt;/P&gt;&lt;P&gt;3- initializing the aead context&lt;/P&gt;&lt;P&gt;4. Doing aead encryption in one go.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do so, I am using sss api in the plug and trust middleware and I am using the se05x api methods to implement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following qustions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Is there an example for aead encryption and decryption for secure element?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I am using the symmetric example in the plug and trust middleware and modify it to my use. I have changed the&amp;nbsp;&lt;SPAN&gt;algorithm -&amp;gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;kAlgorithm_SSS_AES_GCM and used&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_aead_context_init and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_aead_one_go instead of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_symmetric_context_init and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sss_cipher_one_go, respectively. I am getting an error in&amp;nbsp;sss_se05x_aead_one_go outpu ( could be that&amp;nbsp; the symmetric initialization does not match aead functions?). I am confused on how to implement the aead encryption, could you please give me some hints and guidance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Looking forward to your support. Thanks a lot in advance!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 13:55:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1691417#M1309</guid>
      <dc:creator>Zarein94</dc:creator>
      <dc:date>2023-07-24T13:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: SE050E aead encryption</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1691928#M1310</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/220688"&gt;@Zarein94&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to share your code for a review?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 06:26:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1691928#M1310</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2023-07-25T06:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: SE050E aead encryption</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1692418#M1311</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;, thanks for your response. Here's the modified code of symmetric example on plug and trust middleware to do aead encryption:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;sss_status_t ex_sss_entry(ex_sss_boot_ctx_t *pCtx)
{
    sss_status_t status = kStatus_SSS_Success;
    sss_algorithm_t algorithm;
    sss_mode_t mode;
    /* clang-format off */
    uint8_t srcData[16] = { 0x48 ,0x45 ,0x4c ,0x4c ,0x4f ,0x48 ,0x45 ,0x4c ,0x4c ,0x4f ,0x48 ,0x45 ,0x4c ,0x4c ,0x4f ,0x31 }; /*HELLOHELLOHELLO1*/
    uint8_t keystring[KEY_BIT_LEN / 8] = { 0x48 ,0x45 ,0x4c ,0x4c ,0x4f ,0x48 ,0x45 ,0x4c ,0x4c ,0x4f ,0x48 ,0x45 ,0x4c ,0x4c ,0x4f ,0x31 }; /*HELLOHELLOHELLO1*/
    uint8_t destData[16] = {0,};
    size_t destDataLen = sizeof(destData);
    uint8_t iv[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x15, 0x71, 0x99, 0x32, 0xd3, 0x56, 0x90};
    size_t ivlen = sizeof(iv);
    uint32_t keyId = MAKE_TEST_ID(__LINE__);
    sss_key_part_t keyPart;
    sss_cipher_type_t cipherType;
    size_t keyByteLenMax = KEY_BIT_LEN/8;
    sss_object_t key = { 0 };
    sss_aead_t ctx_aead_encrypt = { 0 };
    size_t TAG_SIZE = (96 / 8);
    uint8_t tag[TAG_SIZE];
    uint8_t  *aad =(uint8_t*)"Extra authentication data";
    size_t aadSize = strlen((char*)aad);

    algorithm =  kAlgorithm_SSS_AES_GCM; 
    keyPart    = kSSS_KeyPart_Default;
    cipherType = kSSS_CipherType_AES;
    mode       = kMode_SSS_Encrypt;

    /* doc:start ex_sss_symmetric-allocate-key */
    /* Pre-requisite for encryption Part*/ 
    ENSURE_OR_GO_CLEANUP(kType_SSS_SE_SE05x == pCtx-&amp;gt;session.subsystem);
    status = sss_key_object_init(&amp;amp;key, &amp;amp;pCtx-&amp;gt;ks);
    ENSURE_OR_GO_CLEANUP(status == kStatus_SSS_Success);

    status = sss_key_object_allocate_handle(&amp;amp;key, keyId, keyPart, cipherType, keyByteLenMax, kKeyObject_Mode_Persistent);
    ENSURE_OR_GO_CLEANUP(status == kStatus_SSS_Success);

    status = sss_key_store_set_key(&amp;amp;pCtx-&amp;gt;ks, &amp;amp;key, keystring, sizeof(keystring), sizeof(keystring) * 8, NULL, 0);
    ENSURE_OR_GO_CLEANUP(status == kStatus_SSS_Success);
    /* doc:end ex_sss_symmetric-allocate-key */

    /* doc:start ex_sss_aead-encrypt */

    status = sss_aead_context_init(&amp;amp;ctx_aead_encrypt, &amp;amp;pCtx-&amp;gt;session, &amp;amp;key, algorithm, mode);
    ENSURE_OR_GO_CLEANUP(status == kStatus_SSS_Success);

    LOG_I("Do Encryption");
    LOG_MAU8_I("iv", iv, ivlen);
    LOG_MAU8_I("srcData", srcData, ivlen);
    /*Do Encryption*/

    status = sss_aead_one_go(&amp;amp;ctx_aead_encrypt,srcData,destData, destDataLen, iv, ivlen, aad, aadSize, tag, &amp;amp;TAG_SIZE);
    ENSURE_OR_GO_CLEANUP(status == kStatus_SSS_Success);
    /* doc:end ex_sss_aead-encrypt */

    LOG_MAU8_I("encrypted data", destData, destDataLen);
    LOG_I("Encryption successful !!!");

cleanup:
    if (ctx_aead_encrypt.session != NULL) {
        sss_aead_context_free(&amp;amp;ctx_aead_encrypt);
    }
    sss_key_object_free(&amp;amp;key);
    return status;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sss :WARN :nxEnsure:'status == SM_OK' failed. At Line:6082 Function:sss_se05x_aead_one_go&lt;BR /&gt;App :WARN :nxEnsure:'status == kStatus_SSS_Success' failed. At Line:116 Function:ex_sss_entry&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 17:52:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1692418#M1311</guid>
      <dc:creator>Zarein94</dc:creator>
      <dc:date>2023-07-25T17:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: SE050E aead encryption</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1692929#M1312</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/220688"&gt;@Zarein94&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the information!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For AEAD encryption, the length of&amp;nbsp;the authentication tag is always 16 bytes, as mentioned in the APDU spec:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kan_Li_0-1690362831419.png" style="width: 699px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/233684i3750D6A77A95DF84/image-dimensions/699x145?v=v2" width="699" height="145" role="button" title="Kan_Li_0-1690362831419.png" alt="Kan_Li_0-1690362831419.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;so please adjust the tag length in your application code accordingly (12 ==&amp;gt; 16).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please kindly let me know if the problem is still there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 09:15:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1692929#M1312</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2023-07-26T09:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: SE050E aead encryption</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1693123#M1313</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;&amp;nbsp; for your support! That was the problem! It works fine now!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 13:51:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/SE050E-aead-encryption/m-p/1693123#M1313</guid>
      <dc:creator>Zarein94</dc:creator>
      <dc:date>2023-07-26T13:51:04Z</dc:date>
    </item>
  </channel>
</rss>

