Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package openCryptoki for openSUSE:Factory 
checked in at 2026-11-19 16:57:43
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/openCryptoki (Old)
 and      /work/SRC/openSUSE:Factory/.openCryptoki.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "openCryptoki"

Thu Nov 19 16:57:43 2026 rev:99 rq:1398682 version:3.28.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/openCryptoki/openCryptoki.changes        
2026-11-04 19:52:00.811844505 +0100
+++ /work/SRC/openSUSE:Factory/.openCryptoki.new.1251/openCryptoki.changes      
2026-11-19 16:59:03.721821343 +0100
@@ -1,0 +2,9 @@
+Thu Nov 19 10:17:22 UTC 2026 - Nikolay Gueorguiev <[email protected]>
+
+- Fix for the following vulnerability (CVE assignment still pending):
+  * Soft token AES-CTR ignores the nonce and repeats keystream when
+    ulCounterBits < 128 (bsc#1290848, GHSA-79qh-5gjg-gmm8):
+    + openCryptoki-GHSA-79qh-5gjg-gmm8-commit-e987dd3.patch
+    + openCryptoki-GHSA-79qh-5gjg-gmm8-commit-04eabed.patch
+
+-------------------------------------------------------------------

New:
----
  openCryptoki-GHSA-79qh-5gjg-gmm8-commit-04eabed.patch
  openCryptoki-GHSA-79qh-5gjg-gmm8-commit-e987dd3.patch

----------(New B)----------
  New:    + openCryptoki-GHSA-79qh-5gjg-gmm8-commit-e987dd3.patch
    + openCryptoki-GHSA-79qh-5gjg-gmm8-commit-04eabed.patch
  New:    ulCounterBits < 128 (bsc#1290848, GHSA-79qh-5gjg-gmm8):
    + openCryptoki-GHSA-79qh-5gjg-gmm8-commit-e987dd3.patch
    + openCryptoki-GHSA-79qh-5gjg-gmm8-commit-04eabed.patch
----------(New E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ openCryptoki.spec ++++++
--- /var/tmp/diff_new_pack.1neRYU/_old  2026-11-19 16:59:04.513854916 +0100
+++ /var/tmp/diff_new_pack.1neRYU/_new  2026-11-19 16:59:04.514854958 +0100
@@ -50,6 +50,9 @@
 # and because we don't want(?) various file and directory permissions to be 
0700.
 Patch000:       ocki-3.28-remove-make-install-chgrp.patch
 #
+Patch010:       openCryptoki-GHSA-79qh-5gjg-gmm8-commit-e987dd3.patch
+Patch011:       openCryptoki-GHSA-79qh-5gjg-gmm8-commit-04eabed.patch
+#
 BuildRequires:  autoconf
 BuildRequires:  autoconf-archive
 BuildRequires:  automake

++++++ openCryptoki-GHSA-79qh-5gjg-gmm8-commit-04eabed.patch ++++++
>From 04eabed2c52f758c2cd96e97673c5fa68a6da3c2 Mon Sep 17 00:00:00 2001
From: Ingo Franzki <[email protected]>
Date: Fri, 6 Nov 2026 10:24:19 +0100
Subject: [PATCH] ICA: Only use libica for AES-CTR with byte-sized counters

libica's ica_aes_ctr() only supports counter widths that are a multiple
of 8 bits. Handle all other counter widths with the generic OpenSSL
implementation.

Note that libica versions without the fix for the counter increment in
__inc_aes_ctr() and __fill_aes_ctrlist() return wrong results for
counter widths above 64 bits, and for a 128 bit counter whose lower 64
bits wrap around.

Signed-off-by: Ingo Franzki <[email protected]>
---
 usr/lib/ica_s390_stdll/ica_specific.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/usr/lib/ica_s390_stdll/ica_specific.c 
b/usr/lib/ica_s390_stdll/ica_specific.c
index 2c33e0d56..e1420aa3a 100644
--- a/usr/lib/ica_s390_stdll/ica_specific.c
+++ b/usr/lib/ica_s390_stdll/ica_specific.c
@@ -4286,7 +4286,15 @@ CK_RV token_specific_aes_ctr(STDLL_TokData_t *tokdata,
     CK_RV rc;
     CK_ATTRIBUTE *attr = NULL;
 
-    if (!ica_data->ica_aes_available)
+    /*
+     * libica supports any data length, but only counter widths that are a
+     * multiple of 8 bits. A counter width that is not a multiple of 8 bits
+     * is handled by the generic OpenSSL implementation.
+     * Note: libica versions without the fix for the counter increment in
+     * __inc_aes_ctr()/__fill_aes_ctrlist() produce wrong results for
+     * counter widths above 64 bits.
+     */
+    if (!ica_data->ica_aes_available || counter_width % 8 != 0)
         return openssl_specific_aes_ctr(tokdata, in_data, in_data_len,
                                         out_data, out_data_len, key,
                                         counterblock, counter_width, encrypt);

++++++ openCryptoki-GHSA-79qh-5gjg-gmm8-commit-e987dd3.patch ++++++
>From e987dd3aaf1d696b7994e4ff033e2a40b2331c0c Mon Sep 17 00:00:00 2001
From: Ingo Franzki <[email protected]>
Date: Fri, 6 Nov 2026 10:23:12 +0100
Subject: [PATCH] COMMON/SOFT/ICA: Fix AES-CTR nonce being ignored for counter
 widths < 128

openssl_specific_aes_ctr() built the IV for OpenSSL from the low
ulCounterBits / 8 bytes of the counter block, placed at the start of a
zeroed block. The nonce part of the counter block was never used, so for
ulCounterBits < 128 the key stream depended only on the key and the
counter value. Two messages under the same key whose counter blocks
differ only in the nonce were encrypted with the same key stream.

OpenSSL also incremented the zero padding rather than the counter, and
the counter written back to the caller was wrong. With multi-part
operations in 16 byte steps every block of the message was encrypted
with the same key stream block. The counter was also never wrapped at
ulCounterBits, as PKCS#11 requires.

Pass the whole counter block to OpenSSL as IV. Since OpenSSL always
increments all 128 bits, split the data at the point where the low
ulCounterBits bits wrap, and restart with the wrapped counter and the
nonce bits unchanged for the remainder. Write the updated counter block
back to the caller only on success. Counter widths that are not a
multiple of 8 bits are handled by using a bit mask.

A counter width of 128 bits was not affected. The CCA, EP11 and ICSF
tokens do not support CKM_AES_CTR. The ICA token is affected only if it
falls back to the software implementation.

Data encrypted with the old code and a counter width < 128 bits can not
be decrypted with the fixed code and must be re-encrypted.

Reported-by: Alexandre Laroche <[email protected]>
Signed-off-by: Ingo Franzki <[email protected]>
---
 usr/lib/common/mech_openssl.c | 119 ++++++++++++++++++++++++++++++----
 1 file changed, 108 insertions(+), 11 deletions(-)

diff --git a/usr/lib/common/mech_openssl.c b/usr/lib/common/mech_openssl.c
index 5d2466f7c..1d16b810b 100644
--- a/usr/lib/common/mech_openssl.c
+++ b/usr/lib/common/mech_openssl.c
@@ -10,6 +10,7 @@
 
 
 #include <pthread.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -4669,6 +4670,78 @@ CK_RV openssl_specific_aes_cbc(STDLL_TokData_t *tokdata,
                                   encrypt);
 }
 
+/*
+ * Mask of the bits of byte 'idx' (0 = most significant byte) of a counter
+ * block that belong to the counter, i.e. to the 'counter_width' least
+ * significant bits of the 128 bit block.
+ */
+static CK_BYTE aes_ctr_byte_mask(CK_ULONG counter_width, unsigned int idx)
+{
+    CK_ULONG low_bit = (AES_BLOCK_SIZE - 1 - idx) * 8;
+
+    if (counter_width >= low_bit + 8)
+        return 0xff;
+    if (counter_width <= low_bit)
+        return 0x00;
+    return (CK_BYTE)((1u << (counter_width - low_bit)) - 1);
+}
+
+/*
+ * Number of blocks that can be processed with the current counter value
+ * before the counter wraps around (2^counter_width - counter).
+ * Returns UINT64_MAX if this number does not fit into 64 bits.
+ */
+static uint64_t aes_ctr_blocks_to_wrap(const CK_BYTE *cb,
+                                       CK_ULONG counter_width)
+{
+    uint64_t inv = 0;
+    unsigned int i;
+
+    /* inverted counter bits: 2^counter_width - 1 - counter */
+    for (i = 0; i < AES_BLOCK_SIZE; i++) {
+        CK_BYTE b = ~cb[i] & aes_ctr_byte_mask(counter_width, i);
+
+        if (i < AES_BLOCK_SIZE - 8) {
+            if (b != 0)
+                return UINT64_MAX;
+        } else {
+            inv = (inv << 8) | b;
+        }
+    }
+
+    if (inv == UINT64_MAX)
+        return UINT64_MAX;
+    return inv + 1;
+}
+
+/*
+ * Add 'n' to the counter (the 'counter_width' least significant bits) of the
+ * counter block. The counter wraps around at 2^counter_width, the other
+ * (nonce) bits of the block are left unchanged.
+ */
+static void aes_ctr_add(CK_BYTE *cb, CK_ULONG counter_width, uint64_t n)
+{
+    CK_BYTE orig[AES_BLOCK_SIZE];
+    unsigned int carry = 0, sum, add, i;
+    CK_BYTE mask;
+
+    memcpy(orig, cb, sizeof(orig));
+
+    for (i = 0; i < AES_BLOCK_SIZE; i++) {
+        unsigned int shift = i * 8;
+
+        add = shift < 64 ? (unsigned int)((n >> shift) & 0xff) : 0;
+        sum = cb[AES_BLOCK_SIZE - 1 - i] + add + carry;
+        cb[AES_BLOCK_SIZE - 1 - i] = (CK_BYTE)(sum & 0xff);
+        carry = sum >> 8;
+    }
+
+    for (i = 0; i < AES_BLOCK_SIZE; i++) {
+        mask = aes_ctr_byte_mask(counter_width, i);
+        cb[i] = (cb[i] & mask) | (orig[i] & ~mask);
+    }
+}
+
 CK_RV openssl_specific_aes_ctr(STDLL_TokData_t *tokdata,
                                CK_BYTE *in_data,
                                CK_ULONG in_data_len,
@@ -4678,8 +4751,10 @@ CK_RV openssl_specific_aes_ctr(STDLL_TokData_t *tokdata,
                                CK_BYTE *counterblock,
                                CK_ULONG counter_width, CK_BYTE encrypt)
 {
-    unsigned char init_v[AES_BLOCK_SIZE];
-    CK_RV rc;
+    CK_BYTE cb[AES_BLOCK_SIZE];
+    CK_ULONG offset = 0, chunk_len, remaining = in_data_len, len;
+    uint64_t blocks, to_wrap;
+    CK_RV rc = CKR_OK;
 
     UNUSED(tokdata);
 
@@ -4688,17 +4763,39 @@ CK_RV openssl_specific_aes_ctr(STDLL_TokData_t *tokdata,
         return CKR_ARGUMENTS_BAD;
     }
 
-    memset(init_v, 0, sizeof(init_v));
-    memcpy(init_v, counterblock + AES_BLOCK_SIZE - (counter_width / 8),
-           counter_width / 8);
+    /* Work on a copy, so that the counter block is only updated on success */
+    memcpy(cb, counterblock, sizeof(cb));
 
-    rc = openssl_cipher_perform(key, CKM_AES_CTR, in_data, in_data_len,
-                                  out_data, out_data_len, init_v, init_v,
-                                  encrypt);
+    /*
+     * OpenSSL increments the complete 128 bit block. Thus, split the data
+     * at the point where the counter bits wrap around, and restart with the
+     * wrapped counter (nonce bits unchanged) for the next part.
+     */
+    while (remaining > 0) {
+        blocks = ((uint64_t)remaining + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE;
+        to_wrap = aes_ctr_blocks_to_wrap(cb, counter_width);
 
-    if (rc == CKR_OK)
-        memcpy(counterblock, init_v + AES_BLOCK_SIZE - (counter_width / 8),
-               counter_width / 8);
+        if (to_wrap < blocks)
+            chunk_len = (CK_ULONG)(to_wrap * AES_BLOCK_SIZE);
+        else
+            chunk_len = remaining;
+
+        len = chunk_len;
+        rc = openssl_cipher_perform(key, CKM_AES_CTR, in_data + offset,
+                                    chunk_len, out_data + offset, &len,
+                                    cb, NULL, encrypt);
+        if (rc != CKR_OK)
+            return rc;
+
+        aes_ctr_add(cb, counter_width,
+                    ((uint64_t)chunk_len + AES_BLOCK_SIZE - 1) /
+                                                        AES_BLOCK_SIZE);
+        offset += chunk_len;
+        remaining -= chunk_len;
+    }
+
+    *out_data_len = in_data_len;
+    memcpy(counterblock, cb, sizeof(cb));
 
     return rc;
 }

Reply via email to