Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 12 XMSS and 16 XMSSMT parameters. #1489

Merged
merged 9 commits into from
Jul 24, 2023

Conversation

ducnguyen-sb
Copy link
Contributor

@ducnguyen-sb ducnguyen-sb commented Jun 5, 2023

  1. All XMSS parameters are separated by namespace.
  2. After discussion with Andreas Huelsing, he recommends using the fast approach. This approach improved the performance of signing at the cost of larger sk.
  3. The _fast parameters is incompatible with the general version. At first, I couldn't believe it, I went back and generate original KATs file from original Github repo. And I confirm that the _fast and general version, given the same message and same randomness, it will generate different signatures. Given the signature of _fast, the general version cannot verify using _fast parameter public key.

Similar issue in xmss-reference: XMSS/xmss-reference#17

  1. All parameters are tested with pre-generated KAT files and SHA256 hashes of the KAT.

All the parameters added to XMSS. https://github.com/ducnguyen-sb/xmss-reference/blob/master/external/xmss_liboqs_params.md

Algorithms oid sk pk sig n
XMSS-SHA2_10_256 0x01 1373 64 2500 32
XMSS-SHA2_16_256 0x02 2093 64 2692 32
XMSS-SHA2_20_256 0x03 2573 64 2820 32
XMSS-SHAKE_10_256 0x07 1373 64 2500 32
XMSS-SHAKE_16_256 0x08 2093 64 2692 32
XMSS-SHAKE_20_256 0x09 2573 64 2820 32
XMSS-SHA2_10_512 0x04 2653 128 9092 64
XMSS-SHA2_16_512 0x05 4045 128 9476 64
XMSS-SHA2_20_512 0x06 4973 128 9732 64
XMSS-SHAKE_10_512 0x0a 2653 128 9092 64
XMSS-SHAKE_16_512 0x0b 4045 128 9476 64
XMSS-SHAKE_20_512 0x0c 4973 128 9732 64
XMSSMT-SHA2_20/2_256 0x01 5998 64 4963 32
XMSSMT-SHA2_20/4_256 0x02 10938 64 9251 32
XMSSMT-SHA2_40/2_256 0x03 9600 64 5605 32
XMSSMT-SHA2_40/4_256 0x04 15252 64 9893 32
XMSSMT-SHA2_40/8_256 0x05 24516 64 18469 32
XMSSMT-SHA2_60/3_256 0x06 16629 64 8392 32
XMSSMT-SHA2_60/6_256 0x07 24507 64 14824 32
XMSSMT-SHA2_60/12_256 0x08 38095 64 27688 32
XMSSMT-SHAKE_20/2_256 0x11 5998 64 4963 32
XMSSMT-SHAKE_20/4_256 0x12 10938 64 9251 32
XMSSMT-SHAKE_40/2_256 0x13 9600 64 5605 32
XMSSMT-SHAKE_40/4_256 0x14 15252 64 9893 32
XMSSMT-SHAKE_40/8_256 0x15 24516 64 18469 32
XMSSMT-SHAKE_60/3_256 0x16 16629 64 8392 32
XMSSMT-SHAKE_60/6_256 0x17 24507 64 14824 32
XMSSMT-SHAKE_60/12_256 0x18 38095 64 27688 32
  1. The upstream of the current code: https://github.com/ducnguyen-sb/xmss-reference
  • Does this PR change the input/output behaviour of a cryptographic algorithm (i.e., does it change known answer test values)? (If so, a version bump will be required from x.y.z to x.(y+1).0.)
  • Does this PR change the list of algorithms available -- either adding, removing, or renaming? Does this PR otherwise change an API? (If so, PRs in oqs-provider, OQS-OpenSSL, OQS-BoringSSL, and OQS-OpenSSH will also need to be ready for review and merge by the time this is merged.)

@dstebila dstebila added this to the 0.9.0 milestone Jul 5, 2023
@ducnguyen-sb ducnguyen-sb changed the title Add XMSS parameters: SHA2_10_256_fast and SHAKE_10_256 Add 28 XMSS parameters. Jul 17, 2023
@ducnguyen-sb
Copy link
Contributor Author

image

All test pass in local. CI/CD are time out in many platforms.

@ducnguyen-sb ducnguyen-sb marked this pull request as ready for review July 17, 2023 00:18
@ducnguyen-sb ducnguyen-sb changed the title Add 28 XMSS parameters. Add 12 XMSS and 16 XMSSMT parameters. Jul 17, 2023
@ducnguyen-sb
Copy link
Contributor Author

@dstebila I got CI timeout, what can I do to extend the test time longer?

@baentsch
Copy link
Member

@dstebila I got CI timeout, what can I do to extend the test time longer?

