Skip to content

test: [kat-app] remove unsafe SNOW3G key pointer casts#178

Closed
iragimov-arm wants to merge 1 commit into
intel:mainfrom
iragimov-arm:snow3g_kat
Closed

test: [kat-app] remove unsafe SNOW3G key pointer casts#178
iragimov-arm wants to merge 1 commit into
intel:mainfrom
iragimov-arm:snow3g_kat

Conversation

@iragimov-arm
Copy link
Copy Markdown
Contributor

@iragimov-arm iragimov-arm commented Apr 20, 2026

Change submit_uea2_jobs() to take snow3g_key_schedule_t *const *keys instead of uint8_t **const keys and update the call sites to pass typed key-schedule pointers directly. This removes unsafe pointer casts in the SNOW3G KAT job API path and fixes invalid key handling that triggers IMB_STATUS_INVALID_ARGS with newer Clang compilers such as clang-21 and clang-22.

Description

When built with clang version >= 20, the KAT tests fail for SNOW3G-UEA.

Clang-22: SNOW3G KAT output before the patch:

./build/test/kat-app/imb-kat --test-type snow3g

Detected library version: 3.0.0-dev
Tool version: 3.0.0-dev
Detected hardware features:
        XSAVE         : OK
        OSXSAVE       : OK
        SHANI         : OK
        AESNI         : OK
        PCLMULQDQ     : OK
        MOVBE         : OK
        CMOV          : OK
        SSE4.2        : OK
        AVX           : OK
        AVX2          : OK
        AVX512(SKX)   : n/a
        VAES          : OK
        VPCLMULQDQ    : OK
        GFNI          : OK
        AVX512-IFMA   : n/a
        AVX-IFMA      : n/a
        BMI2          : OK
        HYBRID-CORE   : OK
        SM3NI         : n/a
        SM4NI         : n/a
        SHA512NI      : n/a
        APX           : n/a
        AVX10-256     : n/a
        AVX10-512     : n/a
SELF-TEST: PASS
[INFO] [ARCH] using SSE interface [SSE-SHANI-GFNI]
199 error status:4, job 0IMB_SNOW3G_F8_8_BUFFER(Enc) vector:1 buffer:0
Actual::
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 


Expected::
0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 
0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 


199 error status:4, job 0snow3g_f8_8_multi_buffer(Enc) vector:1 buffer:0
Actual::
0x91 0x09 0x68 0xF8 0x95 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 


Expected::
0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 
0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 


[INFO] [ALGO] SNOW3G-UEA2 FAIL
[INFO] [ALGO] SNOW3G-UIA2 PASS
SELF-TEST: PASS
[INFO] [ARCH] using AVX2 interface [AVX2]
199 error status:4, job 0IMB_SNOW3G_F8_8_BUFFER(Enc) vector:1 buffer:0
Actual::
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 


Expected::
0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 
0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 


199 error status:4, job 0snow3g_f8_8_multi_buffer(Enc) vector:1 buffer:0
Actual::
0xB1 0x01 0x68 0xF8 0x95 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 


Expected::
0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 
0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 


[INFO] [ALGO] SNOW3G-UEA2 FAIL
[INFO] [ALGO] SNOW3G-UIA2 PASS
Test completed: FAIL

As indicated by the error message specifically: 199 error status:4
the problem occurs at the stage of passing data through the Job API. Status 4 is a job->status value equal to IMB_STATUS_INVALID_ARGS.

After a brief analysis, it became clear that the root cause of the error is an attempt to pass an invalid pointer to the keys for SNOW3G algorithms. In the is_job_invalid() function from lib/include/mb_mgr_job_check.h file, the keys are checked against NULL and fail this validation:

                if (job->enc_keys == NULL) {
                        imb_set_errno(state, IMB_ERR_JOB_NULL_KEY);
                        return 1;
                }

This issue is unrelated to the algorithm implementations themselves, since execution never reaches them. The algorithms have also been tested via the Direct API. The problem is not an internal issue of the Job API either, as all keys are properly initialized in the test source code before the algorithms are executed.
This error occurs only in the Release build and is not detected in the Debug build.
It turns out that the root cause lies in the test code. Specifically, the issue is caused by passing keys between functions using a cast to uint8_t **.

How Has This Been Tested?

Hardware:

Architecture:                x86_64
  CPU op-mode(s):            32-bit, 64-bit
  Address sizes:             46 bits physical, 48 bits virtual
  Byte Order:                Little Endian
CPU(s):                      12
  On-line CPU(s) list:       0-11
Vendor ID:                   GenuineIntel
  Model name:                13th Gen Intel(R) Core(TM) i7-1365U
    CPU family:              6
    Model:                   186
    Thread(s) per core:      2
    Core(s) per socket:      10
    Socket(s):               1
    Stepping:                3
    CPU max MHz:             5200.0000
    CPU min MHz:             400.0000
    BogoMIPS:                5376.00
    Flags:                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_kno
                             wn_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanc
                             ed tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_not
                             ify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_user

Compiler:

Ubuntu clang version 22.0.0 (++20251015042503+856555bfd843-1~exp1~20251015042630.2731)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-22/bin

Test command line:
./build/test/kat-app/imb-kat --test-type snow3g

Test output:

Detected library version: 3.0.0-dev
Tool version: 3.0.0-dev
Detected hardware features:
        XSAVE         : OK
        OSXSAVE       : OK
        SHANI         : OK
        AESNI         : OK
        PCLMULQDQ     : OK
        MOVBE         : OK
        CMOV          : OK
        SSE4.2        : OK
        AVX           : OK
        AVX2          : OK
        AVX512(SKX)   : n/a
        VAES          : OK
        VPCLMULQDQ    : OK
        GFNI          : OK
        AVX512-IFMA   : n/a
        AVX-IFMA      : n/a
        BMI2          : OK
        HYBRID-CORE   : OK
        SM3NI         : n/a
        SM4NI         : n/a
        SHA512NI      : n/a
        APX           : n/a
        AVX10-256     : n/a
        AVX10-512     : n/a
SELF-TEST: PASS
[INFO] [ARCH] using SSE interface [SSE-SHANI-GFNI]
[INFO] [ALGO] SNOW3G-UEA2 PASS
[INFO] [ALGO] SNOW3G-UIA2 PASS
SELF-TEST: PASS
[INFO] [ARCH] using AVX2 interface [AVX2]
[INFO] [ALGO] SNOW3G-UEA2 PASS
[INFO] [ALGO] SNOW3G-UIA2 PASS
Test completed: PASS

Checklist

  • Fixed for clang-21 build
  • Fixed for clang-22 build

Change submit_uea2_jobs() to take snow3g_key_schedule_t *const *keys
instead of uint8_t **const keys and update the call sites to pass typed
key-schedule pointers directly. This removes unsafe pointer casts in
the SNOW3G KAT job API path and fixes invalid key handling that
triggers IMB_STATUS_INVALID_ARGS with newer Clang compilers such as
clang-21 and clang-22.

Signed-off-by: Islam Ragimov <islam.ragimov@arm.com>
@mdcornu
Copy link
Copy Markdown
Contributor

mdcornu commented Apr 27, 2026

This is now merged into main.

Closing this PR. Thank you for your contribution.

@mdcornu mdcornu closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants