This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 6bd96f7a3263f354414064718d4b154042d12792
Author: makejian <[email protected]>
AuthorDate: Thu May 22 09:52:41 2025 +0800

    testing/drivers/crypto: pass the IV length
    
    cryptodev forwards cop->ivlen to the driver. The software driver derives
    the IV length from the algorithm, but a hardware driver uses the value it
    is given, so a test that leaves ivlen at 0 sends no IV and gets the wrong
    ciphertext. Set ivlen in the 3DES, AES-CBC and AES-CMAC tests.
    
    Signed-off-by: makejian <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 testing/drivers/crypto/3descbc.c | 7 ++++---
 testing/drivers/crypto/aescbc.c  | 2 ++
 testing/drivers/crypto/aescmac.c | 1 +
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/testing/drivers/crypto/3descbc.c b/testing/drivers/crypto/3descbc.c
index 5095786c2..09f92b4e6 100644
--- a/testing/drivers/crypto/3descbc.c
+++ b/testing/drivers/crypto/3descbc.c
@@ -41,7 +41,7 @@
 #include <unistd.h>
 
 static int syscrypt(FAR const unsigned char *key, size_t klen,
-                    FAR const unsigned char *iv,
+                    FAR const unsigned char *iv, size_t ivlen,
                     FAR const unsigned char *in, FAR unsigned char *out,
                     size_t len, int encrypt)
 {
@@ -79,6 +79,7 @@ static int syscrypt(FAR const unsigned char *key, size_t klen,
   cryp.flags = 0;
   cryp.len = len;
   cryp.olen = len;
+  cryp.ivlen = ivlen;
   cryp.src = (caddr_t) in;
   cryp.dst = (caddr_t) out;
   cryp.iv = (caddr_t) iv;
@@ -182,14 +183,14 @@ int main(int argc, FAR char **argv)
   memset(b2, 0, sizeof(b2));
   memcpy(iv, iv0, sizeof(iv0));
 
-  if (syscrypt(key, sizeof(key), iv, b1, b2, sizeof(b1), 1) < 0)
+  if (syscrypt(key, sizeof(key), iv, sizeof(iv), b1, b2, sizeof(b1), 1) < 0)
     {
       warnx("encrypt with /dev/crypto failed");
       fail++;
     }
 
   memcpy(iv, iv0, sizeof(iv0));
-  if (syscrypt(key, sizeof(key), iv, b2, b2, sizeof(b1), 0) < 0)
+  if (syscrypt(key, sizeof(key), iv, sizeof(iv), b2, b2, sizeof(b1), 0) < 0)
     {
       warnx("decrypt with /dev/crypto failed");
       fail++;
diff --git a/testing/drivers/crypto/aescbc.c b/testing/drivers/crypto/aescbc.c
index 6e9a33abb..92b51b8f5 100644
--- a/testing/drivers/crypto/aescbc.c
+++ b/testing/drivers/crypto/aescbc.c
@@ -182,6 +182,7 @@ static int syscrypt(FAR const char *key, size_t klen,
   cryp.flags = 0;
   cryp.len = len;
   cryp.olen = len;
+  cryp.ivlen = 16;
   cryp.src = (caddr_t) in;
   cryp.dst = (caddr_t) out;
   cryp.iv = (caddr_t) tmp_iv;
@@ -261,6 +262,7 @@ static int syscrypt_stream(FAR const char *key, size_t klen,
   cryp.flags = 0;
   cryp.mac = 0;
   cryp.iv = (caddr_t) tmp_iv;
+  cryp.ivlen = 16;
   while (len >= 16)
     {
       cryp.len = 16;
diff --git a/testing/drivers/crypto/aescmac.c b/testing/drivers/crypto/aescmac.c
index 8d745c25e..c84b75958 100644
--- a/testing/drivers/crypto/aescmac.c
+++ b/testing/drivers/crypto/aescmac.c
@@ -189,6 +189,7 @@ static int syscrypt(FAR const unsigned char *key, int 
keybits,
   cryp.op = COP_ENCRYPT;
   cryp.flags = 0;
   cryp.len = len;
+  cryp.olen = outlen;
   cryp.src = (caddr_t)message;
   cryp.mac = (caddr_t)output;
 

Reply via email to