kyber
kyber copied to clipboard
Test on Windows and fix CMakeList
Uses the CMake build files to test on Windows and fixes some small issues with the CMakeList.txt
s.
Weirdly enough, on my branch this passed https://travis-ci.com/github/thomwiggers/kyber-clean/builds/177924662
Can you please tell me how to import the library into the project?
The library itself compiles successfully with your commands from travis, but the vectors and debug fail the tests.
When compiling project, it gives me an error: a reference to an unresolved external symbol "int __cdecl pqcrystals_kyber768_ref_keypair(unsigned char *,unsigned char *)"
And the same errors for decapsulation and encapsulation.
Error in Russian, perhaps the translation is not accurate.
Compiled with command:
cl source.cpp /IF:\kyber\ref /link F:\kyber\build\ref\Release\kyber512_ref.lib
I also tried to import in visual studio
, there is the same error.
I also tried to build lib and import with other compilers (gcc
and clang
), all the same errors.
What am I doing wrong?
This looks like a linker error, how exactly are you trying to build your code.
For Windows I recommend using the implementation from PQClean [1], which has a
Makefile.Microsoft_nmake
.
[1] https://github.com/PQClean/PQClean
Windows 11 Pro 22H2 22621.1992 Visual Studio Community 2022 17.6.5 cl.exe version 19.36.32537 for x64 cmake version 3.27.0-rc4 All steps:
- clone repo into
F:\kyber
- create folder
build
inF:\kyber
- open powershell and cd
F:\kyber\build
-
cmake --build . -- /property:Configuration=Release
-
cmake --build . -- /property:Configuration=Release
-
ctest --output-on-failure -C Release
- Create
source.cpp
inF:\kyber-test
with content:
#include <kem.h>
int main()
{
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
uint8_t sk[CRYPTO_SECRETKEYBYTES];
uint8_t ct[CRYPTO_CIPHERTEXTBYTES];
uint8_t key[CRYPTO_BYTES];
crypto_kem_keypair(pk, sk);
crypto_kem_enc(ct, key, pk);
crypto_kem_dec(key, ct, sk);
}
- run
x64 Native Tools Command Prompt for VS 2022
- go to
F:\kyber_test
-
cl source.cpp /IF:\kyber\ref /link F:\kyber\build\ref\Release\kyber512_ref.lib
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.6.5
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
D:\Program Files\Microsoft Visual Studio\2022\Community>cd F:\kyber_test
D:\Program Files\Microsoft Visual Studio\2022\Community>F:
F:\kyber_test>cl source.cpp /IF:\kyber\ref /link F:\kyber\build\ref\Release\kyber512_ref.lib
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.36.32537 для x64
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.
source.cpp
Microsoft (R) Incremental Linker Version 14.36.32537.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:source.exe
F:\kyber\build\ref\Release\kyber512_ref.lib
source.obj
source.obj : error LNK2019: ссылка на неразрешенный внешний символ "int __cdecl pqcrystals_kyber768_ref_keypair(unsigned char *,unsigned char *)" (?pqcrystals_kyber768_ref_keypair@@YAHPEAE0@Z) в функции main.
source.obj : error LNK2019: ссылка на неразрешенный внешний символ "int __cdecl pqcrystals_kyber768_ref_enc(unsigned char *,unsigned char *,unsigned char const *)" (?pqcrystals_kyber768_ref_enc@@YAHPEAE0PEBE@Z) в функции main.
source.obj : error LNK2019: ссылка на неразрешенный внешний символ "int __cdecl pqcrystals_kyber768_ref_dec(unsigned char *,unsigned char const *,unsigned char const *)" (?pqcrystals_kyber768_ref_dec@@YAHPEAEPEBE1@Z) в функции main.
source.exe : fatal error LNK1120: неразрешенных внешних элементов: 3
F:\kyber_test>
If you add #define KYBER_K 2
to the top of source.cpp
you get this:
The lib file contains the necessary symbols.
dumpbin /symbols F:\kyber\build\ref\Release\kyber512_ref.lib > kyber512_ref_symbols.txt
kyber512_ref_symbols.txt
With PQClean I also get unresolved external symbol. Help please.
With PQClean I also get unresolved external symbol. Help please.
FWIW, even further downstream, I'd suggest taking a look at liboqs where there's Windows CI (passing).
For Windows I recommend using the implementation from PQClean
@cryptojedi Is there a reason the PQClean github workflows (containing Windows as I realize only now) are not displayed on the project README? Or is their status summarily shown somewhere else?
For Windows I recommend using the implementation from PQClean
@cryptojedi Is there a reason the PQClean github workflows (containing Windows as I realize only now) are not displayed on the project README? Or is their status summarily shown somewhere else?
We have a bajillion of them. https://github.com/PQClean/PQClean/blob/master/.github/workflows/BADGES.md
Not sure why they're failing right now though.
Thanks for the pointer.
Not sure why they're failing right now though.
The log seems pretty clear about that: "Prohibited use of preprocessor conditional"
Thanks for the pointer.
Not sure why they're failing right now though.
The log seems pretty clear about that: "Prohibited use of preprocessor conditional"
I meant I did not have time to look into it 😉
ACK. https://github.com/PQClean/PQClean/pull/492 seems like it would be fixing that.
ACK. PQClean/PQClean#492 seems like it would be fixing that.
No, this change had no effect. I switched to liboqs, everything works great. Just tell me, please, did the creators of kyber check this lib? It is safe?
It is safe?
What do you mean by this?
It is safe?
What do you mean by this?
Is the algorithm implemented correctly? Are there any vulnerabilities? I recently saw a lib in which key pair were not generated and the code from the example worked with empty keys. This lib had a lot of stars and no one paid attention to the obvious vulnerability. That's why I wanted to use the official implementation.
OQS uses the code from this repository; it extracts it via a set of scripts that are publicly available in the liboqs repository. I would expect any vulnerability in liboqs's Kyber to also be present here.
You might be interested in an implementation of Kyber that has actual proofs of correctness attached to it. See https://github.com/formosa-crypto/libjade and https://eprint.iacr.org/2023/215.pdf
I would expect any vulnerability in liboqs's Kyber to also be present here
Agreed. With one caveat: The ARM code in liboqs
doesn't come straight from this repo.
an implementation of Kyber that has actual proofs of correctness attached to it. See https://github.com/formosa-crypto/libjade and https://eprint.iacr.org/2023/215.pdf
Hence https://github.com/open-quantum-safe/liboqs/issues/1466. Anyone reading: Please state interest in getting that issue resolved (sooner than later) to help liboqs
priority setting.