Skip to content

Commit 2016fa2

Browse files
authored
Add OQS rand API support (#19)
Add OQS rand API support
2 parents 5411ff2 + 6c1a397 commit 2016fa2

File tree

15 files changed

+376
-155
lines changed

15 files changed

+376
-155
lines changed

.gitignore

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,119 @@
22
__pycache__
33
liboqs.so
44
*.pyc
5-
test-results
5+
test-results
6+
7+
.swp
8+
# Byte-compiled / optimized / DLL files
9+
__pycache__/
10+
*.py[cod]
11+
*$py.class
12+
13+
# C extensions
14+
*.so
15+
16+
# Distribution / packaging
17+
.Python
18+
env/
19+
build/
20+
develop-eggs/
21+
dist/
22+
downloads/
23+
eggs/
24+
.eggs/
25+
lib/
26+
lib64/
27+
parts/
28+
sdist/
29+
var/
30+
wheels/
31+
*.egg-info/
32+
.installed.cfg
33+
*.egg
34+
35+
# PyInstaller
36+
# Usually these files are written by a python script from a template
37+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
38+
*.manifest
39+
*.spec
40+
41+
# Installer logs
42+
pip-log.txt
43+
pip-delete-this-directory.txt
44+
45+
# Unit test / coverage reports
46+
htmlcov/
47+
.tox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
.hypothesis/
55+
56+
# Translations
57+
*.mo
58+
*.pot
59+
60+
# Django stuff:
61+
*.log
62+
local_settings.py
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# pyenv
81+
.python-version
82+
83+
# celery beat schedule file
84+
celerybeat-schedule
85+
86+
# SageMath parsed files
87+
*.sage.py
88+
89+
# dotenv
90+
.env
91+
92+
# virtualenv
93+
.venv
94+
venv/
95+
ENV/
96+
97+
# Spyder project settings
98+
.spyderproject
99+
.spyproject
100+
101+
# Rope project settings
102+
.ropeproject
103+
104+
# mkdocs documentation
105+
/site
106+
107+
# mypy
108+
.mypy_cache/
109+
110+
# PyCharm & virtualenv
111+
.idea
112+
bin/
113+
include/
114+
lib/
115+
spell/
116+
pip-selfcheck.json
117+
pyvenv.cfg
118+
119+
# vim
120+
*.swp

CHANGES.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Version 0.2.1 - January 22, 2020
2+
- Added a signature example
3+
- Added partial support for RNGs from <oqs/rand.h>
4+
- Added an RNG example
5+
6+
Version 0.2.0 - October 8, 2019
7+
- This release updates for compatibility with liboqs 0.2.0, which contains
8+
new/updated algorithms based on NIST Round 2 submissions.
9+
10+
Version 0.1.0 - April 23, 2019
11+
- Initial release

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Open Quantum Safe
3+
Copyright (c) 2018-2020 Open Quantum Safe
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,29 @@ Contents
3333

3434
The project contains the following files:
3535

36-
- **`oqs/wrapper.py`: a Python 3 module wrapper for the liboqs C library.**
37-
- `examples/example.py`: illustrates the usage of the liboqs-python wrapper.
38-
- `tests/test_*.py`: unit tests for the liboqs-python wrapper.
36+
- **`oqs/oqs.py`: a Python 3 module wrapper for the liboqs C library.**
37+
- `oqs/rand.py`: a Python 3 module supporting RNGs from `<oqs/rand.h>`
38+
- `examples/kem.py`: key encapsulation example
39+
- `examples/rand.py`: RNG example
40+
- `examples/sig.py`: signature example
41+
- `tests`: unit tests
3942

4043
Usage
4144
-----
4245

43-
liboqs-python defines two main classes: `KeyEncapsulation` and `Signature`, providing post-quantum key encapsulation and signture mechanisms, respectively. Each must be instantiated with a string identifying one of mechanisms supported by liboqs; these can be enumerated using the `get_enabled_KEM_mechanisms` and `get_enabled_sig_mechanisms` functions. The `example.py` file demonstrates the wrapper's API.
46+
liboqs-python defines two main classes: `KeyEncapsulation` and `Signature`, providing post-quantum key encapsulation and signture mechanisms, respectively. Each must be instantiated with a string identifying one of mechanisms supported by liboqs; these can be enumerated using the `get_enabled_KEM_mechanisms` and `get_enabled_sig_mechanisms` functions. The files in `examples/` demonstrate the wrapper's API.
47+
Support for alternative RNGs is provided via the `randombytes[*]` functions.
4448

4549
liboqs installation
4650
-------------------
4751

4852
liboqs-python depends on the liboqs C library; it must be compiled as a Linux/macOS library or Windows DLL, and installed in one of:
4953

50-
- any file path specified by the `LIBOQS_INSTALL_PATH` environment variable (e.g. `LIBOQS_INSTALL_PATH="/path/to/liboqs.so"`)
54+
- any file path specified by the `LIBOQS_INSTALL_PATH` environment variable (e.g. `LIBOQS_INSTALL_PATH="/usr/local/bin/liboqs.so"`; **do not forget to specify `liboqs.so` at the end**)
5155
- system-wide folder
5256
- the liboqs Python module's current folder
5357

54-
`wrapper.py` checks the above locations in that order. At present, only liboqs master branch can be installed; see the [liboqs project](https://github.com/open-quantum-safe/liboqs/) for installation instructions.
58+
`oqs/oqs.py` checks the above locations in that order. At present, only liboqs master branch can be installed; see the [liboqs project](https://github.com/open-quantum-safe/liboqs/) for installation instructions.
5559

5660
liboqs-python does not depend on any other Python packages. The package isn't hosted on PyPI yet, but can be installed into a virtualenv using:
5761

@@ -71,9 +75,9 @@ The liboqs-python project should be in the `PYTHONPATH`:
7175

7276
As any python module, liboqs wrapper components can be imported into python programs with `import oqs`.
7377

74-
To run the example program:
78+
To run an example program:
7579

76-
python3 examples/example.py
80+
python3 examples/kem.py
7781

7882
To run the unit tests with a test runner (e.g. nose or rednose (`apt install python3-nose python3-rednose` or `pip3 install nose rednose`)):
7983

@@ -112,12 +116,14 @@ The Open Quantum Safe project is led by [Douglas Stebila](https://www.douglas.st
112116
Contributors to the liboqs-python wrapper include:
113117

114118
- Ben Davies (University of Waterloo)
119+
- Vlad Gheorghiu (evolutionQ, University of Waterloo)
115120
- Christian Paquin (Microsoft Research)
121+
- Douglas Stebila (University of Waterloo)
116122

117123
### Support
118124

119125
Financial support for the development of Open Quantum Safe has been provided by Amazon Web Services and the Tutte Institute for Mathematics and Computing.
120126

121-
We'd like to make a special acknowledgement to the companies who have dedicated programmer time to contribute source code to OQS, including Amazon Web Services, evolutionQ, and Microsoft Research.
127+
We'd like to make a special acknowledgement to the companies who have dedicated programmer time to contribute source code to OQS, including Amazon Web Services, Cisco Systems, evolutionQ, IBM Research, and Microsoft Research.
122128

123129
Research projects which developed specific components of OQS have been supported by various research grants, including funding from the Natural Sciences and Engineering Research Council of Canada (NSERC); see the source papers for funding acknowledgments.

RELEASE.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
liboqs-python version 0.2.0
1+
liboqs-python version 0.2.1
22
===========================
33

44
About
55
-----
66

7-
The **Open Quantum Safe (OQS) project** has the goal of developing and prototyping quantum-resistant cryptography. More information on OQS can be found on our website: https://openquantumsafe.org/ and on Github at https://github.com/open-quantum-safe/.
7+
The **Open Quantum Safe (OQS) project** has the goal of developing and prototyping quantum-resistant cryptography. More information on OQS can be found on our website: https://openquantumsafe.org/ and on Github at https://github.com/open-quantum-safe/.
88

9-
**liboqs** is an open source C library for quantum-resistant cryptographic algorithms. See more about liboqs at [https://github.com/open-quantum-safe/liboqs/](https://github.com/open-quantum-safe/liboqs/), including a list of supported algorithms.
9+
**liboqs** is an open source C library for quantum-resistant cryptographic algorithms. See more about liboqs at [https://github.com/open-quantum-safe/liboqs/](https://github.com/open-quantum-safe/liboqs/), including a list of supported algorithms.
1010

11-
**liboqs-python** is an open source Python 3 wrapper for the liboqs C library for quantum-resistant cryptographic algorithms. Details about liboqs-python can be found in [README.md](https://github.com/open-quantum-safe/liboqs-python/blob/master/README.md). See in particular limitations on intended use.
11+
**liboqs-python** is an open source Python 3 wrapper for the liboqs C library for quantum-resistant cryptographic algorithms. Details about liboqs-python can be found in [README.md](https://github.com/open-quantum-safe/liboqs-python/blob/master/README.md). See in particular limitations on intended use.
1212

1313
Release notes
1414
=============
1515

16-
This release of liboqs-python was released on October 8, 2019. Its release page on GitHub is https://github.com/open-quantum-safe/liboqs-python/releases/tag/0.2.0.
16+
This release of liboqs-python was released on January 22, 2020. Its release page on GitHub is https://github.com/open-quantum-safe/liboqs-python/releases/tag/0.2.1.
1717

1818
What's New
1919
----------
2020

21-
This is the second release of liboqs-python.
21+
This is the third release of liboqs-python.
2222

23-
This release updates for compatibility with liboqs 0.2.0, which contains new/updated algorithms based on NIST Round 2 submissions.
23+
This release added partial support for RNGs from `<oqs/rand.h>`, together with a signature example and an RNG example.
24+
25+
For a list of changes see [CHANGES.txt](https://github.com/open-quantum-safe/liboqs-python/blob/master/CHANGES.txt).

examples/example.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

examples/kem.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# key encapsulation Python example
2+
3+
from pprint import pprint
4+
import oqs
5+
6+
#######################################################################
7+
# KEM example
8+
#######################################################################
9+
10+
kems = oqs.get_enabled_KEM_mechanisms()
11+
12+
print('Enabled KEM mechanisms:')
13+
pprint(kems)
14+
15+
# create client and server with default KEM mechanisms
16+
kemalg = "DEFAULT"
17+
with oqs.KeyEncapsulation(kemalg) as client:
18+
with oqs.KeyEncapsulation(kemalg) as server:
19+
print("\nKey encapsulation details:")
20+
pprint(client.details)
21+
22+
# client generates its keypair
23+
public_key = client.generate_keypair()
24+
# optionally, the secret key can be obtained by calling export_secret_key()
25+
# and the client can later be re-instantiated with the key pair:
26+
# secret_key = client.export_secret_key()
27+
# store key pair, wait... (session resumption):
28+
# client = oqs.KeyEncapsulation(kemalg, secret_key)
29+
30+
# the server encapsulates its secret using the client's public key
31+
ciphertext, shared_secret_server = server.encap_secret(public_key)
32+
33+
# the client decapsulates the the server's ciphertext to obtain the shared secret
34+
shared_secret_client = client.decap_secret(ciphertext)
35+
36+
print("\nShared secretes coincide:", shared_secret_client == shared_secret_server)

examples/rand.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# various RNGs Python example
2+
3+
import oqs.rand as oqsrand # must be explicitly imported
4+
5+
#######################################################################
6+
# randomness example
7+
#######################################################################
8+
9+
# set the entropy seed to some random values
10+
entropy_seed = [0] * 48
11+
entropy_seed[0] = 100
12+
entropy_seed[20] = 200
13+
entropy_seed[47] = 150
14+
15+
oqsrand.randombytes_nist_kat_init(bytes(entropy_seed))
16+
oqsrand.randombytes_switch_algorithm('NIST-KAT')
17+
print('{:17s}'.format("NIST-KAT:"), ' '.join('{:02X}'.format(x) for x in oqsrand.randombytes(32)))
18+
19+
oqsrand.randombytes_switch_algorithm("OpenSSL")
20+
print('{:17s}'.format("OpenSSL:"), ' '.join('{:02X}'.format(x) for x in oqsrand.randombytes(32)))
21+
22+
oqsrand.randombytes_switch_algorithm("system")
23+
print('{:17s}'.format("System (default):"), ' '.join('{:02X}'.format(x) for x in oqsrand.randombytes(32)))

0 commit comments

Comments
 (0)