Coder Social home page Coder Social logo

dajiaji / hpke-js Goto Github PK

View Code? Open in Web Editor NEW
52.0 1.0 9.0 10.61 MB

A Hybrid Public Key Encryption (HPKE) module built on top of Web Cryptography API.

Home Page: https://dajiaji.github.io/hpke-js/docs

License: MIT License

JavaScript 3.42% TypeScript 93.13% HTML 3.45%
hpke rfc9180 encryption security webcrypto aead kdf kem kyber post-quantum

hpke-js's People

Contributors

dajiaji avatar dependabot[bot] avatar jiep avatar or13 avatar snorp avatar zhiyi-zhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hpke-js's Issues

Question about the JS module size

We have been using hpke-js in our library. We found the hpke-js library is big in size.
Do you have some numbers for the size of the JS module?

image

suite.kemContext is not a function

I am trying to export/serialize the public key with the following code:

import { Aes256Gcm, CipherSuite, HkdfSha512 } from "@hpke/core";
import { DhkemX448HkdfSha512 } from "@hpke/dhkem-x448";


async function doHpke() {
  const suite = new CipherSuite({
    kem: new DhkemX448HkdfSha512(),
    kdf: new HkdfSha512(),
    aead: new Aes256Gcm(),
  });
  const kemContext = await suite.kemContext();

  // A recipient generates a key pair.
  const rkp = await suite.kem.generateKeyPair();

  const rawPubKey = await kemContext.serializePublicKey(rkp.publicKey);

  console.log(rawPubKey)

  // A sender encrypts a message with the recipient public key.
  const sender = await suite.createSenderContext({
    recipientPublicKey: rkp.publicKey,
  });

  const ct = await sender.seal(new TextEncoder().encode("Hello world!"));

I get the following error:
TypeError: suite.kemContext is not a function

Is there something I've overlooked?

Thank you

IANA codepoint for DHKEM-over-secp256k1

Hi folks! Thanks for a really useful implementation.

I recently wrote a brief specification for HPKE using DHKEM over secp256k1, for which IANA has allocated the codepoint 0x0016. (I am sorry to report that the code point 0x0013 used in this project's experimental implementation was already allocated to a different DHKEM variant, as you can see from the link above.)

It would be great if this project could update its experimental DHKEM-over-secp256k1 implementation to use this codepoint! I'm happy to submit a pull request---please let me know if/how I can be helpful.

Support public key encoding and decoding at the suite

It's sometimes necessary to encode and decode KEM public keys for transmission over the wire. There seems to be an API for doing this on the KemInterface, but I don't see an obvious way to invoke that. If it's not already done, would it make sense to expose these APIs for use?

NotSupportedError: Web Cryptograph API not supported

This happens when you try to run the examples in the readme directly with jest.

I tried creating jest.config.js, but it did not resolve the issue.

with:

module.exports = {
  testEnvironment: 'node',
};

This is likely not a problem with your library, but rather with how jest handles node modules / es modules by default.

  "dependencies": {
    "hpke-js": "^0.13.0"
  },
  "devDependencies": {
    "jest": "^29.1.2"
  }

Work around... don't use jest.

Plan for X25519 and Chacha20poly1305 implementation?

Great work so far on this implementation! What's your plan for X25519 KEM and Chacha20poly1305 encryption since support seems to be spotty in browser for these algorithms?

I'm looking to use this implementation to play around with Oblivious DNS over HTTPS, but the implementation I'm trying to interoperate with only supports the following crypto primitives (KEM: X25519HkdfSha256, KDF: HkdfSha256, AEAD: AesGcm128). Should I plan on these cryptographic primitives being limited to only certain JS environments or do you have an idea in mind of how to get them supported in every major environment (particularly concerned about browser env right now)?

Cannot find module './src/cipherSuite.js'

_sync:2 Uncaught Error: Cannot find module './src/cipherSuite.js'
    at webpackEmptyContext (_sync:2:10)
    at eval (mod.js:30:28)
    at eval (mod.js:17:17)
    at eval (mod.js:26:3)
    at ./node_modules/hpke-js/script/mod.js (main.js:372:1)
    at __webpack_require__ (main.js:726:42)
    at eval (app.js:40:17)
    at ./app.js (main.js:19:1)
    at __webpack_require__ (main.js:726:42)
    at eval (index.js:2:62)

This error occurs when bundling with web pack, a typescript application, that included hpke-js.

I created a PoC here: #301

Suggestions for Browser Extension Manifest V3

Anyone has used browserify with this hpke-js library for loading into a Chrome browser extension V3? @dajiaji
I'm running into a problem where I can't import {CipherSuite, KemId, KdfId, etc.} into a browser extension's background.js getting an error that the module does not provide an export named "CipherSuite, ..etc"

We are using bidirectional encryption support and cannot find way to re-implement it in v1.2.3

Previously hpke-js allows to create reverse direction context.
After v1.00, this feature is dropped.
However, so far (v1.2.3), there isn't a way to construct a new hpke context using exported key, nonce, etc.

Basically what want to do:

  1. derive new key, nonce, and exporter secret with SenderContext's exportersecret (this is doable via SenderContext.export
  2. construct a recipient context with the exported key and nonce.

The step 2 does not seem to be supported by V1.2.3

I am wondering if we can expose APIs from Ciphersuite to make this possible?
E.g., add a new function called constructRecipientContext(key, base_nonce, seq, exporter_secret) and its variant for SenderContext: constructSenderContext(key, base_nonce, seq, exporter_secret) to CiphersuiteNative

Support of curve secp256k1

I'd like to bring HPKE to web3 ecosystem. The curve secp256k1 is native on ethereum.

There's some existing js implementation of curve secp256k1 like secp256k1.
I believe that this curve is capable of KEM in HPKE.

I'm asking for your opinion of adding support of secp256k1. Then I can start to work and submit a pr to this repo.

Expose suite-specific KDF and AEAD interfaces

Some protocols that build on top of HPKE, such as Oblivious HTTP, use the KDF and AEAD interfaces associated with a HPKE suite for various things. In the specific case of OHTTP, the KDF and AEAD interfaces are used to encapsulate HTTP responses (pseudocode copied from the draft):

secret = context.Export("message/bhttp response", Nk)
response_nonce = random(max(Nn, Nk))
salt = concat(enc, response_nonce)
prk = Extract(salt, secret)
aead_key = Expand(prk, "key", Nk)
aead_nonce = Expand(prk, "nonce", Nn)
ct = Seal(aead_key, aead_nonce, "", response)
enc_response = concat(response_nonce, ct)

I don't see an obvious was to get access to these interfaces through the things that hpke-js exposes. One could certainly reimplement the KDF and AEAD interfaces on top of WebCrypto, but it seems a lot less error prone if this library allowed the caller to just use the already-implemented functions directly.

@dajiaji, what do you think about exposing these? For context, I'm trying to implement a Javascript version of OHTTP, and this is the last bit that's required.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.