<?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>PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90075/psa-encryption---aes-ctr-128---message-input-length</link><description>Hello, I am porting to nRF5340 from nRF52833. Previously, we were using sdk17.0.2 for nRF52833 and we were able to successfully implement encryption algorithm AES-CTR-128 with sdk 17.0.2. 
 Now that we are porting to nRF5340, we would want to implement</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 19 Jul 2022 13:00:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90075/psa-encryption---aes-ctr-128---message-input-length" /><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377637?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 13:00:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd6f0da4-5872-429b-ab51-3795fea3a701</guid><dc:creator>Regie Roshan Magendiran</dc:creator><description>&lt;p&gt;I see. Then it makes sense to update to the new NCS version. Thanks again for sorting it out!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377636?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 12:58:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee2b4f20-da96-40fe-992b-f6a2d88c1368</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;No, Oberon is a software crypto driver, and will not use the CryptoCell.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377630?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 12:44:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:401c3326-79ad-4613-88f7-7a728e388c14</guid><dc:creator>Regie Roshan Magendiran</dc:creator><description>&lt;p&gt;Thanks for the response, Sigurd!&lt;/p&gt;
&lt;p&gt;Would&amp;nbsp;PSA Oberon library use the CryptoCell 312 in nRF5340? I would like to use the library that uses the hardware for faster computation or remove as much load as possible from the CPU.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Regie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377595?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 11:32:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d18bba97-8640-4584-be11-4922e0ae0fb9</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Our developers say:&lt;/p&gt;
&lt;p&gt;&amp;quot;There is a limitation in the ncs v1.9.1 which only allows multiple of block size input and outputs. The 1.9 was the first release which supported the PSA APIs. This issue is fixed in the ncs v.2.0.x which I highly suggest to use for this. For the v.1.9.1 a workaround is to use the PSA Oberon driver. &amp;quot;&lt;/p&gt;
&lt;p&gt;Does this work for you?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377476?ContentTypeID=1</link><pubDate>Mon, 18 Jul 2022 21:23:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e90aff59-fd3e-42fb-989d-ffd345f840a5</guid><dc:creator>Regie Roshan Magendiran</dc:creator><description>&lt;p&gt;I did try&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://armmbed.github.io/mbed-crypto/html/api/ops/ciphers.html?highlight=psa_cipher_update#c.PSA_CIPHER_UPDATE_OUTPUT_SIZE"&gt;PSA_CIPHER_UPDATE_OUTPUT_SIZE&lt;/a&gt;&amp;nbsp;earlier. I tried it again to re-confirm. So for an input message length of 76 bytes, key type&amp;nbsp;PSA_KEY_TYPE_AES, and algorithm PSA_ALG_CTR, the output buffer size is 76 bytes. But when I feed&amp;nbsp;a input and output buffer length of 76 bytes&amp;nbsp;to &lt;span&gt;psa_cipher_update(), it returns&amp;nbsp;PSA_ERROR_INVALID_ARGUMENT.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Regie&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377447?ContentTypeID=1</link><pubDate>Mon, 18 Jul 2022 14:14:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b95e289-b942-4338-9316-37ac81265375</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi Regie,&lt;/p&gt;
&lt;p&gt;Thanks for explaining your issue, I get it now.&lt;/p&gt;
&lt;p&gt;I will ask our crypto experts if there any rules for about the output length.&lt;/p&gt;
&lt;p&gt;In the meantime, maybe &lt;a href="https://armmbed.github.io/mbed-crypto/html/api/ops/ciphers.html?highlight=psa_cipher_update#c.PSA_CIPHER_UPDATE_OUTPUT_SIZE"&gt;PSA_CIPHER_UPDATE_OUTPUT_SIZE&lt;/a&gt; would be helpful to get output sizes.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377444?ContentTypeID=1</link><pubDate>Mon, 18 Jul 2022 13:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5be15d5-ff0f-4e81-92b0-7d847cb785fb</guid><dc:creator>Regie Roshan Magendiran</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;Thanks for trying it out. Let me give you more information about what I&amp;#39;m trying to implement.&lt;/p&gt;
&lt;p&gt;In your example you are maintaining a buffer of 128 bytes (initialized to zero), and I think, your input message length is 15 bytes here. This gets encrypted using the algorithm which outputs a 128 bytes encrypted cipher text. So for an input message length of 15 bytes, the&amp;nbsp;encrypted output length&amp;nbsp;is 128 bytes.&lt;/p&gt;
&lt;p&gt;In our application, we need the same encrypted output length as the input length, for example,&amp;nbsp; for 15 bytes input length, we would need 15 bytes encrypted output. We had this implemented using the sdk17.0.2. Our application involves in sending the encrypted text via BLE and we cannot afford to send more (extra) bytes due to our high transmission frequency.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To implement this with the PSA crypto example in ncs sdk, I simply changed the size of the input message and the output length buffer in&amp;nbsp;psa_cipher_update(), but as I said earlier, I received&amp;nbsp;&amp;nbsp;&lt;span&gt;PSA_ERROR_INVALID_ARGUMENT. Then as I debugged more, I found out that the input message length should be in multiples of 16 bytes. But if I understand correctly, for AES-CTR-128, this should not be the case. AES-CTR-128 should be able to output an encrypted output of the same length as its input message length. I also remember, this was one of the reason why we chose AES-CTR-128 (padding is not required).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;So I would need AES-CTR-128 encryption that would give the same encrypted output length as the input message length.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Why isn&amp;#39;t this possible? Or am I doing something wrong?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your time again!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regie&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PSA encryption - AES CTR 128 - message input length</title><link>https://devzone.nordicsemi.com/thread/377401?ContentTypeID=1</link><pubDate>Mon, 18 Jul 2022 11:51:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c26bc16-b586-466c-b12a-34fe873ff25c</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>[quote user=""]encrypt[/quote]
&lt;p&gt;Hi Regie,&lt;/p&gt;
&lt;p&gt;I do not think I understand your question.&lt;br /&gt;When I try to replicate your issue, I change the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/samples/crypto/aes_ctr/src/main.c b/samples/crypto/aes_ctr/src/main.c
index a76cd2f44..896868255 100644
--- a/samples/crypto/aes_ctr/src/main.c
+++ b/samples/crypto/aes_ctr/src/main.c
@@ -40,7 +40,7 @@ static uint8_t m_iv[NRF_CRYPTO_EXAMPLE_AES_BLOCK_SIZE];
 
 /* Below text is used as plaintext for encryption/decryption */
 static uint8_t m_plain_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE] = {
-       &amp;quot;Example string to demonstrate basic usage of AES CTR mode.&amp;quot;
+       &amp;quot;Example string &amp;quot;
 };
 
 static uint8_t m_encrypted_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE];
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But it runs fine, with the log as follows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.7.99-ncs1-1  ***
[00:00:00.415,924] &amp;lt;inf&amp;gt; aes_ctr: Starting AES CTR example...
[00:00:00.415,924] &amp;lt;inf&amp;gt; aes_ctr: Generating random AES key...
[00:00:00.416,168] &amp;lt;inf&amp;gt; aes_ctr: AES key generated successfully!
[00:00:00.416,168] &amp;lt;inf&amp;gt; aes_ctr: Encrypting using AES CTR MODE...
[00:00:00.416,625] &amp;lt;inf&amp;gt; aes_ctr: Encryption successful!

