smuellerDD / libkcapi

Linux Kernel Crypto API User Space Interface Library
http://www.chronox.de/libkcapi
Other
171 stars 72 forks source link

Cannot get valid data via kcapi_cipher_dec_aes_cbc for blocks > 64KiB #127

Open apylchagin opened 3 years ago

apylchagin commented 3 years ago

Hello,

I'm experiencing issues with that function for blocks bigger than 64KiB. I'm working on migration from openssl based to kcapi based. The data is coming by 70-80KiB blocks and I need to decrypt them. There is a unit test which just compares the existing openssl based and the new kcapi based implementation. the byte-to-byte comparison is showing that the error exists ONLY in 16 bytes from 0x10000 all other parts of the entire decrypted data are identical.

The environment I've tried on: 1) Stock Ubuntu 20.04 (Intel server platform) 2) NXP imx8 (Android 10)

The quick check I've done by doubling the pagesize in _kcapi_handle_alloc() which avoid split the data into 64KiB blocks and after that the result is exactly the same to openssl output, i.e. all test have passed.

I've build 1.3.1 version by myself for both platforms.

Any guidance or recommendations would be appreciated. can it be that this function is deprecated for some reason?

smuellerDD commented 3 years ago

Am Mittwoch, dem 06.10.2021 um 02:11 -0700 schrieb apylchagin:

Hello,

I'm experiencing issues with that function for blocks bigger than 64KiB. I'm working on migration from openssl based to kcapi based. The data is coming by 70-80KiB blocks and I need to decrypt them. There is a unit test which just compares the existing openssl based and the new kcapi based implementation. the byte-to-byte comparison is showing that the error exists ONLY in 16 bytes from 0x10000 all other parts of the entire decrypted data are identical.

The environment I've tried on: 1) Stock Ubuntu 20.10 (Intel server platform) 2) NXP imx8 (Android 10)

The quick check I've done by doubling the pagesize in _kcapi_handle_alloc() which avoid split the data into 64KiB blocks and after that the result is exactly the same to openssl output.

I've build 1.3.1 version by myself for both platforms.

Which algo are you testing? The core issue that I see here is that the algorithm does not support a "steam" operation where multiple input/output calls on the same key/IV are supported.

What you did is to increase the allotted buffer to get more data into the kernel in one call where the issue is not triggered.

Ciao Stephan

apylchagin commented 3 years ago

Thank you for the quick response. I've got data in AES CBC 128-bit -- I believe this is a function kcapi_cipher_dec_aes_cbc for that algo only -- cbc(aes). right?

The core issue that I see here is that the algorithm does not support a "steam" operation where multiple input/output calls on the same key/IV are supported.

For my case there is no multiple calls in row of kcapi_cipher_dec_aes_cbc() for the same data-chunk. I've got a single chunk of 80KiB encrypted data and I'm calling kcapi_cipher_dec_aes_cbc() for whole that chunk only once, i.e. ivec is passed only once. The function returns me no errors; it gives exact amount of decrypted bytes, i.e. the same 80KiB. So, the only multiple calls which I can via trace and kcapi logs are done internally by kcapi.

Per kcapi_cipher_dec_aes_cbc() description I would expect that it should handle unrestricted block sizes with the only requirment to have them 16bytes-aligned. Does it mean that I need to use some other method or mechanism from kcapi, or this is a restriction of CryptoAPI for that algo?

If that function has some restriction it would make sense to add some note about 16*page-size restriction as soon as this is pre-defined algo.

What you did is to increase the allotted buffer to get more data into the kernel in one call where the issue is not triggered.

I understood that. Thanks for confirmation.

smuellerDD commented 3 years ago

Am Mittwoch, dem 06.10.2021 um 03:25 -0700 schrieb apylchagin:

Thank you for the quick response. I've got data in AES CBC 128-bit -- I believe this is a function kcapi_cipher_dec_aes_cbc for that algo only -- cbc(aes). right?

Yes, but there may be many algos behind that. Can you send me the /proc/crypto output?

The core issue that I see here is that the algorithm does not support a "steam" operation where multiple input/output calls on the same key/IV are supported.

For my case there is no multiple calls in row of kcapi_cipher_dec_aes_cbc() for the same data-chunk.

Maybe so, but libkcapi has to chunk it up commonly after PAGE_SIZE * 16 unless the pipe size is extended.

