rucry
Криптографические примитивы на чистом Python.
Содержание
Особенности
| Область | Что даёт |
|---|---|
| GOST 28147-89 | ECB / CBC / OFB / CTR |
| S-боксы | предопределённые наборы (CryptoPro A–D, Test) или свои 8×16 |
| Ключ | 8×uint32 или 32 байта — передаётся снаружи |
| Чистый Python | без нативных расширений и внешних crypto-зависимостей |
| Hex API | encrypt_hex / decrypt_hex |
| Расширяемость | algorithms/ — сюда добавляются новые шифры |
Структура пакета
src/rucry/
├── __init__.py # публичный API
├── __version__.py
├── py.typed
└── algorithms/
├── __init__.py
└── gost28147.py # GOST 28147-89
tests/
└── test_gost28147.py
.github/
├── FUNDING.yml
└── workflows/
└── workflow.yml # Publish to PyPI (workflow_dispatch)
Публичный импорт
from rucry import (
Gost28147,
CRYPT_MODE,
SBOXES, SBOX_CRYPTOPRO_A, SBOX_TEST,
encrypt_hex, decrypt_hex,
encrypt_bytes, decrypt_bytes,
resolve_sbox, normalize_key,
)
Установка
Из GitHub:
pip install git+https://github.com/busy4beaver/rucry.git
Локально (editable):
git clone https://github.com/busy4beaver/rucry.git
cd rucry
pip install -e .
Зависимостей нет (stdlib only). Для тестов: pip install pytest.
Быстрый старт
from rucry import Gost28147, CRYPT_MODE
key = [
0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20,
]
g = Gost28147(sbox="cryptopro-a") # default
data = bytearray(b"12345678")
g.crypt(data, key, encrypt=True, mode=CRYPT_MODE.ECB)
g.crypt(data, key, encrypt=False, mode=CRYPT_MODE.ECB)
# Hex API
from rucry import encrypt_hex, decrypt_hex
ct = encrypt_hex("12345678", key, mode=CRYPT_MODE.ECB)
pt = decrypt_hex(ct, key, mode=CRYPT_MODE.ECB)
GOST 28147-89
Блочный шифр: блок 64 бит, ключ 256 бит. S-боксы — параметр алгоритма (в стандарте не зафиксированы).
Режимы
CRYPT_MODE |
Значение | Примечание |
|---|---|---|
ECB |
0 | при encrypt дополнение нулями до кратности 8 |
CBC |
1 | нужен iv (8 байт; default — нули) |
OFB |
2 | потоковый; encrypt ≡ decrypt |
CTR |
3 | потоковый со счётчиком; encrypt ≡ decrypt |
S-боксы
| Имя | Описание |
|---|---|
cryptopro-a (default) |
CryptoPro-A (RFC 4357) |
cryptopro-b / c / d |
CryptoPro B–D |
test |
TestParamSet (RFC 4357) |
| custom | любая последовательность 8×16 значений 0..15 |
from rucry import Gost28147, SBOX_TEST, resolve_sbox
Gost28147() # cryptopro-a
Gost28147(sbox="test")
Gost28147(sbox=SBOX_TEST)
Gost28147(sbox=resolve_sbox("cryptopro-b"))
# свой набор
my_sbox = [
list(range(16)), # 8 строк × 16 значений 0..15
# ...
]
Gost28147(sbox=my_sbox)
Длинные OID-имена (id-Gost28147-89-CryptoPro-A-ParamSet и т.п.) тоже принимаются.
Ключ
# 8 × uint32
key = [0x01234567, 0x89ABCDEF, ...] # 8 слов
# или 32 байта (little-endian слова)
key = bytes(range(32))
Ключ не хранится в модуле — всегда передаётся в crypt / helper-функции.
API
from rucry import Gost28147, CRYPT_MODE
g = Gost28147(sbox="cryptopro-a")
msg = bytearray(b"1234567890123456")
g.crypt(msg, key, encrypt=True, mode=CRYPT_MODE.ECB)
g.crypt(msg, key, encrypt=False, mode=CRYPT_MODE.ECB)
# CBC с IV
iv = b"\x00" * 8
g.crypt(msg, key, encrypt=True, mode=CRYPT_MODE.CBC, iv=iv)
# OFB / CTR — повторный crypt с encrypt=True восстанавливает plaintext
g.crypt(msg, key, encrypt=True, mode=CRYPT_MODE.OFB, iv=iv)
Вспомогательные: mod32, rol, ror, bytes_to_hex, hex_to_bytes,
normalize_key, resolve_sbox.
Тесты
pip install pytest
pytest tests/ -v
Покрывают round-trip ECB/CBC, involution OFB/CTR, padding, hex API, выбор S-боксов по имени и custom, ключ как 32 байта.
☕ Поддержать проект
Metadata
Release files for rucry 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rucry-0.1.0.tar.gz | 12.6 kB | With provenance | Details for rucry-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rucry-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for rucry-0.1.0-py3-none-any.whl |
Total release size: 23.0 kB
Release files / rucry-0.1.0.tar.gz
| Download URL | rucry-0.1.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
212ce03e819a70278890e6e13bbd0a5bc3828752ff038f61e634b08b1442d71b
|
|
BLAKE2b-256 checksum How to use checksums |
7fafbc2dc3e32fbb2b32fe7c3c263d9df0810d16cbdf093df8c037e59b4e0846
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logRelease files / rucry-0.1.0-py3-none-any.whl
| Download URL | rucry-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ea51ae88de252e94398b1ddd11e4e2ab3da708423c852147b60328ef11eff35
|
|
BLAKE2b-256 checksum How to use checksums |
123bd6f6e11bc4919aa11a8da48886915bcf16e465ca9f6c8bc82040854c1a82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logSecurity for rucry 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rucry-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.