-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9738c2a
Showing
411 changed files
with
25,174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = true | ||
|
||
[**.{cc,js}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test-native: | ||
runs-on: ${{matrix.os}} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest] | ||
node-version: [18.x, 20.x, 21.x] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Node.js ${{matrix.node-version}} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{matrix.node-version}} | ||
- name: Build | ||
run: npm install | ||
- name: Test | ||
run: npm test | ||
build-wasm: | ||
runs-on: ubuntu-latest | ||
env: | ||
NODE_VERSION: 18.x | ||
EMSDK_VERSION: 3.1.14 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Node.js ${{env.NODE_VERSION}} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{env.NODE_VERSION}} | ||
- name: Set up Emscripten SDK ${{env.EMSDK_VERSION}} | ||
uses: mymindstorm/setup-emsdk@v14 | ||
with: | ||
version: ${{env.EMSDK_VERSION}} | ||
- name: Install dependencies | ||
run: npm install --ignore-scripts | ||
- name: Build WebAssembly module | ||
run: npm run build-wasm | ||
- name: Upload build output | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: wasm-gen | ||
path: | | ||
wasm/mceliece.wasm | ||
wasm/mceliece_constants.js | ||
if-no-files-found: error | ||
test-wasm: | ||
needs: build-wasm | ||
runs-on: ${{matrix.os}} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest, windows-latest] | ||
node-version: [18.x, 20.x, 21.x] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Node.js ${{matrix.node-version}} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{matrix.node-version}} | ||
- name: Install dependencies | ||
run: npm install --ignore-scripts | ||
- name: Download WebAssembly module | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: wasm-gen | ||
path: wasm | ||
- name: Test | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
node_modules/ | ||
wasm/mceliece.wasm | ||
wasm/mceliece_constants.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# mceliece-nist | ||
|
||
This package provides Node.js bindings for the reference implementation that is | ||
part of the [NIST submission](https://classic.mceliece.org/nist.html) by | ||
Bernstein et al. | ||
|
||
This version is based on the round-4 submission `mceliece-20221023`. | ||
See [`deps/mceliece`](deps/mceliece). | ||
|
||
## Installation | ||
|
||
Installation should work as usual: | ||
|
||
```sh | ||
npm i mceliece-nist | ||
``` | ||
|
||
## Example | ||
|
||
```javascript | ||
const { McEliece } = require('mceliece-nist'); | ||
|
||
const kem = new McEliece('mceliece8192128'); | ||
const { publicKey, privateKey } = kem.keypair(); | ||
|
||
const { key, encryptedKey } = kem.generateKey(publicKey); | ||
console.log(`Bob is using the key ${key.toString('hex')}`); | ||
|
||
const receivedKey = kem.decryptKey(privateKey, encryptedKey); | ||
console.log(`Alice is using the key ${receivedKey.toString('hex')}`); | ||
``` | ||
|
||
## API | ||
|
||
The package exports a single class, `McEliece`. | ||
|
||
### Class `McEliece` | ||
|
||
#### `new McEliece(algorithm)` | ||
|
||
Creates a new instance using the specified algorithm. `algorithm` must be one of | ||
the values contained in `McEliece.supportedAlgorithms`. | ||
|
||
#### `McEliece.supportedAlgorithms` | ||
|
||
This static field is an array of all supported algorithms. | ||
|
||
#### `instance.keySize` | ||
|
||
The (maximum) key size in bytes that this instance can encapsulate. | ||
|
||
#### `instance.encryptedKeySize` | ||
|
||
The size of the encapsulated key in bytes. | ||
|
||
#### `instance.publicKeySize` | ||
|
||
The size of the public key in bytes. | ||
|
||
#### `instance.privateKeySize` | ||
|
||
The size of the private key in bytes. | ||
|
||
#### `instance.keypair([callback])` | ||
|
||
Creates and returns a new key pair `{ publicKey, privateKey }`. Both keys will | ||
be returned as `Buffer`s. | ||
|
||
If `callback` is a function, `keypair` immediately returns `undefined` and calls | ||
`callback(err, { publicKey, privateKey })` as soon as a new keypair has been | ||
generated. | ||
|
||
#### `instance.generateKey(publicKey)` | ||
|
||
Generates a new symmetric key and encrypts it using the given `publicKey`. | ||
Returns `{ key, encryptedKey }`, both objects will be `Buffer`s. | ||
|
||
#### `instance.decryptKey(privateKey, encryptedKey[, callback])` | ||
|
||
Decrypts the `encryptedKey` that was returned by | ||
`instance.generateKey(publicKey)` and returns the decrypted key as a `Buffer`. | ||
|
||
If `callback` is a function, `decryptKey` immediately returns `undefined` and | ||
calls `callback(err, key)` as soon as the key has been decrypted. | ||
|
||
## License | ||
|
||
This project is distributed under the ISC license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "node_mceliece", | ||
"sources": ["node_mceliece.cc"], | ||
"include_dirs": [ | ||
"<!@(node -p \"require('node-addon-api').include\")", | ||
"<(module_root_dir)/deps/mceliece" | ||
], | ||
"dependencies": [ | ||
"<!(node -p \"require('node-addon-api').gyp\")", | ||
"<(module_root_dir)/deps/mceliece/binding.gyp:mceliece" | ||
], | ||
"defines": [ | ||
"NAPI_DISABLE_CPP_EXCEPTIONS", | ||
"NODE_ADDON_API_DISABLE_DEPRECATED" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.o | ||
mceliece.a | ||
*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Reference implementation of Classic McEliece | ||
|
||
The `kem` directory contains the reference implementation of the Classic | ||
McEliece KEM that was provided by Bernstein et al. as part of the | ||
[Classic McEliece NIST submission](https://classic.mceliece.org/nist.html). | ||
|
||
- Source: Round-4 submission package | ||
- Revision: `mceliece-20221023` | ||
- File: [`mceliece-20221023.tar.gz`](https://classic.mceliece.org/nist/mceliece-20221023.tar.gz) | ||
- `37bc7bddf9b061cb52992afe27f40f82` (md5) | ||
- `e939e24b0f840a1a78c474575b846c50986d4651` (sha1) | ||
- `sha256: 0428f1c9aeb3472ab580f21693d7fa26ccc92f29beee40a78cc88dab79dfb7a3` (sha256) | ||
|
||
## Automatically applied patches | ||
|
||
The `extract-kem-from-nist-submission` script was used to generate the contents | ||
of the `kem` directory as well as the header file `mceliece.h` and the file | ||
`binding.gyp`. | ||
|
||
The contents of the `kem` directory correspond to the contents of the | ||
`Reference_Implementation/kem` directory that is part of the submission package. | ||
However, the `extract-kem-from-nist-submission` script applies the following | ||
patches. | ||
|
||
- The reference implementation uses libkeccak to implement SHAKE256. However, | ||
because Node.js uses OpenSSL by default, references to libkeccak header files | ||
are replaced with references to [`mceliece_externals.h`](mceliece_externals.h) | ||
that defines a compatible interface. The implementation of the interface | ||
uses OpenSSL. | ||
- The reference implementation uses a random number generator that is based on | ||
AES256-CTR. Instead, we patch the implementation to use the random number | ||
generator provided by OpenSSL via | ||
[`mceliece_externals.h`](mceliece_externals.h). | ||
- Files that are not required for providing bindings for the reference | ||
implementation are removed (e.g., `KATNUM`). |
Oops, something went wrong.