Note, the kernel naturally wants to limit how much data it processes. When, say, you send 1GB in a single submission, the kernel would need to handle/store that 1GB somewhere. As this is not advisable, the processing is chunked up.

I try to re-create the issue here.

I've got a single chunk of 80KiB encrypted data and I'm calling kcapi_cipher_dec_aes_cbc() for whole that chunk only once, i.e. ivec is passed only once. The function returns me no errors; it gives exact amount of decrypted bytes, i.e. the same 80KiB.

Per kcapi_cipher_dec_aes_cbc() description I would expect that it should handle unrestricted block sizes with the only requirment to have them 16bytes-aligned.  Does it mean that I need to use some other method or mechanism from kcapi, or this is a restriction of CryptoAPI for that also?

There is no size constraint. There maybe constraints in the crypto implementations.

What you did is to increase the allotted buffer to get more data into the kernel in one call where the issue is not triggered.

I understood that. Thanks for confirmation.

Thanks Stephan

apylchagin commented 3 years ago

Here we go. crypto.txt.zip -- 18.04 crypto.txt.zip -- 20.04

Just in case I've tried on two ubuntu servers:

1) Ubuntu 18.04.6 LTS -- Linux 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux 2) Ubuntu 20.04.3 LTS -- Linux 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

I'm very appreciate your assist.

smuellerDD commented 3 years ago

Am Mittwoch, dem 06.10.2021 um 05:10 -0700 schrieb apylchagin:

Here we go. crypto.txt.zip

Thanks. cbc-aes-aesni is the implementation that is used. I will test that here.

smuellerDD commented 2 years ago

Am Mittwoch, 6. Oktober 2021, 12:25:19 CEST schrieb apylchagin:

Hi apylchagin,

Thank you for the quick response. I've got data in AES CBC 128-bit -- I believe this is a function kcapi_cipher_dec_aes_cbc for that algo only -- cbc(aes). right?

The core issue that I see here is that the algorithm does not support a "steam" operation where multiple input/output calls on the same key/IV are supported.

For my case there is no multiple calls in row of kcapi_cipher_dec_aes_cbc() for the same data-chunk. I've got a single chunk of 80KiB encrypted data and I'm calling kcapi_cipher_dec_aes_cbc() for whole that chunk only once, i.e. ivec is passed only once. The function returns me no errors; it gives exact amount of decrypted bytes, i.e. the same 80KiB.

Per kcapi_cipher_dec_aes_cbc() description I would expect that it should handle unrestricted block sizes with the only requirment to have them 16bytes-aligned. Does it mean that I need to use some other method or mechanism from kcapi, or this is a restriction of CryptoAPI for that also?

What you did is to increase the allotted buffer to get more data into the kernel in one call where the issue is not triggered. I understood that. Thanks for confirmation.

I am so sorry for the delay. But the LRNG work kept me busy.

Now, I performed:

So, the decryption operation works as intended.

When I now test the convenience function with the following code, I get a matching output:

include

include

include

void main(void) { uint8_t key[16] = { 0 }; uint8_t data[88000] = { 0 }; uint8_t data2[88000] = { 1 }; uint8_t ct[88000]; uint8_t iv[16] = { 0 };

if (sizeof(data) % 16) {
    printf("non-aligned data\n");
    return;
}

kcapi_cipher_enc_aes_cbc(key, sizeof(key),
             data, sizeof(data),
             iv,
             ct, sizeof(ct));
kcapi_cipher_dec_aes_cbc(key, sizeof(key),
             ct, sizeof(ct),
             iv,
             data2, sizeof(data2));

if (memcmp(data, data2, sizeof(data))) {
    printf("mismatch\n");
} else {
    printf("match\n");
}

}

Thus, can you please help me what you do exactly?

One more note, the issue you describe is fixed with the change ce5866e0e77aa0e54200ddcab6c3b76cb7093090

When you strace the command above, the key is the following:

pipe([4, 5]) = 0 fcntl(4, F_SETPIPE_SZ, 69632) = 131072 fcntl(5, F_SETPIPE_SZ, 69632) = 131072

Thus, if the code above does not work, can you please strace the invocation and check whether the mentioned system calls are present?

Thanks Stephan

apylchagin commented 2 years ago

Hello Stephan.

Thank you for your support.

I've spent some time converting my example from bigger project into the dedicated repo https://github.com/apylchagin/kcapi_test. Plz, do not hesitate to use it for verification.

