Skip to content

Commit 97353bc

Browse files
AdijeShenSWilson4johngray-dev
authored
Enable Build On Windows (#28)
* [build] use .a of liboqs Signed-off-by: Adije Shen <[email protected]> * [3rd] add link to liboqs Signed-off-by: Adije Shen <[email protected]> * mv liboqs as a submodule Signed-off-by: Adije Shen <[email protected]> * [doc] update the doc Signed-off-by: Adije Shen <[email protected]> * unify windows and unix operation Signed-off-by: Adije Shen <[email protected]> * add guide for windows Signed-off-by: Adije Shen <[email protected]> * Update README.md Signed-off-by: Huajie Shen <[email protected]> Signed-off-by: Adije Shen <[email protected]> * keep the origin README file format Signed-off-by: Adije Shen <[email protected]> * Update README Signed-off-by: Adije Shen <[email protected]> * Add RELEASE.md Signed-off-by: Huajie Shen <[email protected]> Signed-off-by: Adije Shen <[email protected]> * delete gitmodules Signed-off-by: Adije Shen <[email protected]> * Move CI to GitHub Actions (#30) * Port workflows from CircleCI to GitHub Actions * Add CI job for workflow linting * Update README badge --------- Signed-off-by: Spencer Wilson <[email protected]> Signed-off-by: Adije Shen <[email protected]> * Add support for the ML-DSA Context (#31) Signed-off-by: John Gray <[email protected]> Signed-off-by: Adije Shen <[email protected]> * Update README, examples, and CI before 0.2.0 release (#32) * Update to latest CI image Signed-off-by: Spencer Wilson <[email protected]> * Install jdk package and set JAVA_HOME Signed-off-by: Spencer Wilson <[email protected]> * Add macOS job Signed-off-by: Spencer Wilson <[email protected]> * Update README.md and example files Signed-off-by: Spencer Wilson <[email protected]> * Remove unnecessary install Signed-off-by: Spencer Wilson <[email protected]> --------- Signed-off-by: Spencer Wilson <[email protected]> * Support derandomized key generation for ML-KEM (#33) * Support derandomized key generation for ML-KEM Signed-off-by: Spencer Wilson <[email protected]> * Update example output in README.md Signed-off-by: Spencer Wilson <[email protected]> --------- Signed-off-by: Spencer Wilson <[email protected]> Signed-off-by: Adije Shen <[email protected]> * add back the windows installation guide Signed-off-by: Adije Shen <[email protected]> * merge Signed-off-by: adijeshen <[email protected]> * add windows CI Signed-off-by: adijeshen <[email protected]> * change CI Signed-off-by: root <root@adijethinkbook.> Signed-off-by: Adije Shen <[email protected]> * Update README.md Signed-off-by: Spencer Wilson <[email protected]> --------- Signed-off-by: Adije Shen <[email protected]> Signed-off-by: Huajie Shen <[email protected]> Signed-off-by: Spencer Wilson <[email protected]> Signed-off-by: John Gray <[email protected]> Signed-off-by: adijeshen <[email protected]> Signed-off-by: root <root@adijethinkbook.> Co-authored-by: Spencer Wilson <[email protected]> Co-authored-by: John Gray <[email protected]>
1 parent bf37d5f commit 97353bc

File tree

4 files changed

+289
-34
lines changed

4 files changed

+289
-34
lines changed

.github/workflows/java.yml

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
path: liboqs
3434
ref: main
3535
- name: Build liboqs
36-
run: mkdir build && cd build && cmake .. -G"Ninja" -DBUILD_SHARED_LIBS=ON -DOQS_BUILD_ONLY_LIB=ON && ninja install
36+
run: mkdir build && cd build && cmake .. -G"Ninja" -DOQS_BUILD_ONLY_LIB=ON && ninja install
3737
working-directory: liboqs
3838
- name: Resolve all maven project dependencies
3939
run: mvn dependency:go-offline
@@ -62,17 +62,78 @@ jobs:
6262
path: liboqs
6363
ref: main
6464
- name: Install liboqs dependencies
65-
run: env HOMEBREW_NO_AUTO_UPDATE=1 brew install ninja && pip3 install --require-hashes --break-system-packages -r .github/workflows/requirements.txt
66-
working-directory: liboqs
65+
run: |
66+
env HOMEBREW_NO_AUTO_UPDATE=1 brew install ninja openssl@3
67+
echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
68+
export LDFLAGS="-L$(brew --prefix openssl@3)/lib"
69+
echo "LDFLAGS=$LDFLAGS"
6770
- name: Build liboqs
68-
run: mkdir build && cd build && cmake .. -G"Ninja" -DBUILD_SHARED_LIBS=ON -DOQS_BUILD_ONLY_LIB=ON && sudo ninja install
71+
run: mkdir build && cd build && cmake .. -G"Ninja" -DOQS_BUILD_ONLY_LIB=ON && sudo ninja install
6972
working-directory: liboqs
7073
- name: Resolve all maven project dependencies
7174
run: mvn dependency:go-offline
7275
- name: Build liboqs-java and run tests
73-
run: export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib" && mvn -P macosx package
76+
run: |
77+
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib"
78+
export OPENSSL_PATH=$(brew --prefix openssl@3)/lib
79+
mvn -P macosx "-Dlinker.end.option=/usr/local/lib/liboqs.a -L$OPENSSL_PATH -lcrypto" package
7480
- name: Compile KEM, Signatures and Rand examples
7581
run: |
7682
javac -cp target/liboqs-java.jar examples/KEMExample.java &&
7783
javac -cp target/liboqs-java.jar examples/SigExample.java &&
7884
javac -cp target/liboqs-java.jar examples/RandExample.java
85+
86+
windows:
87+
needs: workflowcheck
88+
runs-on: windows-latest
89+
steps:
90+
- name: Checkout liboqs-java
91+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
92+
93+
- name: Install MSYS2
94+
uses: msys2/setup-msys2@v2
95+
with:
96+
update: true
97+
install: >-
98+
mingw-w64-x86_64-gcc
99+
mingw-w64-x86_64-ninja
100+
mingw-w64-x86_64-cmake
101+
make
102+
103+
- name: Set up JDK
104+
uses: actions/setup-java@v4
105+
with:
106+
distribution: 'temurin'
107+
java-version: '8'
108+
cache: 'maven'
109+
110+
- name: Checkout liboqs main
111+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
112+
with:
113+
repository: open-quantum-safe/liboqs
114+
path: liboqs
115+
ref: main
116+
117+
- name: Build liboqs (static library)
118+
shell: msys2 {0}
119+
run: |
120+
cd liboqs
121+
mkdir build
122+
cd build
123+
cmake .. -G "Ninja" -DOQS_BUILD_ONLY_LIB=ON -DBUILD_SHARED_LIBS=OFF
124+
ninja
125+
126+
- name: Resolve Maven dependencies
127+
run: mvn dependency:go-offline
128+
129+
- name: Build liboqs-java and run tests
130+
run: |
131+
$env:Path += ";$env:GITHUB_WORKSPACE\liboqs\build\lib"
132+
$includeDir = "$env:GITHUB_WORKSPACE\liboqs\build\include"
133+
$libDir = "$env:GITHUB_WORKSPACE\liboqs\build\lib"
134+
mvn -Pwindows "-Dliboqs.include.dir=$includeDir" "-Dliboqs.lib.dir=$libDir" package
135+
- name: Compile KEM, Signatures and Rand examples
136+
run: |
137+
javac -cp target\liboqs-java.jar examples\KEMExample.java
138+
javac -cp target\liboqs-java.jar examples\SigExample.java
139+
javac -cp target\liboqs-java.jar examples\RandExample.java

README.md

Lines changed: 116 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,117 @@ To build `liboqs-java` first download or clone this java wrapper into a `liboqs-
6767
git clone -b master https://github.com/open-quantum-safe/liboqs-java.git
6868
```
6969

70-
### Building the OQS dependency
70+
### Windows Build
71+
72+
#### Prerequisites
73+
74+
- MinGW-w64 GCC (version 11.5.0 or later)
75+
- CMake
76+
- JDK 1.8
77+
- Maven 3.8.8
78+
- Git
79+
80+
#### Installation Steps
81+
82+
1. Install MinGW-w64 GCC:
83+
- Download from [WinLibs](https://winlibs.com/#download-release)
84+
- Extract the ZIP file to a directory without spaces
85+
- Add the bin directory to PATH environment variable (e.g., `E:\develop\mingw64\bin`)
86+
- Via Control Panel → System → System Info → Advanced System Settings → Advanced → Environment Variables → PATH
87+
- Or via command line: `setx PATH "E:\develop\mingw64\bin;%PATH%"` (not recommended)
88+
89+
2. Install CMake:
90+
- Either via winget: `winget install cmake`
91+
- Or download from [cmake.org](https://cmake.org/download/)
92+
- Ensure CMake is added to PATH
93+
94+
3. Verify installations (by open cmd and type):
95+
```bash
96+
gcc --version
97+
cmake --version
98+
```
99+
100+
4. Build liboqs:
101+
```bash
102+
git clone https://github.com/open-quantum-safe/liboqs/
103+
cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DBUILD_SHARED_LIBS=OFF -S . -B build
104+
cmake --build build -j4
105+
cd ..
106+
```
71107

72-
#### Linux/MacOS
73-
First, you must build the `main` branch of [liboqs](https://github.com/open-quantum-safe/liboqs/) according to the liboqs building instructions with shared library support enabled (add `-DBUILD_SHARED_LIBS=ON` to the `cmake` command), followed (optionally) by a `sudo ninja install` to ensure that the compiled library is visible system-wide (by default it installs under `/usr/local/include` and `/usr/local/lib` on Linux/macOS).
108+
5. Install Java dependencies:
109+
- Install JDK 1.8 from [OpenLogic](https://www.openlogic.com/openjdk-downloads)
110+
- Install Maven 3.8.8 from [Maven](https://maven.apache.org/)
111+
- Add both to PATH environment variables
112+
- Verify Java installations:
113+
```bash
114+
java -version
115+
mvn -version
116+
```
74117

118+
If you clone the liboqs under `liboqs-java` directory, then you can run the following command to build the package:
119+
```bash
120+
mvn package -P windows
75121
```
76-
git clone -b main https://github.com/open-quantum-safe/liboqs.git
77-
cd liboqs
78-
mkdir build && cd build
79-
cmake -GNinja -DBUILD_SHARED_LIBS=ON ..
80-
ninja
81-
sudo ninja install
122+
123+
Or else, you should run
124+
```bash
125+
mvn package -P windows -Dliboqs.include.dir="<path-to-save-liboqs>\liboqs\build\include" -Dliboqs.lib.dir="<path-to-save-liboqs>\liboqs\build\lib"
126+
```
127+
128+
### Linux/MacOS
129+
130+
#### Prerequisites
131+
- JDK 1.8
132+
- GCC
133+
- CMake
134+
- ninja-build
135+
- Maven
136+
- OpenSSL
137+
138+
#### Build Instructions
139+
140+
First, you must build the `main` branch of [liboqs](https://github.com/open-quantum-safe/liboqs/) according to the liboqs building instructions with static library, followed (optionally) by a `sudo cmake --install build` to ensure that the compiled library is visible system-wide (by default it installs under `/usr/local/include` and `/usr/local/lib` on Linux/macOS).
141+
142+
1. Build the liboqs C library to generate liboqs.a
143+
```bash
144+
cd <path-to-save-liboqs>
145+
git clone https://github.com/open-quantum-safe/liboqs/
146+
cmake -S . -B build
147+
cmake --build build -j4
148+
#optional
149+
sudo cmake --install build
150+
cd ..
82151
```
83152

153+
This step will generate the `liboqs/build/liboqs.a` file.
84154

85155
### Building the Java OQS wrapper
86156

87-
To build the `liboqs-java` wrapper type for different operating systems add the `-P <OS>` flag, where `<OS> = {linux, macosx}`.
157+
To build the `liboqs-java` wrapper type for different operating systems add the `-P <OS>` flag, where `<OS> = {linux, macosx, windows}`.
88158

89159
For instance, to build `liboqs-java` for MacOS, type:
90160
```
91161
mvn package -P macosx -Dliboqs.include.dir="/usr/local/include" -Dliboqs.lib.dir="/usr/local/lib"
92162
```
93163
The above command will compile the C and Java files and also run the unit tests.
94164

165+
For those who doen't want the `liboqs` library to install system wide. You **have to** change `<liboqs.include.dir>` to `<path-to-save-liboqs>/liboqs/build/include` to and `<liboqs.lib.dir>` to `<path-to-save-liboqs>/liboqs/build/lib`
166+
```
167+
mvn package -P macosx -Dliboqs.include.dir="<path-to-save-liboqs>/liboqs/build/include" -Dliboqs.lib.dir="<path-to-save-liboqs>/liboqs/build/lib"
168+
```
169+
95170
To build without running the default unit tests you can use the `-Dmaven.test.skip=true` command line option as follows:
96171
```
97172
mvn package -P macosx -Dliboqs.include.dir="/usr/local/include" -Dliboqs.lib.dir="/usr/local/lib" -Dmaven.test.skip=true
98173
```
99174

100175
The default profile for building is `linux`, so when building on Linux the `-P <OS>` command line option may be omitted.
101176

102-
You may also omit the `-Dliboqs.include.dir` and `-Dliboqs.lib.dir` options in case you installed liboqs in `/usr/local` (true if you ran `sudo ninja install` after building liboqs).
177+
You may also omit the `-Dliboqs.include.dir` and `-Dliboqs.lib.dir` options in case you installed liboqs in `/usr/local` (true if you ran `sudo cmake --install build` after building liboqs).
103178

104179
Both the above commands will create a `target` directory with the build files, as well as a `src/main/resources` directory that will contain the `liboqs-jni.so` native library. Finally, a `liboqs-java.jar` will be created inside the `target` directory that will contain all the class files as well as the `liboqs-jni.so` native library.
105180

106-
107181
### Building and running the examples
108182

109183
The examples include:
@@ -121,11 +195,19 @@ The examples include:
121195
* OpenSSL
122196
* System (default)
123197

124-
#### Linux/MacOS
125-
126-
##### 1) Key Encapsulation example
198+
#### 1) Key Encapsulation example
127199

128200
To compile and run the KEM example, type:
201+
202+
##### Windows
203+
204+
```
205+
$ javac -cp target/liboqs-java.jar examples\KEMExample.java
206+
$ java -cp "target\liboqs-java.jar;examples\" KEMExample
207+
```
208+
209+
##### Linux/MacOS
210+
129211
```
130212
javac -cp target/liboqs-java.jar examples/KEMExample.java
131213
java -cp target/liboqs-java.jar:examples/ KEMExample
@@ -165,7 +247,16 @@ Server shared secret:
165247
Shared secrets coincide? true
166248
```
167249

168-
##### 2) Signatures example
250+
#### 2) Signatures example
251+
252+
##### Windows
253+
254+
```
255+
$ javac -cp target/liboqs-java.jar examples/SigExample.java
256+
$ java -cp "target/liboqs-java.jar;examples\" SigExample
257+
```
258+
259+
##### Linux/MacOS
169260

170261
```
171262
javac -cp target/liboqs-java.jar examples/SigExample.java
@@ -201,8 +292,16 @@ C0 41 9D 4D A9 B1 5F 4C ... 00 00 00 00 0A 20 2E 41
201292
Valid signature? true
202293
```
203294

204-
##### 3) Rand example
295+
#### 3) Rand example
296+
297+
##### Windows
298+
299+
```
300+
$ javac -cp target/liboqs-java.jar examples\RandExample.java
301+
$ java -cp "target/liboqs-java.jar;examples\" RandExample
302+
```
205303

304+
##### Linux/MacOS
206305
```
207306
javac -cp target/liboqs-java.jar examples/RandExample.java
208307
java -cp target/liboqs-java.jar:examples/ RandExample

examples/KEMExample.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.openquantumsafe.*;
22
import java.util.ArrayList;
33
import java.util.Arrays;
4+
import java.util.Base64;
45

56
public class KEMExample {
67

@@ -38,6 +39,19 @@ public static void main(String[] args) {
3839
byte[] shared_secret_client = client.decap_secret(ciphertext);
3940
System.out.println("It took " + (System.currentTimeMillis() - t) + " millisecs to decapsulate the secret.");
4041

42+
byte[] secret_key = client.export_secret_key();
43+
System.out.println("\nSecret key (Base64):");
44+
System.out.println(Base64.getEncoder().encodeToString(secret_key));
45+
46+
System.out.println("\nShared secrets coincide? " + Arrays.equals(shared_secret_client, shared_secret_server));
47+
48+
System.out.println("\nShared secrets (Base64):");
49+
System.out.println(Base64.getEncoder().encodeToString(shared_secret_server));
50+
System.out.println("\nPublic key (Base64):");
51+
System.out.println(Base64.getEncoder().encodeToString(client_public_key));
52+
System.out.println("\nCiphertext (Base64):");
53+
System.out.println(Base64.getEncoder().encodeToString(ciphertext));
54+
4155
client.dispose_KEM();
4256
server.dispose_KEM();
4357

0 commit comments

Comments
 (0)