https://stackoverflow.com/questions/36173553/how-to-extend-timeout-for-tests-in-circleci#36209650

HOWEVER, may I question the practical value of code that apparently requires more than 10 minutes for a single signature operation? Or is the test too big?

@ducnguyen-sb
Copy link
Contributor Author

ducnguyen-sb commented Jul 17, 2023

Hi @baentsch ,

I think the test is too big (if the test is all schemes in liboqs, XMSS test only 1 iteration per parameter), when it reaches to XMSS it's almost out of time.
On my local machine: Apple M1, all test for XMSS took 1.13 second.

I assume CI is slower, if I multiply my local number by 100x, then it's about ~100 seconds. Still below the 600 seconds (10 minutes).

Yes, I think the choice of parameters Sign/Verify (we don't test keygen here, because it's very very long) is reasonable. (again, 1 seconds for 28 Sign/Verify test in my local).

Should I go ahead and modify the timeout?
Or, How can I just test XMSS to iterate my code quicker?

@ducnguyen-sb ducnguyen-sb force-pushed the ducnguyen-sb/xmss/add_two_parameters branch from 9969445 to a2e6076 Compare July 18, 2023 02:18
@ducnguyen-sb ducnguyen-sb force-pushed the ducnguyen-sb/xmss/add_two_parameters branch from f58f079 to f4f3799 Compare July 18, 2023 03:04
@baentsch
Copy link
Member

Should I go ahead and modify the timeout?

That should only be the last resort. But it seems you found a way without doing so: Great! Or are the tests now doing less?

@ducnguyen-sb
Copy link
Contributor Author

@baentsch I realize that the test_cmdline.py actually run the key pair generation.
So I write a helper so at certain parameters, it should read pre-generated keypair instead of generating one.

You can see the idea in this section of the code:

OQS_STATUS sig_stfl_KATs_keygen(OQS_SIG_STFL *sig, uint8_t *public_key, uint8_t *secret_key, const char *katfile) {
printf("%s", sig->method_name);
if (0) {
#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h16
} else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmss_sha256_h16) == 0) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_sha256_h20
} else if (strcmp(sig->method_name, OQS_SIG_STFL_alg_xmss_sha256_h20) == 0) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h16
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmss_shake128_h16)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_shake128_h20
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmss_shake128_h20)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h16
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmss_sha512_h16)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_sha512_h20
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmss_sha512_h20)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h16
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmss_shake256_h16)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmss_shake256_h20
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmss_shake256_h20)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h40_2
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h40_2)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmssmt_sha256_h60_3
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_sha256_h60_3)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h40_2
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h40_2)) {
goto from_kats;
#endif
#ifdef OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_3
} else if (0 == strcasecmp(sig->method_name, OQS_SIG_STFL_alg_xmssmt_shake128_h60_3)) {
goto from_kats;
#endif
} else {
goto from_keygen;
}
from_kats:
return sig_stfl_keypair_from_KATs(sig, public_key, secret_key, katfile);
from_keygen:
return sig_stfl_keypair_from_keygen(sig, public_key, secret_key);

Now I don't know why my test on arm_emulated return different hash output. That's strange.

@ducnguyen-sb
Copy link
Contributor Author

ducnguyen-sb commented Jul 18, 2023

Oh, I don't know why the test on arm_emulated is off by one.
Instead of checking the 1st KAT hash of 1st parameter, it compares output KAT with the 2nd KATs hash.

No it's not off by one. But somehow I don't know why the hash is incorrect.

@ducnguyen-sb
Copy link
Contributor Author

The reason the output hash is incorrect because the comparison with sigs_total and sigs_remaining.

In KAT file, when hash tree is at 2^40, it's overflow size_t type in 32-bit.
Change to uint64_t resolve the problem.

Next, scan_build give me errors in the reference code of XMSS.

Am I allowed to modify the reference code (as long as same KAT output) to fix the scan_build?
Anyway, all warnings are false positive in execution, all allocated memories are initialized and has data.

@baentsch can you recommend what should I do to clear CI?

@baentsch
Copy link
Member

Am I allowed to modify the reference code (as long as same KAT output) to fix the scan_build?

I'd personally say "Yes, of course" -- if that corrects code otherwise containing flaws. Now, on second consideration the question is this: How did you import this reference code? If it's a fully automated process, please consider doing something similar to what we already do in scripts with copy_from_upstream and copy_from_xkcp: In both cases there's the concept of "copy-then-patch". In this case, the patch of course should contain the changes to fix "scan_build" (and you may want to consider contributing those changes upstream such as to eventually completely get rid of them here -- and improve the reference code). If you did the import manually, well, please consider automation: It'll save all of us a lot of problems in the future (that upstream changes or we harden our own tests).

@ducnguyen-sb
Copy link
Contributor Author