There are 4 possible test cases. KCAPI-ENC_DEC, OPENSSL-ENC_DEC, KCAPI-ENC-OPENSSL-DEC, OPENSSL-ENC-KCAPI-DEC. The code you provided above is a KCAPI-ENC_DEC case and here is the output from strace: EncDec.KcapiEncDec.txt.zip

So, on my setup both cases where openssl and kcapi are in use are failing. Here is the full log: tests.zip

At some moment, by mistake, instead of using own build of 1.3.1 version I used the system-installed in ubuntu 18.04 which is 1.0.3 and all tests surprisingly passed but they finished by error elated to incorrect address for free() call at the very end

Sincerely yours, Alex P

smuellerDD commented 2 years ago

Am Mittwoch, 27. Oktober 2021, 22:12:19 CEST schrieb apylchagin:

Hi apylchagin,

Hello Stephan.

I've stent some time converting my example from bigger project into the dedicated repo https://github.com/apylchagin/kcapi_test. Plz, do not hesitate to use it for verification.

There are 4 possible test cases. KCAPI-ENC_DEC, OPENSSL-ENC_DEC, KCAPI-ENC-OPENSSL-DEC, OPENSSL-ENC-KCAPI-DEC. The code you provided above is a KCAPI-ENC_DEC case and here is the output from strace: EncDec.KcapiEncDec.txt.zip

So, on my setup both cases there openssl and kcapi are in use are failing.

By mistake, instead of using own build of 1.3.1 version I used the system-installed in ubuntu 18.04 which is 1.0.3 and all tests passed but they finished by error elated to incorrect address for free() call.

$ mkdir build cmake -G"Unix Makefiles" -B build -S . -- The C compiler identification is GNU 11.2.1 -- The CXX compiler identification is GNU 11.2.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.1.1l")
CMake Error at CMakeLists.txt:27 (add_subdirectory): The source directory

/home/sm/tmp/kcapi_test/gtest

does not contain a CMakeLists.txt file.

-- Configuring incomplete, errors occurred! See also "/home/sm/tmp/kcapi_test/build/CMakeFiles/CMakeOutput.log".

$ ./setup_and_build.sh ~/tmp/kcapi_test/kcapi/code ~/tmp/kcapi_test autoreconf: 'configure.ac' or 'configure.in' is required

ls -l kcapi/code $

--> empty

It seems I miss something.

Thanks Stephan

Sincerely yours, Alex P

Ciao Stephan

apylchagin commented 2 years ago

Sorry about that. I've added googletest and kcapi repos as a git submodules. thus, you need to clone with submodules update or do it explicitly after clone: git submodule update --init

smuellerDD commented 2 years ago

It sounds like the issue is closed. Thus I close the report. If something is pending, please feel free to reopen it.

apylchagin commented 2 years ago

Sorry but I don’t get it. Could you please advice what version has a fix for it? The label 1.3.1 cannot be used for OpenSSL encoded content. Or the intent that the library can decode the content only encoded by itself? If I’m using some content which came to the software from some other resource I cannot use the cryptoapi?

Thank you for explanation in advance.

smuellerDD commented 2 years ago

Apologies - I misinterpreted your last comment.

After pulling you git repo again, I cannot get the code to configure:

$ cmake -G"Unix Makefiles" -B build -S .
-- The C compiler identification is GNU 11.2.1
-- The CXX compiler identification is GNU 11.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.1.1l")  
CMake Error at CMakeLists.txt:27 (add_subdirectory):
  The source directory

    /home/sm/tmp/kcapi_test/gtest

  does not contain a CMakeLists.txt file.

-- Configuring incomplete, errors occurred!
See also "/home/sm/tmp/kcapi_test/build/CMakeFiles/CMakeOutput.log".

Please provide me with the precise steps how to get your test compiled. Thanks.

apylchagin commented 2 years ago

@smuellerDD sorry for the long delay. I've update the script in my repo -- now it does git submodules update. Once you run it the build should be done and you should see the tests execution results. the code of test cases is in https://github.com/apylchagin/kcapi_test/blob/main/code/main.cc

smuellerDD commented 2 years ago

$ mkdir build cmake -G"Unix Makefiles" -B build -S . -- The C compiler identification is GNU 11.2.1 -- The CXX compiler identification is GNU 11.2.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) CMake Error at CMakeLists.txt:27 (add_subdirectory): The source directory

/home/sm/tmp/kcapi_test/gtest

does not contain a CMakeLists.txt file.

