Tongsuo-Project / Tongsuo

铜锁/Tongsuo is a Modern Cryptographic Primitives and Protocols Library
https://www.tongsuo.net
Apache License 2.0
1.09k stars 178 forks source link

Cipher operation failed error during sm4-ccm decrypt operation #487

Open Premkumarx opened 11 months ago

Premkumarx commented 11 months ago

Issue Details : BabaSSL Version : master

Error Message : 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278:

Command : ./openssl speed -evp sm4-ccm -decrypt

Result : Doing SM4-CCM for 3s on 16 size blocks: 6110997 SM4-CCM's in 3.00s Doing SM4-CCM for 3s on 64 size blocks: 6071608 SM4-CCM's in 3.00s Doing SM4-CCM for 3s on 256 size blocks: 5944993 SM4-CCM's in 3.00s Doing SM4-CCM for 3s on 1024 size blocks: 5389947 SM4-CCM's in 3.00s Doing SM4-CCM for 3s on 8192 size blocks: 2892223 SM4-CCM's in 3.00s Doing SM4-CCM for 3s on 16384 size blocks: 1974567 SM4-CCM's in 3.00s version: 3.0.3 built on: Tue Sep 5 07:49:52 2023 UTC options: bn(64,64) compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -g -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG CPUINFO: OPENSSL_ia32cap=0x7ffef3ffffebffff:0x40417f5ef3bfb7ef The 'numbers' are in 1000s of bytes per second processed. type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 16384 bytes SM4-CCM 32591.98k 129527.64k 507306.07k 1839768.58k 7897696.94k 10783768.58k 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278: 009452C2087F0000:error:1C800066:Provider routines:ossl_ccm_stream_update:cipher operation failed:providers/implementations/ciphers/ciphercommon_ccm.c:278:

InfoHunter commented 10 months ago

After some investigation in the code, I don't think this is a true bug. The speed code is not well written for ccm decryption so there seems to be a mismatching tag which will lead to decryption failure.