Files
dvs 5dfdd87c06 Release v3.2.1: performance overhaul (1.96x geometric-mean speed-up)
Pure-Python, zero-dependency speed-up across every hot path. No public API,
error-semantics or security change.

Measured (interleaved A/B min-of-N, idle 16-core, 1 KiB payload):
  Base64 decode      21.98x
  Base58 encode       8.01x
  ChaCha20-Poly1305   3.54x
  XChaCha20-Poly1305  3.28x
  Base64 encode       2.98x
  AES-256-GCM (enc)   2.25x   (dec) 2.26x
  AES-GCM-SIV enc     2.06x
  AES-256 CTR/ECB/CBC 2.01x / 1.96x / 1.88x
  AES single block    1.87x
  Poly1305 MAC        1.41x
  Ed25519 sign        1.41x
  X25519 base         1.19x
  BLAKE2b / SHA3-512 / SHAKE128  1.34x / 1.33x / 1.30x
  => 24 improved, 3 unchanged, 0 regressed.

Techniques (all pure Python):
  - code-generated, fully unrolled AES round function and Keccak-f[1600]
  - big-integer bulk operations for GHASH, POLYVAL, buffer XOR, Base64 pack
  - precomputed lookup tables (AES T-tables, GHASH/POLYVAL 4-bit windows)
  - branch-free constant-time selection in Ed25519 scan and X25519 ladder
  - lazy modular reduction in X25519 field arithmetic
  - batched Base58/Base64 processing
  - inlined inner loops in AEAD assembly and the SHA-2 message schedule

Verification:
  - full test suite: 639 passed, 1 skipped, 0 failed
  - all FIPS / RFC / NIST vectors reproduce byte-for-byte
  - differential probe of 1266 deterministic inputs: identical
    (one unreachable private-helper edge case, no caller can reach it)
  - public API signature comparison: 0 removals, 0 changes
  - independent security regression suite: 35 / 35

Also adds docs/benchmark.md, bench/benchmark.py and the v3.2.1 documentation.
2026-09-27 11:37:33 +08:00

155 lines
5.9 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
purepycrypto — setup.py (legacy setuptools entry point)
Modern usage prefers pyproject.toml:
pip install .
pip install -e .
python -m build
======================================================================
Three usage modes provided after installation (important)
======================================================================
After installing this package, an executable command is created in the
**Python Scripts directory**:
<Python>/Scripts/purepycrypto (Windows: purepycrypto.exe)
The command is registered via ``entry_points.console_scripts`` and points to
``purepycrypto:main``; ``main()`` dispatches automatically based on whether
arguments are given:
1) purepycrypto # no arguments -> launch [interactive TUI]
2) purepycrypto hash --text abc --hex # with arguments -> [command-line mode]
3) purepycrypto --help # show command-line help
4) purepycrypto version / selftest # version / self-test
It can also be used as a library:
import purepycrypto
purepycrypto.sha256(b"abc")
And the equivalent without installation:
python -m purepycrypto # TUI
python -m purepycrypto hash --text abc --hex # command line
That is: **one single command — no arguments for the TUI, arguments for the command line**
(no separate -args command required).
======================================================================
Where CLI / TUI are implemented (for packaging and maintenance reference)
======================================================================
purepycrypto/cli.py TUI implementation (menus, self-test, CN/EN language switch)
purepycrypto/cli_args.py command-line mode implementation (argparse subcommands)
purepycrypto/__init__.py unified entry main() / run_tui() / run_cli()
purepycrypto/__main__.py python -m purepycrypto entry point
purepycrypto/single/ single-file bundle artifact (build_single.py --mode one)
Build the single file:
python purepycrypto/scripts/build_single.py --mode one
# generates purepycrypto/single/purepycrypto.py (no arguments = TUI, arguments = command line)
======================================================================
"""
import os
import sys
from setuptools import setup, find_packages
VERSION = "3.2.1"
HERE = os.path.abspath(os.path.dirname(__file__))
def _read(rel, fallback=""):
try:
with open(os.path.join(HERE, rel), "r", encoding="utf-8") as f:
return f.read()
except OSError:
return fallback
def write_version_file():
"""Write the version into purepycrypto/_version.py (keeps the runtime and packaged versions in sync)."""
path = os.path.join(HERE, "purepycrypto", "_version.py")
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", encoding="utf-8") as f:
f.write('__version__ = "%s"\n' % VERSION)
write_version_file()
long_description = _read("README.md", "purepycrypto - pure Python cryptography library")
# ----------------------------------------------------------------------
# console_scripts entry point (installed into the Python Scripts directory)
# ----------------------------------------------------------------------
# Notes:
# * Register only ONE command, `purepycrypto`, to avoid command sprawl;
# * The target is `purepycrypto:main`, whose behavior is:
# no arguments -> TUI
# with arguments -> command-line mode
# * After installation it can therefore be used directly:
# purepycrypto (TUI)
# purepycrypto hash --help (command line)
CONSOLE_SCRIPTS = [
"purepycrypto = purepycrypto:main",
]
setup(
name="purepycrypto",
version=VERSION,
description=("Pure-Python cryptography library (zero dependencies): "
"SHA-2/SHA-3/BLAKE2b, AES-GCM(-SIV), ChaCha20-Poly1305, "
"X25519/Ed25519, RSA-OAEP/PSS, with built-in TUI and command-line tool"),
long_description=long_description,
long_description_content_type="text/markdown",
author="Dvs(DvsXT)",
author_email="dvs6666@163.com",
url="https://git.dvscloud.net/dvs/purepycrypto",
license="MIT",
packages=find_packages(include=[
"purepycrypto", "purepycrypto.*",
]),
python_requires=">=3.7",
install_requires=[],
extras_require={
"test": ["pytest>=7.0"],
"dev": ["pytest>=7.0", "build", "twine"],
"compare": ["pycryptodome", "cryptography>=45"],
},
# ---- key: register the executable command (no arguments = TUI, arguments = CLI) ----
entry_points={
"console_scripts": CONSOLE_SCRIPTS,
},
include_package_data=True,
package_data={
"purepycrypto": ["py.typed"],
"purepycrypto.tests": ["vectors/*.json"],
# Single-file bundle (if generated)
"purepycrypto.single": ["*.py"],
},
zip_safe=False,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Environment :: Console",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Security :: Cryptography",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords=("cryptography crypto pure-python aes aes-gcm aes-gcm-siv "
"chacha20 poly1305 x25519 ed25519 rsa oaep pss "
"sha256 sha512 sha3 keccak shake blake2b argon2 scrypt hkdf pbkdf2 hmac "
"cli tui"),
)