-- Configuring incomplete, errors occurred! See also "/home/sm/tmp/kcapi_test/build/CMakeFiles/CMakeOutput.log".

apylchagin commented 1 year ago

Hello, sorry for a long time not seeing the answer. This is what I do on my setup:

sudo sudo apt install autoconf libtool
cd ~
git clone git@github.com:apylchagin/kcapi_test.git
cd kcapi_test
./setup_and_build.sh

the result is:

parallels@ubuntu-linux-20-04-desktop:/media/psf/SAM_MAC/code/kcapi_test$ ./setup_and_build.sh 
make sure the autoconf and libtool are installed
/media/psf/SAM_MAC/code/kcapi_test/kcapi/code /media/psf/SAM_MAC/code/kcapi_test
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert aarch64-unknown-linux-gnu file names to aarch64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert aarch64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking how to run the C preprocessor... gcc -E
checking for gcc... gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking how to run the C preprocessor... gcc -E
checking if gcc supports PIE... yes
checking for openssl... /usr/bin/openssl
checking for clang... no
checking for cppcheck... no
checking for xmlto... no
checking for db2pdf... no
checking for db2ps... no
checking for mktemp... /usr/bin/mktemp
checking for library containing clock_gettime... none required
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking whether ln -s works... yes
checking for cp... /usr/bin/cp
checking for ln... /usr/bin/ln
checking for mv... /usr/bin/mv
checking for touch... /usr/bin/touch
configure: WARNING: clang not installed
configure: WARNING: cppcheck not installed
configure: WARNING: xmlto not installed
configure: WARNING: db2pdf not installed
configure: WARNING: db2ps not installed
checking for getrandom... yes
checking for secure_getenv... yes
checking whether CC supports -fstack-protector-strong... yes
checking whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS... no
checking for tail... yes
configure: API version=1.3.1
configure: library version=1.3.1
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for off_t... yes
checking for _LARGEFILE_SOURCE value needed for large files... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libkcapi.pc
config.status: executing depfiles commands
config.status: executing libtool commands
Makefile:2025: warning: overriding recipe for target 'lib/doc/bin/docproc'
Makefile:992: warning: ignoring old recipe for target 'lib/doc/bin/docproc'
gcc -Wextra -Wall -pedantic -fwrapv --param ssp-buffer-size=4 -O2 -Werror -std=gnu99 -Wconversion  -g -O2 -o lib/doc/bin/docproc lib/doc/bin/docproc.o
/bin/bash ./libtool  --tag=CC   --mode=link gcc  -fstack-protector-strong -g -O2 -fpie -fPIE -DPIE -Wl,-z,relro,-z,now -Wl,--version-script,./lib/version.lds -version-number `echo 1.3.1 | sed 's/\./:/g'` -pie -o libkcapi.la -rpath /usr/local/lib lib/libkcapi_la-kcapi-kernel-if.lo lib/libkcapi_la-kcapi-utils.lo  lib/libkcapi_la-kcapi-sym.lo  lib/libkcapi_la-kcapi-md.lo  lib/libkcapi_la-kcapi-kdf.lo  lib/libkcapi_la-kcapi-aead.lo  lib/libkcapi_la-kcapi-rng.lo      
libtool: link: rm -fr  .libs/libkcapi.a .libs/libkcapi.la .libs/libkcapi.lai .libs/libkcapi.so .libs/libkcapi.so.1 .libs/libkcapi.so.1.3.1
libtool: link: gcc -shared  -fPIC -DPIC  lib/.libs/libkcapi_la-kcapi-kernel-if.o lib/.libs/libkcapi_la-kcapi-utils.o lib/.libs/libkcapi_la-kcapi-sym.o lib/.libs/libkcapi_la-kcapi-md.o lib/.libs/libkcapi_la-kcapi-kdf.o lib/.libs/libkcapi_la-kcapi-aead.o lib/.libs/libkcapi_la-kcapi-rng.o    -fstack-protector-strong -g -O2 -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,--version-script -Wl,./lib/version.lds   -Wl,-soname -Wl,libkcapi.so.1 -o .libs/libkcapi.so.1.3.1
libtool: link: (cd ".libs" && rm -f "libkcapi.so.1" && ln -s "libkcapi.so.1.3.1" "libkcapi.so.1")
libtool: link: (cd ".libs" && rm -f "libkcapi.so" && ln -s "libkcapi.so.1.3.1" "libkcapi.so")
libtool: link: ar cr .libs/libkcapi.a  lib/libkcapi_la-kcapi-kernel-if.o lib/libkcapi_la-kcapi-utils.o lib/libkcapi_la-kcapi-sym.o lib/libkcapi_la-kcapi-md.o lib/libkcapi_la-kcapi-kdf.o lib/libkcapi_la-kcapi-aead.o lib/libkcapi_la-kcapi-rng.o
libtool: link: ranlib .libs/libkcapi.a
libtool: link: ( cd ".libs" && rm -f "libkcapi.la" && ln -s "../libkcapi.la" "libkcapi.la" )
/media/psf/SAM_MAC/code/kcapi_test
mkdir: cannot create directory ‘build’: File exists
/media/psf/SAM_MAC/code/kcapi_test/build /media/psf/SAM_MAC/code/kcapi_test
-- Configuring done
-- Generating done
-- Build files have been written to: /media/psf/SAM_MAC/code/kcapi_test/build
Consolidate compiler generated dependencies of target gtest
[ 20%] Built target gtest
Consolidate compiler generated dependencies of target kcapi_test
Consolidate compiler generated dependencies of target gmock
Consolidate compiler generated dependencies of target gtest_main
[ 40%] Built target kcapi_test
[ 60%] Built target gmock
[ 80%] Built target gtest_main
Consolidate compiler generated dependencies of target gmock_main
[100%] Built target gmock_main
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from EncDec
[ RUN      ] EncDec.KcapiEncDec
[       OK ] EncDec.KcapiEncDec (0 ms)
[ RUN      ] EncDec.OpenSSLEncDec
[       OK ] EncDec.OpenSSLEncDec (0 ms)
[ RUN      ] EncDec.KcapiEncOpenSSLDec
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:93: Failure
Expected equality of these values:
  std::vector<uint8_t>(data, data + KCAPI_TEST_SIZE)
    Which is: { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', ... }
  std::vector<uint8_t>(data2, data2 + KCAPI_TEST_SIZE)
    Which is: { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', ... }
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xEB' (235)
idx==65536 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xE9' (233)
idx==65537 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '_' (95, 0x5F)
idx==65538 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\x87' (135)
idx==65539 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: 'a' (97, 0x61)
idx==65540 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: 'V' (86, 0x56)
idx==65541 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xC3' (195)
idx==65542 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\x89' (137)
idx==65543 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\x89' (137)
idx==65544 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xD4' (212)
idx==65545 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xF0' (240)
idx==65546 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '2' (50, 0x32)
idx==65547 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xB6' (182)
idx==65548 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\'' (39, 0x27)
idx==65549 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '\xFD' (253)
idx==65550 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:96: Failure
Expected equality of these values:
  data[idx]
    Which is: '\0'
  data2[idx]
    Which is: '>' (62, 0x3E)
idx==65551 of 88000
[  FAILED  ] EncDec.KcapiEncOpenSSLDec (2 ms)
[ RUN      ] EncDec.OpenSSLEncKcapiDec
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:125: Failure
Expected equality of these values:
  std::vector<uint8_t>(data, data + KCAPI_TEST_SIZE)
    Which is: { 'f' (102, 0x66), '\xE9' (233), 'K' (75, 0x4B), '\xD4' (212), '\xEF' (239), '\x8A' (138), ',' (44, 0x2C), ';' (59, 0x3B), '\x88' (136), 'L' (76, 0x4C), '\xFA' (250), 'Y' (89, 0x59), '\xCA' (202), '4' (52, 0x34), '+' (43, 0x2B), '.' (46, 0x2E), '\xF7' (247), '\x95' (149), '\xBD' (189), 'J' (74, 0x4A), 'R' (82, 0x52), '\xE2' (226), '\x9E' (158), '\xD7' (215), '\x13' (19), '\xD3' (211), '\x13' (19), '\xFA' (250), ' ' (32, 0x20), '\xE9' (233), '\x8D' (141), '\xBC' (188), ... }
  std::vector<uint8_t>(data2, data2 + KCAPI_TEST_SIZE)
    Which is: { 'f' (102, 0x66), '\xE9' (233), 'K' (75, 0x4B), '\xD4' (212), '\xEF' (239), '\x8A' (138), ',' (44, 0x2C), ';' (59, 0x3B), '\x88' (136), 'L' (76, 0x4C), '\xFA' (250), 'Y' (89, 0x59), '\xCA' (202), '4' (52, 0x34), '+' (43, 0x2B), '.' (46, 0x2E), '\xF7' (247), '\x95' (149), '\xBD' (189), 'J' (74, 0x4A), 'R' (82, 0x52), '\xE2' (226), '\x9E' (158), '\xD7' (215), '\x13' (19), '\xD3' (211), '\x13' (19), '\xFA' (250), ' ' (32, 0x20), '\xE9' (233), '\x8D' (141), '\xBC' (188), ... }
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: 'f' (102, 0x66)
  data2[idx]
    Which is: '\xF6' (246)
idx==65536 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\xE9' (233)
  data2[idx]
    Which is: '\x8E' (142)
idx==65537 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: 'K' (75, 0x4B)
  data2[idx]
    Which is: 'T' (84, 0x54)
idx==65538 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\xD4' (212)
  data2[idx]
    Which is: 'T' (84, 0x54)
idx==65539 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\xEF' (239)
  data2[idx]
    Which is: '&' (38, 0x26)
idx==65540 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\x8A' (138)
  data2[idx]
    Which is: '\x5' (5)
idx==65541 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: ',' (44, 0x2C)
  data2[idx]
    Which is: '\x9B' (155)
idx==65542 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: ';' (59, 0x3B)
  data2[idx]
    Which is: 'u' (117, 0x75)
idx==65543 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\x88' (136)
  data2[idx]
    Which is: 'P' (80, 0x50)
idx==65544 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: 'L' (76, 0x4C)
  data2[idx]
    Which is: '\x9A' (154)
idx==65545 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\xFA' (250)
  data2[idx]
    Which is: '\xDD' (221)
idx==65546 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: 'Y' (89, 0x59)
  data2[idx]
    Which is: '\x91' (145)
idx==65547 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '\xCA' (202)
  data2[idx]
    Which is: '\xAA' (170)
idx==65548 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '4' (52, 0x34)
  data2[idx]
    Which is: '\xA7' (167)
idx==65549 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '+' (43, 0x2B)
  data2[idx]
    Which is: ',' (44, 0x2C)
idx==65550 of 88000
/media/psf/SAM_MAC/code/kcapi_test/code/main.cc:128: Failure
Expected equality of these values:
  data[idx]
    Which is: '.' (46, 0x2E)
  data2[idx]
    Which is: '\x6' (6)
idx==65551 of 88000
[  FAILED  ] EncDec.OpenSSLEncKcapiDec (2 ms)
[----------] 4 tests from EncDec (5 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 1 test suite ran. (5 ms total)
[  PASSED  ] 2 tests.
[  FAILED  ] 2 tests, listed below:
[  FAILED  ] EncDec.KcapiEncOpenSSLDec
[  FAILED  ] EncDec.OpenSSLEncKcapiDec

 2 FAILED TESTS
smuellerDD commented 1 year ago

Am Dienstag, 25. Oktober 2022, 23:51:46 CET schrieb apylchagin:

Hi apylchagin,

Hello, sorry for a long time not seeing the answer. This is what I do on my setup:

sudo sudo apt install autoconf libtool
cd ~
git clone ***@***.***:apylchagin/kcapi_test.git
cd kcapi_test
./setup_and_build.sh

Perfect, thanks for the reproducer. I will work on it.

Ciao Stephan

smuellerDD commented 1 year ago

Am Dienstag, 25. Oktober 2022, 23:51:46 CET schrieb apylchagin:

Hi apylchagin,

Hello, sorry for a long time not seeing the answer. This is what I do on my setup:

sudo sudo apt install autoconf libtool
cd ~
git clone ***@***.***:apylchagin/kcapi_test.git
cd kcapi_test
./setup_and_build.sh

The error is visible with this:

    ASSERT_EQ(KCAPI_TEST_SIZE, kcapi_cipher_enc_aes_ctr(key, sizeof(key),
                             data, KCAPI_TEST_SIZE,
                             iv,
                             ct, KCAPI_TEST_SIZE));

std::cout << "here\n"; EXPECT_EQ(ct[0], ct[65536]) << " of " << KCAPI_TEST_SIZE; std::cout << "here2\n";

-> the output of ct[0] is identical to ct[65536]. As data is sent to the kernel in 65536 chunks, it implies that the new chunk is processed with a new IV state.

Somehow I recollect that the kernel developers wanted to disable staged calls like this, because it did not work appropriately. But I need to find out the current state and think about how to solve it.

Ciao Stephan