Skip to content

Commit

Permalink
chore: trigger CI for 8724374
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen committed Feb 1, 2024
0 parents commit a3307ac
Show file tree
Hide file tree
Showing 411 changed files with 25,174 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[**.{cc,js}]
indent_style = space
indent_size = 2
77 changes: 77 additions & 0 deletions .github/workflows/ci.yml
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: 20.x
EMSDK_VERSION: 3.1.53
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
node_modules/
wasm/mceliece.wasm
wasm/mceliece_constants.js
88 changes: 88 additions & 0 deletions README.md
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.
20 changes: 20 additions & 0 deletions binding.gyp
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"
]
}
]
}
3 changes: 3 additions & 0 deletions deps/mceliece/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
mceliece.a
*.tar.gz
35 changes: 35 additions & 0 deletions deps/mceliece/README.md
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`).
Loading

0 comments on commit a3307ac

Please sign in to comment.