Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
BeechatNetworkSystemsLtd committed Apr 25, 2021
1 parent 17e13c9 commit cb8764d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JNI-PQC
# kyber-JNI

This repository contains the reference implementation of the [Kyber](https://www.pq-crystals.org/kyber/) key encapsulation mechanism, Post Quantum Cryptography algorithms usable through Java Native Interface wrappers.

Expand Down
2 changes: 1 addition & 1 deletion jni/ref/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ find_package(Java COMPONENTS Development)

if(MSVC)
add_compile_options(/nologo /O2 /W4 /wd4146 /wd4244)
add_compile_options(/I${_JAVA_HOME}\include /I${_JAVA_HOME}\include\linux)
add_compile_options(/I${_JAVA_HOME}\include /I${_JAVA_HOME}\include\win32)
else()
add_compile_options(-I${_JAVA_HOME}/include -I${_JAVA_HOME}/include/linux)
add_compile_options(-Wall -fPIC -Wextra -Wpedantic -Werror)
Expand Down
50 changes: 47 additions & 3 deletions test/network/beechat/Main.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package network.beechat;

import java.io.*;
import java.util.Scanner;
import java.nio.charset.StandardCharsets;

public class Main {

public static void main(String[] args) {
public static void main(String[] args) throws FileNotFoundException {
Base58 b58 = new Base58();
byte[] alice_pk = new byte[Kyber512.KYBER_PUBLICKEYBYTES];
byte[] alice_sk = new byte[Kyber512.KYBER_SECRETKEYBYTES];
Expand All @@ -20,16 +22,37 @@ public static void main(String[] args) {

String testOutput = new String(b58.encode(alice_pk));
System.out.println("Alice's public key:\n" + testOutput);
try (FileWriter writer = new FileWriter("alice.public", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}
testOutput = new String(b58.encode(alice_sk));
System.out.println("\nAlice's secret key:\n" + testOutput);
try (FileWriter writer = new FileWriter("alice.secret", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}

testOutput = new String(b58.encode(bob_pk));
System.out.println("\nBob's public key:\n" + testOutput);
try (FileWriter writer = new FileWriter("bob.public", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}
testOutput = new String(b58.encode(bob_sk));
System.out.println("\nBob's secret key:\n" + testOutput);
try (FileWriter writer = new FileWriter("bob.secret", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}

// Step 2:
Kyber512.crypto_kem_enc(ct, bob_skey, alice_pk);
Scanner sc = new Scanner(new File("alice.public"));
Kyber512.crypto_kem_enc(ct, bob_skey, b58.decode(sc.nextLine()));
// Step 3:
Kyber512.crypto_kem_dec(alice_skey, ct, alice_sk);

Expand All @@ -52,16 +75,37 @@ public static void main(String[] args) {

testOutput = new String(b58.encode(alice_pk));
System.out.println("Alice's public key:\n" + testOutput);
try (FileWriter writer = new FileWriter("alice.public", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}
testOutput = new String(b58.encode(alice_sk));
System.out.println("\nAlice's secret key:\n" + testOutput);
try (FileWriter writer = new FileWriter("alice.secret", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}

testOutput = new String(b58.encode(bob_pk));
System.out.println("\nBob's public key:\n" + testOutput);
try (FileWriter writer = new FileWriter("bob.public", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}
testOutput = new String(b58.encode(bob_sk));
System.out.println("\nBob's secret key:\n" + testOutput);
try (FileWriter writer = new FileWriter("bob.secret", false)) {
writer.write(testOutput);
writer.flush();
writer.close();
} catch (IOException ex){}

// Step 2:
Kyber512_90s.crypto_kem_enc(ct, bob_skey, alice_pk);
sc = new Scanner(new File("alice.public"));
Kyber512_90s.crypto_kem_enc(ct, bob_skey, b58.decode(sc.nextLine()));
// Step 3:
Kyber512_90s.crypto_kem_dec(alice_skey, ct, alice_sk);

Expand Down

0 comments on commit cb8764d

Please sign in to comment.