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

Test on Windows and fix CMakeList #25

Closed
wants to merge 1 commit into from

Conversation

thomwiggers
Copy link
Contributor

@thomwiggers thomwiggers commented Jul 27, 2020

Uses the CMake build files to test on Windows and fixes some small issues with the CMakeList.txts.

@@ -0,0 +1 @@
SHA256SUMS eol=lf
Copy link
Contributor Author

Choose a reason for hiding this comment

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

otherwise sha256sum chokes on Windows, as it is checked out with eol=input.

@thomwiggers
Copy link
Contributor Author

Weirdly enough, on my branch this passed https://travis-ci.com/github/thomwiggers/kyber-clean/builds/177924662

@thomwiggers thomwiggers changed the title Test on Windows Test on Windows and fix CMakeList Aug 17, 2020
@cryptojedi cryptojedi deleted the branch pq-crystals:master May 7, 2023 08:35
@cryptojedi cryptojedi closed this May 7, 2023
@newTomas
Copy link

newTomas commented Jul 18, 2023

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?

@cryptojedi
Copy link
Contributor

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

@newTomas
Copy link

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:

  1. clone repo into F:\kyber
  2. create folder build in F:\kyber
  3. open powershell and cd F:\kyber\build
  4. cmake --build . -- /property:Configuration=Release
    image
  5. cmake --build . -- /property:Configuration=Release
    image
  6. ctest --output-on-failure -C Release
    image
    image
  7. Create source.cpp in F:\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);
}
  1. run x64 Native Tools Command Prompt for VS 2022
  2. go to F:\kyber_test
  3. cl source.cpp /IF:\kyber\ref /link F:\kyber\build\ref\Release\kyber512_ref.lib
    image
**********************************************************************
** 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:
image
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

@newTomas
Copy link

With PQClean I also get unresolved external symbol. Help please.

@baentsch
Copy link
Contributor

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).

@baentsch
Copy link
Contributor

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?

@thomwiggers
Copy link
Contributor Author

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.

@baentsch
Copy link
Contributor

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"

@thomwiggers
Copy link
Contributor Author

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 😉

@baentsch
Copy link
Contributor

ACK. PQClean/PQClean#492 seems like it would be fixing that.

@newTomas
Copy link

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?

@baentsch
Copy link
Contributor

It is safe?

What do you mean by this?

@newTomas
Copy link

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.

@thomwiggers thomwiggers deleted the travis-windows branch July 20, 2023 07:52
@thomwiggers
Copy link
Contributor Author

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

@baentsch
Copy link
Contributor

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 open-quantum-safe/liboqs#1466. Anyone reading: Please state interest in getting that issue resolved (sooner than later) to help liboqs priority setting.

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.

4 participants