[00:00:00.416,625] &amp;lt;inf&amp;gt; aes_ctr: ---- IV (len: 16): ----
[00:00:00.416,656] &amp;lt;inf&amp;gt; aes_ctr: Content:
                                  39 0c fe 12 ff 66 6c 31  95 01 8d a5 35 e0 96 54 |9....fl1 ....5..T
[00:00:00.416,656] &amp;lt;inf&amp;gt; aes_ctr: ---- IV end  ----
[00:00:00.416,656] &amp;lt;inf&amp;gt; aes_ctr: ---- Plaintext (len: 128): ----
[00:00:00.416,717] &amp;lt;inf&amp;gt; aes_ctr: Content:
                                  45 78 61 6d 70 6c 65 20  73 74 72 69 6e 67 20 00 |Example  string .
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
[00:00:00.416,717] &amp;lt;inf&amp;gt; aes_ctr: ---- Plaintext end  ----
[00:00:00.416,717] &amp;lt;inf&amp;gt; aes_ctr: ---- Encrypted text (len: 128): ----
[00:00:00.416,748] &amp;lt;inf&amp;gt; aes_ctr: Content:
                                  59 52 a9 d6 e4 da b1 69  7f 74 94 f8 8f 22 ca 0b |YR.....i .t...&amp;quot;..
                                  36 e2 9c 9d ed f7 c9 15  e1 df 75 de 6e 42 bf 49 |6....... ..u.nB.I
                                  3e 29 3a 45 83 16 4b 50  b9 e2 47 96 69 60 3f b5 |&amp;gt;):E..KP ..G.i`?.
                                  b0 19 a4 27 03 55 3b d8  b0 0e 7a 07 bf 9a 81 dd |...&amp;#39;.U;. ..z.....
                                  be 6f c2 13 8a ce e4 26  17 e4 f5 66 ea 75 9f ed |.o.....&amp;amp; ...f.u..
                                  89 58 04 37 e1 ad 52 14  d7 a9 da dd 2d a9 51 f7 |.X.7..R. ....-.Q.
                                  de 9e b5 e4 c3 7d b1 e8  d7 93 f1 eb fc 1c 93 b7 |.....}.. ........
                                  d8 b7 86 c4 ff 7e f8 84  77 99 05 98 a2 ca 89 20 |.....~.. w...... 
[00:00:00.416,778] &amp;lt;inf&amp;gt; aes_ctr: ---- Encrypted text end  ----
[00:00:00.416,778] &amp;lt;inf&amp;gt; aes_ctr: Decrypting using AES CTR MODE...
[00:00:00.417,114] &amp;lt;inf&amp;gt; aes_ctr: ---- Decrypted text (len: 128): ----
[00:00:00.417,144] &amp;lt;inf&amp;gt; aes_ctr: Content:
                                  45 78 61 6d 70 6c 65 20  73 74 72 69 6e 67 20 00 |Example  string .
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                                  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
[00:00:00.417,144] &amp;lt;inf&amp;gt; aes_ctr: ---- Decrypted text end  ----
[00:00:00.417,236] &amp;lt;inf&amp;gt; aes_ctr: Decryption successful!
[00:00:00.417,297] &amp;lt;inf&amp;gt; aes_ctr: Example finished successfully!
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Are you looking for something other than this?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>