How did you import this reference code?

Unfortunately, I import this code manually. The original reference does not:

  1. Separate message and signature
  2. Type confusion (unsigned long)

And it was not updated for years, due to this I think automation from upstream is a bit overkill. I think my code is a little far ahead of reference implementation.

I will look into the code to fix scan_build.

@baentsch
Copy link
Member

I think my code is a little far ahead of reference implementation

Good: That then IMO gives you a clear answer to

Am I allowed to modify the reference code

Yes -- by all means: Make this code base the new (better) code base of reference.

@ducnguyen-sb
Copy link
Contributor Author

Scan build is happy. This branch is ready to be merged.

Copy link
Member

@baentsch baentsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to merge to "stateful-sigs". Thanks for the latest code enhancements, @ducnguyen-sb ! For a "main" branch merge, I'm personally missing quite a bit of documentation -- but that's arguably another separate task/PR.

@ducnguyen-sb ducnguyen-sb merged commit fd206ae into stateful-sigs Jul 24, 2023
@ducnguyen-sb ducnguyen-sb deleted the ducnguyen-sb/xmss/add_two_parameters branch July 24, 2023 02:10
dstebila pushed a commit that referenced this pull request Aug 18, 2023
* populate all 28 XMSS parameters

* clean up

* remove wanrings in scanbuild

* change free to OQS_MEM_insecure_free

* fix build warning

* fix integer in i386 platforms

* proper type for sigs_remain and sig_maximum

* remove size_t in signature remain and total

* make scan-build happy
SWilson4 pushed a commit that referenced this pull request Dec 15, 2023
* populate all 28 XMSS parameters

* clean up

* remove wanrings in scanbuild

* change free to OQS_MEM_insecure_free

* fix build warning

* fix integer in i386 platforms

* proper type for sigs_remain and sig_maximum

* remove size_t in signature remain and total

* make scan-build happy
SWilson4 pushed a commit that referenced this pull request Feb 14, 2024
* populate all 28 XMSS parameters

* clean up

* remove wanrings in scanbuild

* change free to OQS_MEM_insecure_free

* fix build warning

* fix integer in i386 platforms

* proper type for sigs_remain and sig_maximum

* remove size_t in signature remain and total

* make scan-build happy
cothan pushed a commit that referenced this pull request Apr 2, 2024
* populate all 28 XMSS parameters

* clean up

* remove wanrings in scanbuild

* change free to OQS_MEM_insecure_free

* fix build warning

* fix integer in i386 platforms

* proper type for sigs_remain and sig_maximum

* remove size_t in signature remain and total

* make scan-build happy
SWilson4 pushed a commit that referenced this pull request Apr 12, 2024
* populate all 28 XMSS parameters

* clean up

* remove wanrings in scanbuild

* change free to OQS_MEM_insecure_free

* fix build warning

* fix integer in i386 platforms

* proper type for sigs_remain and sig_maximum

* remove size_t in signature remain and total

* make scan-build happy
SWilson4 pushed a commit that referenced this pull request May 14, 2024
* populate all 28 XMSS parameters

* clean up

* remove wanrings in scanbuild

* change free to OQS_MEM_insecure_free

* fix build warning

* fix integer in i386 platforms

* proper type for sigs_remain and sig_maximum

* remove size_t in signature remain and total

* make scan-build happy
cothan added a commit that referenced this pull request May 30, 2024
commit 244288f Add XMSS parameter xmss_sha256_h10 (#1482)
commit a7e26d9 Add 12 XMSS and 16 XMSSMT parameters. (#1489)
commit 4694fc3 Add secret key object to XMSS (#1530)
commit 99067be Add XMSS Serialize/Deserialize  (#1542)
commit 2dbfc40 Update XMSS secret key object APIs, sync with LMS  (#1588)
commit 47740ad Enforce idx from unsigned int to uint32_t. (#1611)
commit 9610576 Fix windows-x86 and arm compiling error. (#1634)
commit bb658b7 Address  stateful-sigs comments in #1650 (#1656)
commit 7db8ddf Update `sig_stfl.h` document for #1650 (#1655)
commit c3e5750 Add Apache 2.0 and MIT License to XMSS (#1662)
commit e1f02b2 Change XMSS License from `(Apache 2.0 AND MIT)` to `(Apache 2.0 OR MIT) AND CC0-1.0` (#1697)
commit 17c12c3 Add return status for XMSS lock/unlock functions. (#1712)
commit 1941636 Add return check for lock/unlock function (#1727)
commit b45415c Use `abort()` instead of exit to get the trace log. (#1728)
commit ba63672 Reduce number of `malloc/free` call in `XMSS/external` (#1724)

Signed-off-by: Duc Tri Nguyen <dnguye69@gmu.edu>
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.

3 participants