File ocki-3.15.1-EP11-Fix-host-library-version-query.patch of Package openCryptoki.25496

From f29516ff9f52c6c4e2816af9c70a23a5b861311b Mon Sep 17 00:00:00 2001
From: Ingo Franzki <ifranzki@linux.ibm.com>
Date: Tue, 15 Mar 2022 13:14:16 +0100
Subject: [PATCH 2/2] EP11: Fix host library version query

Look at release and modification level, not just the modification level.
Release and modification level are encoded into the one byte minor
field of a CK_VERSION. The high order 4 bits are the release number, the
low order 4 bits the modification level.

This allows host library version checks for release and modification levels.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
---
 usr/lib/ep11_stdll/ep11_specific.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
index 60c27141..f76a41df 100644
--- a/usr/lib/ep11_stdll/ep11_specific.c
+++ b/usr/lib/ep11_stdll/ep11_specific.c
@@ -9039,8 +9039,19 @@ static CK_RV ep11tok_get_ep11_library_version(CK_VERSION *lib_version)
                     rc);
         return rc;
     }
+    TRACE_DEVEL("%s host_version=0x08%x\n", __func__, host_version);
     lib_version->major = (host_version & 0x00FF0000) >> 16;
-    lib_version->minor = host_version & 0x000000FF;
+    /* Minor is 4 bits release number and 4 bits modification level */
+    lib_version->minor = (host_version & 0x00000F00) >> 4 |
+                                            (host_version & 0x0000000F);
+    if ((host_version & 0x0000F000) != 0) {
+        lib_version->minor |= 0xF0;
+        TRACE_DEVEL("%s relelase > 15, treating as 15\n", __func__);
+    }
+    if ((host_version & 0x000000F0) != 0) {
+        lib_version->minor |= 0x0F;
+        TRACE_DEVEL("%s modification level > 15, treating as 15\n", __func__);
+    }
     /*
      * EP11 host library < v2.0 returns an invalid version (i.e. 0x100). This
      * can safely be treated as version 1.0
@@ -9064,9 +9075,10 @@ static CK_RV ep11tok_get_ep11_version(STDLL_TokData_t *tokdata)
     if (rc != CKR_OK)
         return rc;
 
-    TRACE_INFO("%s Host library version: %d.%d\n", __func__,
+    TRACE_INFO("%s Host library version: %d.%d.%d\n", __func__,
                ep11_data->ep11_lib_version.major,
-               ep11_data->ep11_lib_version.minor);
+               (ep11_data->ep11_lib_version.minor & 0xF0) >> 4,
+               (ep11_data->ep11_lib_version.minor & 0x0F));
 
     memset(&qv, 0, sizeof(qv));
     qv.ep11_data = ep11_data;
@@ -9151,6 +9163,7 @@ void ep11tok_copy_firmware_info(STDLL_TokData_t *tokdata,
     if (ep11_data->card_versions != NULL)
         pInfo->hardwareVersion = ep11_data->card_versions->firmware_version;
     pInfo->firmwareVersion = ep11_data->ep11_lib_version;
+    pInfo->firmwareVersion.minor >>= 4; /* report release, skip mod-level */
     memcpy(pInfo->serialNumber, ep11_data->serialNumber,
            sizeof(pInfo->serialNumber));
 }
-- 
2.16.2.windows.1

openSUSE Build Service is sponsored by