|
1 | 1 | # Signature Python example |
| 2 | +import logging |
| 3 | +from pprint import pformat |
2 | 4 |
|
3 | 5 | import oqs |
4 | | -from pprint import pprint |
5 | 6 |
|
6 | | -print("liboqs version:", oqs.oqs_version()) |
7 | | -print("liboqs-python version:", oqs.oqs_python_version()) |
8 | | -print("Enabled signature mechanisms:") |
9 | | -sigs = oqs.get_enabled_sig_mechanisms() |
10 | | -pprint(sigs, compact=True) |
| 7 | +logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO) |
| 8 | +logger = logging.getLogger(__name__) |
| 9 | +logger.setLevel(logging.INFO) |
11 | 10 |
|
12 | | -message = "This is the message to sign".encode() |
| 11 | +logger.info("liboqs version: %s", oqs.oqs_version()) |
| 12 | +logger.info("liboqs-python version: %s", oqs.oqs_python_version()) |
| 13 | +logger.info( |
| 14 | + "Enabled signature mechanisms: %s", |
| 15 | + pformat(oqs.get_enabled_sig_mechanisms(), compact=True), |
| 16 | +) |
| 17 | + |
| 18 | +message = b"This is the message to sign" |
13 | 19 |
|
14 | 20 | # Create signer and verifier with sample signature mechanisms |
15 | 21 | sigalg = "Dilithium2" |
16 | | -with oqs.Signature(sigalg) as signer: |
17 | | - with oqs.Signature(sigalg) as verifier: |
18 | | - print("\nSignature details:") |
19 | | - pprint(signer.details) |
| 22 | +with oqs.Signature(sigalg) as signer, oqs.Signature(sigalg) as verifier: |
| 23 | + logger.info("Signature details: %s", pformat(signer.details)) |
20 | 24 |
|
21 | | - # Signer generates its keypair |
22 | | - signer_public_key = signer.generate_keypair() |
23 | | - # Optionally, the secret key can be obtained by calling export_secret_key() |
24 | | - # and the signer can later be re-instantiated with the key pair: |
25 | | - # secret_key = signer.export_secret_key() |
| 25 | + # Signer generates its keypair |
| 26 | + signer_public_key = signer.generate_keypair() |
| 27 | + # Optionally, the secret key can be obtained by calling export_secret_key() |
| 28 | + # and the signer can later be re-instantiated with the key pair: |
| 29 | + # secret_key = signer.export_secret_key() |
26 | 30 |
|
27 | | - # Store key pair, wait... (session resumption): |
28 | | - # signer = oqs.Signature(sigalg, secret_key) |
| 31 | + # Store key pair, wait... (session resumption): |
| 32 | + # signer = oqs.Signature(sigalg, secret_key) |
29 | 33 |
|
30 | | - # Signer signs the message |
31 | | - signature = signer.sign(message) |
| 34 | + # Signer signs the message |
| 35 | + signature = signer.sign(message) |
32 | 36 |
|
33 | | - # Verifier verifies the signature |
34 | | - is_valid = verifier.verify(message, signature, signer_public_key) |
| 37 | + # Verifier verifies the signature |
| 38 | + is_valid = verifier.verify(message, signature, signer_public_key) |
35 | 39 |
|
36 | | - print("\nValid signature?", is_valid) |
| 40 | + logger.info("Valid signature? %s", is_valid) |
0 commit comments