pyhpke


Namepyhpke JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/dajiaji/pyhpke
SummaryA Python implementation of HPKE.
upload_time2024-11-22 23:23:41
maintainerNone
docs_urlNone
authorAjitomi Daisuke
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyHPKE - A Python implementation of HPKE

[![PyPI version](https://badge.fury.io/py/pyhpke.svg)](https://badge.fury.io/py/pyhpke)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyhpke)
[![Documentation Status](https://readthedocs.org/projects/pyhpke/badge/?version=latest)](https://pyhpke.readthedocs.io/en/latest/?badge=latest)
![Github CI](https://github.com/dajiaji/pyhpke/actions/workflows/ci.yml/badge.svg)
[![codecov](https://codecov.io/gh/dajiaji/pyhpke/branch/main/graph/badge.svg?token=QN8GXEYEP3)](https://codecov.io/gh/dajiaji/pyhpke)


PyHPKE is a [HPKE (Hybrid Public Key Encryption)](https://www.rfc-editor.org/rfc/rfc9180.html) implementation written in Python.

You can install PyHPKE with pip:

```sh
$ pip install pyhpke
```

And then, you can use it as follows:


```py
from pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey

# The sender side:
suite_s = CipherSuite.new(
    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM
)
pkr = KEMKey.from_jwk(  # from_pem is also available.
    {
        "kid": "01",
        "kty": "EC",
        "crv": "P-256",
        "x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
        "y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
    }
)
enc, sender = suite_s.create_sender_context(pkr)
ct = sender.seal(b"Hello world!")

# The recipient side:
suite_r = CipherSuite.new(
    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM
)
skr = KEMKey.from_jwk(
    {
        "kid": "01",
        "kty": "EC",
        "crv": "P-256",
        "x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
        "y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
        "d": "r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8",
    }
)
recipient = suite_r.create_recipient_context(enc, skr)
pt = recipient.open(ct)

assert pt == b"Hello world!"


# deriving a KEMKeyPair
keypair = suite_s.kem.derive_key_pair(b"some_ikm_bytes_used_for_key_derivation")
```

## Index

- [Installation](#installation)
- [Supported HPKE Modes and Cipher Suites](#supported-hpke-modes-and-cipher-suites)
- [Warnings and Restrictions](#warnings-and-restrictions)
- [Usage](#usage)
- [API Reference](#api-reference)
- [Test](#test)
- [Contributing](#contributing)

## Installation

You can install PyHPKE with pip:

```sh
$ pip install pyhpke
```

## Supported HPKE Modes and Cipher Suites

PyHPKE supports all of the HPKE modes and cipher suites defined in RFC9180 below.

- modes
    - ✅ Base
    - ✅ PSK
    - ✅ Auth
    - ✅ AuthPSK
- KEMs (Key Encapsulation Machanisms)
    - ✅ DHKEM (P-256, HKDF-SHA256)
    - ✅ DHKEM (P-384, HKDF-SHA384)
    - ✅ DHKEM (P-521, HKDF-SHA512)
    - ✅ DHKEM (X25519, HKDF-SHA256)
    - ✅ DHKEM (X448, HKDF-SHA512)
- KDFs (Key Derivation Functions)
    - ✅ HKDF-SHA256
    - ✅ HKDF-SHA384
    - ✅ HKDF-SHA512
- AEADs (Authenticated Encryption with Associated Data)
    - ✅ AES-128-GCM
    - ✅ AES-256-GCM
    - ✅ ChaCha20Poly1305
    - ✅ Export Only

## Warnings and Restrictions

Although this library has been passed all of the following official test vectors, it has not been formally audited.
- [RFC9180 official test vectors provided on github.com/cfrg/draft-irtf-cfrg-hpke](https://github.com/cfrg/draft-irtf-cfrg-hpke/blob/5f503c564da00b0687b3de75f1dfbdfc4079ad31/test-vectors.json)

## Usage

```py
from pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey

# The sender side:
suite_s = CipherSuite.new(
    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM
)
pkr = KEMKey.from_jwk(
    {
        "kid": "01",
        "kty": "EC",
        "crv": "P-256",
        "x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
        "y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
    }
)
enc, sender = suite_s.create_sender_context(pkr)
ct = sender.seal(b"Hello world!")

# The recipient side:
suite_r = CipherSuite.new(
    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM
)
skr = KEMKey.from_jwk(
    {
        "kid": "01",
        "kty": "EC",
        "crv": "P-256",
        "x": "Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0",
        "y": "HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw",
        "d": "r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8",
    }
)
recipient = suite_r.create_recipient_context(enc, skr)
pt = recipient.open(ct)

assert pt == b"Hello world!"
```

## API Reference

See [Documentation](https://pyhpke.readthedocs.io/en/stable/api.html).

## Test

You can run tests from the project root after cloning with:

```sh
$ tox
```

## Contributing

We welcome all kind of contributions, filing issues, suggesting new features or sending PRs.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dajiaji/pyhpke",
    "name": "pyhpke",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ajitomi Daisuke",
    "author_email": "dajiaji@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/4c/f05dbfbb8010e3232d9bf4b0e73e7d56aeb48db88d7c5dfd7f45287d6a8a/pyhpke-0.6.1.tar.gz",
    "platform": null,
    "description": "# PyHPKE - A Python implementation of HPKE\n\n[![PyPI version](https://badge.fury.io/py/pyhpke.svg)](https://badge.fury.io/py/pyhpke)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyhpke)\n[![Documentation Status](https://readthedocs.org/projects/pyhpke/badge/?version=latest)](https://pyhpke.readthedocs.io/en/latest/?badge=latest)\n![Github CI](https://github.com/dajiaji/pyhpke/actions/workflows/ci.yml/badge.svg)\n[![codecov](https://codecov.io/gh/dajiaji/pyhpke/branch/main/graph/badge.svg?token=QN8GXEYEP3)](https://codecov.io/gh/dajiaji/pyhpke)\n\n\nPyHPKE is a [HPKE (Hybrid Public Key Encryption)](https://www.rfc-editor.org/rfc/rfc9180.html) implementation written in Python.\n\nYou can install PyHPKE with pip:\n\n```sh\n$ pip install pyhpke\n```\n\nAnd then, you can use it as follows:\n\n\n```py\nfrom pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey\n\n# The sender side:\nsuite_s = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\npkr = KEMKey.from_jwk(  # from_pem is also available.\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n    }\n)\nenc, sender = suite_s.create_sender_context(pkr)\nct = sender.seal(b\"Hello world!\")\n\n# The recipient side:\nsuite_r = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\nskr = KEMKey.from_jwk(\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n        \"d\": \"r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8\",\n    }\n)\nrecipient = suite_r.create_recipient_context(enc, skr)\npt = recipient.open(ct)\n\nassert pt == b\"Hello world!\"\n\n\n# deriving a KEMKeyPair\nkeypair = suite_s.kem.derive_key_pair(b\"some_ikm_bytes_used_for_key_derivation\")\n```\n\n## Index\n\n- [Installation](#installation)\n- [Supported HPKE Modes and Cipher Suites](#supported-hpke-modes-and-cipher-suites)\n- [Warnings and Restrictions](#warnings-and-restrictions)\n- [Usage](#usage)\n- [API Reference](#api-reference)\n- [Test](#test)\n- [Contributing](#contributing)\n\n## Installation\n\nYou can install PyHPKE with pip:\n\n```sh\n$ pip install pyhpke\n```\n\n## Supported HPKE Modes and Cipher Suites\n\nPyHPKE supports all of the HPKE modes and cipher suites defined in RFC9180 below.\n\n- modes\n    - \u2705 Base\n    - \u2705 PSK\n    - \u2705 Auth\n    - \u2705 AuthPSK\n- KEMs (Key Encapsulation Machanisms)\n    - \u2705 DHKEM (P-256, HKDF-SHA256)\n    - \u2705 DHKEM (P-384, HKDF-SHA384)\n    - \u2705 DHKEM (P-521, HKDF-SHA512)\n    - \u2705 DHKEM (X25519, HKDF-SHA256)\n    - \u2705 DHKEM (X448, HKDF-SHA512)\n- KDFs (Key Derivation Functions)\n    - \u2705 HKDF-SHA256\n    - \u2705 HKDF-SHA384\n    - \u2705 HKDF-SHA512\n- AEADs (Authenticated Encryption with Associated Data)\n    - \u2705 AES-128-GCM\n    - \u2705 AES-256-GCM\n    - \u2705 ChaCha20Poly1305\n    - \u2705 Export Only\n\n## Warnings and Restrictions\n\nAlthough this library has been passed all of the following official test vectors, it has not been formally audited.\n- [RFC9180 official test vectors provided on github.com/cfrg/draft-irtf-cfrg-hpke](https://github.com/cfrg/draft-irtf-cfrg-hpke/blob/5f503c564da00b0687b3de75f1dfbdfc4079ad31/test-vectors.json)\n\n## Usage\n\n```py\nfrom pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey\n\n# The sender side:\nsuite_s = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\npkr = KEMKey.from_jwk(\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n    }\n)\nenc, sender = suite_s.create_sender_context(pkr)\nct = sender.seal(b\"Hello world!\")\n\n# The recipient side:\nsuite_r = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\nskr = KEMKey.from_jwk(\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n        \"d\": \"r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8\",\n    }\n)\nrecipient = suite_r.create_recipient_context(enc, skr)\npt = recipient.open(ct)\n\nassert pt == b\"Hello world!\"\n```\n\n## API Reference\n\nSee [Documentation](https://pyhpke.readthedocs.io/en/stable/api.html).\n\n## Test\n\nYou can run tests from the project root after cloning with:\n\n```sh\n$ tox\n```\n\n## Contributing\n\nWe welcome all kind of contributions, filing issues, suggesting new features or sending PRs.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python implementation of HPKE.",
    "version": "0.6.1",
    "project_urls": {
        "Homepage": "https://github.com/dajiaji/pyhpke",
        "Repository": "https://github.com/dajiaji/pyhpke"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0547c20528e70434cb7ada19a29155c5db807ec239a7314d4e90225c623420b",
                "md5": "b2538a8e7f52f192d5ae5f7e923cf354",
                "sha256": "1dde442e2a72caf0df021ffeb5a3d3a71bafd97baf18a6485599acda17c4a237"
            },
            "downloads": -1,
            "filename": "pyhpke-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2538a8e7f52f192d5ae5f7e923cf354",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 53330,
            "upload_time": "2024-11-22T23:23:39",
            "upload_time_iso_8601": "2024-11-22T23:23:39.500244Z",
            "url": "https://files.pythonhosted.org/packages/b0/54/7c20528e70434cb7ada19a29155c5db807ec239a7314d4e90225c623420b/pyhpke-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b14cf05dbfbb8010e3232d9bf4b0e73e7d56aeb48db88d7c5dfd7f45287d6a8a",
                "md5": "a5e6f2495bc7e67851dd7fb1f57564a3",
                "sha256": "d3a1b4b50f81020af1f2835307e24d8c77b47bb733e8ef01dfc1b957d7e01b85"
            },
            "downloads": -1,
            "filename": "pyhpke-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a5e6f2495bc7e67851dd7fb1f57564a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 1751523,
            "upload_time": "2024-11-22T23:23:41",
            "upload_time_iso_8601": "2024-11-22T23:23:41.006519Z",
            "url": "https://files.pythonhosted.org/packages/b1/4c/f05dbfbb8010e3232d9bf4b0e73e7d56aeb48db88d7c5dfd7f45287d6a8a/pyhpke-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-22 23:23:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dajiaji",
    "github_project": "pyhpke",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pyhpke"
}
        
Elapsed time: 2.19110s