smuellerDD / acvpparser

ACVP Parser for invocation of cryptographic implementations using the ACVP JSON test vectors
https://www.chronox.de/acvpparser
Other
36 stars 27 forks source link

The AES MCT results in CBC/OFB modes do not match the expected result when run acvp-parser with libkcapi backends #34

Closed angelshadow closed 3 years ago

angelshadow commented 3 years ago

I implemetd the backends with libkcapi. When running the AES test, it was found that the AFT tests all passed, but the MCT tests in CBC/OFB modes do not match the expected results, I don't know if it is my implementation problem or the actual calculation result is incorrect. Can you help me see it? Here is the sample vetcors:

[ { "acvVersion": "1.0" },{ "vsId": 644483, "algorithm": "ACVP-AES-CBC", "revision": "1.0", "isSample": true, "testGroups": [ { "tgId": 37, "testType": "MCT", "direction": "encrypt", "keyLen": 128, "tests": [ { "tcId": 2151, "iv": "FBEA48BCBCD19F58C03169C756CDE723", "pt": "29A3226A9E133635358271B6BBD57E46", "key": "905A7251EE617FDF6221C0812EBFD969" } ] } ] } ].

The first round and second rouund of expected result is : "tgId": 37, "tests": [ { "tcId": 2151, "resultsArray": [ { "key": "905A7251EE617FDF6221C0812EBFD969", "iv": "FBEA48BCBCD19F58C03169C756CDE723", "pt": "29A3226A9E133635358271B6BBD57E46", "ct": "578B3B760ACD28C8F02EB6F2D76EAF40" },
{ "key": "C7D14927E4AC5717920F7673F9D17629", "iv": "578B3B760ACD28C8F02EB6F2D76EAF40", "pt": "CA6CCCD7F7BADB5BE9A4B14C2CA6977C", "ct": "12923C8DF14DF5A7385048D9EFBE3436" }

But my caculated result for output in first round and second round are :

{ "tcId":2151, "resultsArray":[ { "key":"905a7251ee617fdf6221c0812ebfd969", "pt":"29a3226a9e133635358271b6bbd57e46", "ct":"cdba8c721049b7840241d988dcabd16d", "iv":"fbea48bcbcd19f58c03169c756cde723" },
{ "key":"5de0fe23fe28c85b60601909f2140804", "pt":"e74fa52d047393844b0a6eb3d8f5e64b", "ct":"3068eee3242501b467c41bfc85146edd", "iv":"cdba8c721049b7840241d988dcabd16d" }

Here is my backends implenmetation with libkcapi: mct_init with cipher selection in libkcapi libriray. mct_fini with some log output

image

BTW, i dont know whether it is right with AES_CTR becasue I didnt find corresonding refernce

How can I locate and solve this problem. Attachment is the debug information of MCT test.
Because the AFT test results are correct, I believe there should be no problem with my crypto module. mct_1_round.log

Looking for your response , thanks.

smuellerDD commented 3 years ago

Am Donnerstag, dem 05.08.2021 um 08:03 -0700 schrieb angelshadow:

I implemetd the backends with libkcapi. When running the AES test, it was found that the AFT tests all passed, but the MCT tests in CBC/OFB/CTR modes do not match the expected results,  I don't know if it is my implementation problem or the actual calculation result is incorrect. Can you help me see it? Here is the sample vetcors:

The issue points to a key problem of the kernel crypto API with respect to ACVP.

First of all, when I tried it on my Intel box with AESNI, or aes-generic, I see no bugs (tested CBC only tonight with a 5.13 kernel).

The key problem is that the kernel crypto API has no guarantee that the state of a cipher handle is maintained. It is up to the algo implementation to return the IV back to the cipher handle. For implementations that do not return the IV to the handle, you lost as you cannot perform such ACVP testing.

I had discussions around that upstream about a year ago with Herbert Xu and Ard Biesheuvel.

Ciao Stephan

smuellerDD commented 3 years ago

Closing - in case the issue is still open, please reopen.