summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--README4
-rw-r--r--VERSION2
-rw-r--r--VERSION.do2
-rw-r--r--download.texi10
-rw-r--r--install.texi4
-rwxr-xr-xmaketxts.sh13
-rw-r--r--news.texi15
-rw-r--r--pygost/__init__.py4
-rw-r--r--pygost/asn1schemas/cert-selfsigned-example.py47
-rw-r--r--pygost/asn1schemas/cms.py40
-rw-r--r--pygost/default.t.do1
-rw-r--r--pygost/gost28147.py32
-rw-r--r--pygost/gost28147_mac.py8
-rw-r--r--pygost/gost3410.py38
-rw-r--r--pygost/gost3410_vko.py18
-rw-r--r--pygost/gost34112012.py10
-rw-r--r--pygost/gost34112012256.py2
-rw-r--r--pygost/gost34112012512.py2
-rw-r--r--pygost/gost341194.py12
-rw-r--r--pygost/gost3413.py2
-rw-r--r--pygost/kdf.py6
-rw-r--r--pygost/mgm.py2
-rw-r--r--pygost/pbkdf2.py2
-rw-r--r--pygost/stubs/pygost/gost3410.pyi24
-rw-r--r--pygost/stubs/pygost/gost3410_vko.pyi2
-rw-r--r--pygost/stubs/pygost/kdf.pyi2
-rw-r--r--pygost/test.do34
-rw-r--r--pygost/test_cms.py75
-rw-r--r--pygost/test_gost28147.py16
-rw-r--r--pygost/test_gost28147_mac.py2
-rw-r--r--pygost/test_gost3410.py20
-rw-r--r--pygost/test_gost3410_vko.py8
-rw-r--r--pygost/test_gost341194.py2
-rw-r--r--pygost/test_x509.py16
-rw-r--r--pygost/utils.py8
-rw-r--r--www.do5
-rw-r--r--www.texi4
38 files changed, 257 insertions, 238 deletions
diff --git a/.gitignore b/.gitignore
index 1521c8b..138ee56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
dist
+VERSION
diff --git a/README b/README
index b82dfaf..eeb0ece 100644
--- a/README
+++ b/README
@@ -49,9 +49,9 @@ Example 34.10-2012 keypair generation, signing and verifying:
>>> data_for_signing = b"some data"
>>> dgst = gost34112012256.new(data_for_signing).digest()
>>> from pygost.gost3410 import sign
- >>> signature = sign(curve, prv, dgst, mode=2012)
+ >>> signature = sign(curve, prv, dgst)
>>> from pygost.gost3410 import verify
- >>> verify(curve, pub, dgst, signature, mode=2012)
+ >>> verify(curve, pub, dgst, signature)
True
Other examples can be found in docstrings and unittests.
diff --git a/VERSION b/VERSION
index 86a9588..a75b92f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-4.9
+5.1
diff --git a/VERSION.do b/VERSION.do
new file mode 100644
index 0000000..61428e2
--- /dev/null
+++ b/VERSION.do
@@ -0,0 +1,2 @@
+redo-ifchange pygost/__init__.py
+perl -ne 'print "$1\n" if /__version__.*"(.*)"$/' < pygost/__init__.py
diff --git a/download.texi b/download.texi
index 4555f3a..dcc2997 100644
--- a/download.texi
+++ b/download.texi
@@ -1,6 +1,16 @@
@multitable {XXXXX} {XXXX-XX-XX} {XXXX KiB} {link sign} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
@headitem Version @tab Date @tab Size @tab Tarball @tab SHA256 checksum @tab Streebog-256 checksum
+@item @ref{Release 5.1, 5.1} @tab 2020-09-24 @tab 79 KiB
+@tab @url{pygost-5.1.tar.xz, link} @url{pygost-5.1.tar.xz.sig, sign}
+@tab @code{775C05CD 4E9D618C C13482B7 F9C3935E 397881E3 C146DA90 FEA2828D 3596E0FF}
+@tab @code{2688edf5a8f8339dec24c8313e52fb875d98168fcb1577b7646b4c372222874f}
+
+@item @ref{Release 5.0, 5.0} @tab 2020-09-04 @tab 78 KiB
+@tab @url{pygost-5.0.tar.xz, link} @url{pygost-5.0.tar.xz.sig, sign}
+@tab @code{D5321979 12558C5A 543CCD67 EAA34674 604457BB BF16EB0A 740C8487 C7574C87}
+@tab @code{ec813d16f6c7de42ccce61dfbc1a9cfd6523588e414e6e0aa9768371d405fd78}
+
@item @ref{Release 4.9, 4.9} @tab 2020-07-30 @tab 78 KiB
@tab @url{pygost-4.9.tar.xz, link} @url{pygost-4.9.tar.xz.sig, sign}
@tab @code{D7745B10 0FD11203 DC13BEDA D3E8E4F7 6D6CE0DF 7A496B1A D2EA35BB 4FED586F}
diff --git a/install.texi b/install.texi
index a0d71f9..e1b6793 100644
--- a/install.texi
+++ b/install.texi
@@ -1,8 +1,6 @@
@node Download
@unnumbered Download
-@set VERSION 4.9
-
No additional dependencies except Python 2.7/3.x interpreter are required.
Preferable way is to download tarball with the signature:
@@ -22,7 +20,7 @@ But also you can use pip (@strong{no} OpenPGP authentication is
performed!) with PyPI:
@example
-$ echo pygost==@value{VERSION} --hash=sha256:f832259e13283c18b1c6e8ec9860507aaacf6e6418905aa2719a626ba8235de5 > requirements.txt
+$ echo pygost==@value{VERSION} --hash=sha256:220dc92874b2f2f0ac72875e5f06bd9652b3643a13073b20843968c367db07ff > requirements.txt
$ pip install --requirement requirements.txt
@end example
diff --git a/maketxts.sh b/maketxts.sh
index 1d53d8c..d220097 100755
--- a/maketxts.sh
+++ b/maketxts.sh
@@ -1,5 +1,12 @@
#!/bin/sh -ex
+mkinfo() {
+ ${MAKEINFO:-makeinfo} --plaintext \
+ --set-customization-variable CLOSE_QUOTE_SYMBOL=\" \
+ --set-customization-variable OPEN_QUOTE_SYMBOL=\" \
+ -D "VERSION `cat VERSION`" $@
+}
+
texi=$(mktemp)
cat > $texi <<EOF
@@ -11,7 +18,7 @@ cat > $texi <<EOF
`sed -n '3,$p' < news.texi`
@bye
EOF
-makeinfo --plaintext -o NEWS $texi
+mkinfo --output NEWS $texi
cat > download.texi <<EOF
You can obtain releases source code prepared tarballs on
@@ -27,7 +34,7 @@ cat > $texi <<EOF
@include install.texi
@bye
EOF
-makeinfo --plaintext -o INSTALL $texi
+mkinfo --output INSTALL $texi
cat > $texi <<EOF
\input texinfo
@@ -36,7 +43,7 @@ cat > $texi <<EOF
@include faq.texi
@bye
EOF
-makeinfo --plaintext -o FAQ $texi
+mkinfo --output FAQ $texi
rm -f $texi
diff --git a/news.texi b/news.texi
index f46fbcf..c07e23f 100644
--- a/news.texi
+++ b/news.texi
@@ -3,6 +3,21 @@
@table @strong
+@anchor{Release 5.1}
+@item 5.1
+Small typing stubs fixes.
+
+@anchor{Release 5.0}
+@item 5.0
+ @itemize
+ @item Backward incompatible removing of misleading and excess
+ @option{mode} keyword argument from all @code{gost3410*} related
+ functions. Point/key sizes are determined by looking at curve's
+ parameters size.
+ @item @command{asn1schemas/cert-selfsigned-example.py} optionally
+ can create CA certificate.
+ @end itemize
+
@anchor{Release 4.9}
@item 4.9
@itemize
diff --git a/pygost/__init__.py b/pygost/__init__.py
index c2d5ea8..1ea51ea 100644
--- a/pygost/__init__.py
+++ b/pygost/__init__.py
@@ -1,6 +1,6 @@
-""" Pure Python GOST cryptographic functions library.
+"""Pure Python GOST cryptographic functions library.
PyGOST is free software: see the file COPYING for copying conditions.
"""
-__version__ = "4.9"
+__version__ = "5.1"
diff --git a/pygost/asn1schemas/cert-selfsigned-example.py b/pygost/asn1schemas/cert-selfsigned-example.py
index d6d262d..198ce2f 100644
--- a/pygost/asn1schemas/cert-selfsigned-example.py
+++ b/pygost/asn1schemas/cert-selfsigned-example.py
@@ -1,22 +1,23 @@
"""Create example self-signed X.509 certificate
"""
+from argparse import ArgumentParser
from base64 import standard_b64encode
from datetime import datetime
from datetime import timedelta
from os import urandom
-from sys import argv
-from sys import exit as sys_exit
from textwrap import fill
from pyderasn import Any
from pyderasn import BitString
+from pyderasn import Boolean
from pyderasn import Integer
from pyderasn import OctetString
from pyderasn import PrintableString
from pyderasn import UTCTime
from pygost.asn1schemas.oids import id_at_commonName
+from pygost.asn1schemas.oids import id_ce_basicConstraints
from pygost.asn1schemas.oids import id_ce_subjectKeyIdentifier
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512_paramSetA
@@ -28,6 +29,7 @@ from pygost.asn1schemas.x509 import AlgorithmIdentifier
from pygost.asn1schemas.x509 import AttributeType
from pygost.asn1schemas.x509 import AttributeTypeAndValue
from pygost.asn1schemas.x509 import AttributeValue
+from pygost.asn1schemas.x509 import BasicConstraints
from pygost.asn1schemas.x509 import Certificate
from pygost.asn1schemas.x509 import CertificateSerialNumber
from pygost.asn1schemas.x509 import Extension
@@ -49,8 +51,18 @@ from pygost.gost3410 import public_key
from pygost.gost3410 import sign
from pygost.gost34112012512 import GOST34112012512
-if len(argv) != 2:
- sys_exit("Usage: cert-selfsigned-example.py COMMON-NAME")
+parser = ArgumentParser(description="Self-signed X.509 certificate creator")
+parser.add_argument(
+ "--ca",
+ action="store_true",
+ help="Enable BasicConstraints.cA",
+)
+parser.add_argument(
+ "--cn",
+ required=True,
+ help="Subject's CommonName",
+)
+args = parser.parse_args()
def pem(obj):
@@ -75,12 +87,12 @@ print("-----END PRIVATE KEY-----")
prv = prv_unmarshal(prv_raw)
curve = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
-pub_raw = pub_marshal(public_key(curve, prv), mode=2012)
+pub_raw = pub_marshal(public_key(curve, prv))
subj = Name(("rdnSequence", RDNSequence([
RelativeDistinguishedName((
AttributeTypeAndValue((
("type", AttributeType(id_at_commonName)),
- ("value", AttributeValue(PrintableString(argv[1]))),
+ ("value", AttributeValue(PrintableString(args.cn))),
)),
))
])))
@@ -89,6 +101,19 @@ not_after = not_before + timedelta(days=365)
ai_sign = AlgorithmIdentifier((
("algorithm", id_tc26_signwithdigest_gost3410_2012_512),
))
+exts = [
+ Extension((
+ ("extnID", id_ce_subjectKeyIdentifier),
+ ("extnValue", OctetString(
+ SubjectKeyIdentifier(GOST34112012512(pub_raw).digest()[:20]).encode()
+ )),
+ )),
+]
+if args.ca:
+ exts.append(Extension((
+ ("extnID", id_ce_basicConstraints),
+ ("extnValue", OctetString(BasicConstraints((("cA", Boolean(True)),)).encode())),
+ )))
tbs = TBSCertificate((
("version", Version("v3")),
("serialNumber", CertificateSerialNumber(12345)),
@@ -106,14 +131,7 @@ tbs = TBSCertificate((
))),
("subjectPublicKey", BitString(OctetString(pub_raw).encode())),
))),
- ("extensions", Extensions((
- Extension((
- ("extnID", id_ce_subjectKeyIdentifier),
- ("extnValue", OctetString(
- SubjectKeyIdentifier(GOST34112012512(pub_raw).digest()[:20]).encode()
- )),
- )),
- ))),
+ ("extensions", Extensions(exts)),
))
cert = Certificate((
("tbsCertificate", tbs),
@@ -122,7 +140,6 @@ cert = Certificate((
curve,
prv,
GOST34112012512(tbs.encode()).digest()[::-1],
- mode=2012,
))),
))
print("-----BEGIN CERTIFICATE-----")
diff --git a/pygost/asn1schemas/cms.py b/pygost/asn1schemas/cms.py
index a39b10b..d2d5327 100644
--- a/pygost/asn1schemas/cms.py
+++ b/pygost/asn1schemas/cms.py
@@ -59,10 +59,25 @@ class ContentType(ObjectIdentifier):
pass
+class IssuerAndSerialNumber(Sequence):
+ schema = (
+ ("issuer", Name()),
+ ("serialNumber", CertificateSerialNumber()),
+ )
+
+
+class KeyIdentifier(OctetString):
+ pass
+
+
+class SubjectKeyIdentifier(KeyIdentifier):
+ pass
+
+
class RecipientIdentifier(Choice):
schema = (
- ("issuerAndSerialNumber", Any()),
- # ("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
+ ("issuerAndSerialNumber", IssuerAndSerialNumber()),
+ ("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
)
@@ -159,21 +174,6 @@ class OriginatorPublicKey(Sequence):
)
-class IssuerAndSerialNumber(Sequence):
- schema = (
- ("issuer", Name()),
- ("serialNumber", CertificateSerialNumber()),
- )
-
-
-class KeyIdentifier(OctetString):
- pass
-
-
-class SubjectKeyIdentifier(KeyIdentifier):
- pass
-
-
class OriginatorIdentifierOrKey(Choice):
schema = (
("issuerAndSerialNumber", IssuerAndSerialNumber()),
@@ -188,7 +188,7 @@ class UserKeyingMaterial(OctetString):
class KeyAgreeRecipientIdentifier(Choice):
schema = (
- ("issuerAndSerialNumber", Any()),
+ ("issuerAndSerialNumber", IssuerAndSerialNumber()),
# ("rKeyId", RecipientKeyIdentifier(impl=tag_ctxc(0))),
)
@@ -326,8 +326,8 @@ class EncapsulatedContentInfo(Sequence):
class SignerIdentifier(Choice):
schema = (
- ("issuerAndSerialNumber", Any()),
- # ("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
+ ("issuerAndSerialNumber", IssuerAndSerialNumber()),
+ ("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
)
diff --git a/pygost/default.t.do b/pygost/default.t.do
new file mode 100644
index 0000000..6b7f48d
--- /dev/null
+++ b/pygost/default.t.do
@@ -0,0 +1 @@
+PYTHONPATH=$PYTHONPATH:.. ${PYTHON:-python} -m unittest test_$2
diff --git a/pygost/gost28147.py b/pygost/gost28147.py
index 25c0f50..74f5e87 100644
--- a/pygost/gost28147.py
+++ b/pygost/gost28147.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" GOST 28147-89 block cipher
+"""GOST 28147-89 block cipher
This is implementation of :rfc:`5830` ECB, CNT, CFB and :rfc:`4357`
CBC modes of operation. N1, N2, K names are taken according to
@@ -148,7 +148,7 @@ SBOXES["AppliedCryptography"] = SBOXES["id-GostR3411-94-TestParamSet"]
def _K(s, _in):
- """ S-box substitution
+ """S-box substitution
:param s: S-box
:param _in: 32-bit word
@@ -167,7 +167,7 @@ def _K(s, _in):
def block2ns(data):
- """ Convert block to N1 and N2 integers
+ """Convert block to N1 and N2 integers
"""
data = bytearray(data)
return (
@@ -177,17 +177,17 @@ def block2ns(data):
def ns2block(ns):
- """ Convert N1 and N2 integers to 8-byte block
+ """Convert N1 and N2 integers to 8-byte block
"""
n1, n2 = ns
return bytes(bytearray((
- (n2 >> 0) & 255, (n2 >> 8) & 255, (n2 >> 16) & 255, (n2 >> 24) & 255,
- (n1 >> 0) & 255, (n1 >> 8) & 255, (n1 >> 16) & 255, (n1 >> 24) & 255,
+ (n2 >> 0) & 0xFF, (n2 >> 8) & 0xFF, (n2 >> 16) & 0xFF, (n2 >> 24) & 0xFF,
+ (n1 >> 0) & 0xFF, (n1 >> 8) & 0xFF, (n1 >> 16) & 0xFF, (n1 >> 24) & 0xFF,
)))
def _shift11(x):
- """ 11-bit cyclic shift
+ """11-bit cyclic shift
"""
return ((x << 11) & (2 ** 32 - 1)) | ((x >> (32 - 11)) & (2 ** 32 - 1))
@@ -208,7 +208,7 @@ def validate_sbox(sbox):
def xcrypt(seq, sbox, key, ns):
- """ Perform full-round single-block operation
+ """Perform full-round single-block operation
:param seq: sequence of K_i S-box applying (either encrypt or decrypt)
:param sbox: S-box parameters to use
@@ -234,19 +234,19 @@ def xcrypt(seq, sbox, key, ns):
def encrypt(sbox, key, ns):
- """ Encrypt single block
+ """Encrypt single block
"""
return xcrypt(SEQ_ENCRYPT, sbox, key, ns)
def decrypt(sbox, key, ns):
- """ Decrypt single block
+ """Decrypt single block
"""
return xcrypt(SEQ_DECRYPT, sbox, key, ns)
def ecb(key, data, action, sbox=DEFAULT_SBOX):
- """ ECB mode of operation
+ """ECB mode of operation
:param bytes key: encryption key
:param data: plaintext
@@ -274,7 +274,7 @@ ecb_decrypt = partial(ecb, action=decrypt)
def cbc_encrypt(key, data, iv=8 * b"\x00", pad=True, sbox=DEFAULT_SBOX, mesh=False):
- """ CBC encryption mode of operation
+ """CBC encryption mode of operation
:param bytes key: encryption key
:param bytes data: plaintext
@@ -309,7 +309,7 @@ def cbc_encrypt(key, data, iv=8 * b"\x00", pad=True, sbox=DEFAULT_SBOX, mesh=Fal
def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX, mesh=False):
- """ CBC decryption mode of operation
+ """CBC decryption mode of operation
:param bytes key: encryption key
:param bytes data: ciphertext
@@ -345,7 +345,7 @@ def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX, mesh=False):
def cnt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX):
- """ Counter mode of operation
+ """Counter mode of operation
:param bytes key: encryption key
:param bytes data: plaintext
@@ -385,7 +385,7 @@ def meshing(key, iv, sbox=DEFAULT_SBOX):
def cfb_encrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False):
- """ CFB encryption mode of operation
+ """CFB encryption mode of operation
:param bytes key: encryption key
:param bytes data: plaintext
@@ -419,7 +419,7 @@ def cfb_encrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False):
def cfb_decrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False):
- """ CFB decryption mode of operation
+ """CFB decryption mode of operation
:param bytes key: encryption key
:param bytes data: plaintext
diff --git a/pygost/gost28147_mac.py b/pygost/gost28147_mac.py
index 64712c6..4a257c5 100644
--- a/pygost/gost28147_mac.py
+++ b/pygost/gost28147_mac.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" GOST 28147-89 MAC
+"""GOST 28147-89 MAC
"""
from copy import copy
@@ -39,7 +39,7 @@ SEQ_MAC = (
class MAC(PEP247):
- """ GOST 28147-89 MAC mode of operation
+ """GOST 28147-89 MAC mode of operation
>>> m = MAC(key=key)
>>> m.update("some data")
@@ -70,12 +70,12 @@ class MAC(PEP247):
return MAC(self.key, copy(self.data), self.iv, self.sbox)
def update(self, data):
- """ Append data that has to be authenticated
+ """Append data that has to be authenticated
"""
self.data += data
def digest(self):
- """ Get MAC tag of supplied data
+ """Get MAC tag of supplied data
You have to provide at least single byte of data.
If you want to produce tag length of 3 bytes, then
diff --git a/pygost/gost3410.py b/pygost/gost3410.py
index 9f0a11e..433c818 100644
--- a/pygost/gost3410.py
+++ b/pygost/gost3410.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.10 public-key signature function.
+"""GOST R 34.10 public-key signature function.
This is implementation of GOST R 34.10-2001 (:rfc:`5832`), GOST R
34.10-2012 (:rfc:`7091`). The difference between 2001 and 2012 is the
@@ -28,14 +28,14 @@ from pygost.utils import long2bytes
from pygost.utils import modinvert
-MODE2SIZE = {
- 2001: 32,
- 2012: 64,
-}
+def point_size(point):
+ """Determine is it either 256 or 512 bit point
+ """
+ return (512 // 8) if point.bit_length() > 256 else (256 // 8)
class GOST3410Curve(object):
- """ GOST 34.10 validated curve
+ """GOST 34.10 validated curve
>>> curve = CURVES["id-GostR3410-2001-TestParamSet"]
>>> prv = prv_unmarshal(urandom(32))
@@ -70,6 +70,10 @@ class GOST3410Curve(object):
raise ValueError("Invalid parameters")
self._st = None
+ @property
+ def point_size(self):
+ return point_size(self.p)
+
def pos(self, v):
"""Make positive number
"""
@@ -215,7 +219,7 @@ DEFAULT_CURVE = CURVES["id-GostR3410-2001-CryptoPro-A-ParamSet"]
def public_key(curve, prv):
- """ Generate public key from the private one
+ """Generate public key from the private one
:param GOST3410Curve curve: curve to use
:param long prv: private key
@@ -225,8 +229,8 @@ def public_key(curve, prv):
return curve.exp(prv)
-def sign(curve, prv, digest, rand=None, mode=2001):
- """ Calculate signature for provided digest
+def sign(curve, prv, digest, rand=None):
+ """Calculate signature for provided digest
:param GOST3410Curve curve: curve to use
:param long prv: private key
@@ -237,7 +241,7 @@ def sign(curve, prv, digest, rand=None, mode=2001):
:returns: signature, BE(S) || BE(R)
:rtype: bytes, 64 or 128 bytes
"""
- size = MODE2SIZE[mode]
+ size = curve.point_size
q = curve.q
e = bytes2long(digest) % q
if e == 0:
@@ -263,8 +267,8 @@ def sign(curve, prv, digest, rand=None, mode=2001):
return long2bytes(s, size) + long2bytes(r, size)
-def verify(curve, pub, digest, signature, mode=2001):
- """ Verify provided digest with the signature
+def verify(curve, pub, digest, signature):
+ """Verify provided digest with the signature
:param GOST3410Curve curve: curve to use
:type pub: (long, long)
@@ -274,7 +278,7 @@ def verify(curve, pub, digest, signature, mode=2001):
:type signature: bytes, 64 or 128 bytes
:rtype: bool
"""
- size = MODE2SIZE[mode]
+ size = curve.point_size
if len(signature) != size * 2:
raise ValueError("Invalid signature length")
q = curve.q
@@ -316,25 +320,25 @@ def prv_unmarshal(prv):
return bytes2long(prv[::-1])
-def pub_marshal(pub, mode=2001):
+def pub_marshal(pub):
"""Marshal public key
:type pub: (long, long)
:rtype: bytes
:returns: LE(X) || LE(Y)
"""
- size = MODE2SIZE[mode]
+ size = point_size(pub[0])
return (long2bytes(pub[1], size) + long2bytes(pub[0], size))[::-1]
-def pub_unmarshal(pub, mode=2001):
+def pub_unmarshal(pub):
"""Unmarshal public key
:param pub: LE(X) || LE(Y)
:type pub: bytes
:rtype: (long, long)
"""
- size = MODE2SIZE[mode]
+ size = len(pub) // 2
pub = pub[::-1]
return (bytes2long(pub[size:]), bytes2long(pub[:size]))
diff --git a/pygost/gost3410_vko.py b/pygost/gost3410_vko.py
index 7bc7111..0d49838 100644
--- a/pygost/gost3410_vko.py
+++ b/pygost/gost3410_vko.py
@@ -32,14 +32,14 @@ def ukm_unmarshal(ukm):
return bytes2long(ukm[::-1])
-def kek(curve, prv, pub, ukm, mode):
+def kek(curve, prv, pub, ukm):
key = curve.exp(prv, pub[0], pub[1])
key = curve.exp(curve.cofactor * ukm, key[0], key[1])
- return pub_marshal(key, mode)
+ return pub_marshal(key)
def kek_34102001(curve, prv, pub, ukm):
- """ Key agreement (34.10-2001, 34.11-94)
+ """Key agreement (34.10-2001, 34.11-94)
:param GOST3410Curve curve: curve to use
:param long prv: private key
@@ -54,13 +54,13 @@ def kek_34102001(curve, prv, pub, ukm):
hash output.
"""
return GOST341194(
- kek(curve, prv, pub, ukm, mode=2001),
+ kek(curve, prv, pub, ukm),
sbox="id-GostR3411-94-CryptoProParamSet",
).digest()
-def kek_34102012256(curve, prv, pub, ukm=1, mode=2012):
- """ Key agreement (34.10-2012, 34.11-2012 256 bit)
+def kek_34102012256(curve, prv, pub, ukm=1):
+ """Key agreement (34.10-2012, 34.11-2012 256 bit)
:param GOST3410Curve curve: curve to use
:param long prv: private key
@@ -73,11 +73,11 @@ def kek_34102012256(curve, prv, pub, ukm=1, mode=2012):
Shared Key Encryption Key computation is based on
:rfc:`7836` VKO GOST R 34.10-2012.
"""
- return GOST34112012256(kek(curve, prv, pub, ukm, mode=mode)).digest()
+ return GOST34112012256(kek(curve, prv, pub, ukm)).digest()
def kek_34102012512(curve, prv, pub, ukm=1):
- """ Key agreement (34.10-2012, 34.11-2012 512 bit)
+ """Key agreement (34.10-2012, 34.11-2012 512 bit)
:param GOST3410Curve curve: curve to use
:param long prv: private key
@@ -90,4 +90,4 @@ def kek_34102012512(curve, prv, pub, ukm=1):
Shared Key Encryption Key computation is based on
:rfc:`7836` VKO GOST R 34.10-2012.
"""
- return GOST34112012512(kek(curve, prv, pub, ukm, mode=2012)).digest()
+ return GOST34112012512(kek(curve, prv, pub, ukm)).digest()
diff --git a/pygost/gost34112012.py b/pygost/gost34112012.py
index df4777f..b21b83c 100644
--- a/pygost/gost34112012.py
+++ b/pygost/gost34112012.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.11-2012 (Streebog) hash function common files
+"""GOST R 34.11-2012 (Streebog) hash function common files
This is implementation of :rfc:`6986`. Most function and variable names are
taken according to specification's terminology.
@@ -164,7 +164,7 @@ C = [hexdec("".join(s))[::-1] for s in (
def add512bit(a, b):
- """ Add two 512 integers
+ """Add two 512 integers
"""
a = bytearray(a)
b = bytearray(b)
@@ -213,7 +213,7 @@ def L(data):
class GOST34112012(PEP247):
- """ GOST 34.11-2012 big-endian hash
+ """GOST 34.11-2012 big-endian hash
>>> m = GOST34112012(digest_size=32)
>>> m.update("foo")
@@ -239,12 +239,12 @@ class GOST34112012(PEP247):
return self._digest_size
def update(self, data):
- """ Append data that has to be hashed
+ """Append data that has to be hashed
"""
self.data += data
def digest(self):
- """ Get hash of the provided data
+ """Get hash of the provided data
"""
hsh = BLOCKSIZE * (b"\x01" if self.digest_size == 32 else b"\x00")
chk = bytearray(BLOCKSIZE * b"\x00")
diff --git a/pygost/gost34112012256.py b/pygost/gost34112012256.py
index 865847d..82c947e 100644
--- a/pygost/gost34112012256.py
+++ b/pygost/gost34112012256.py
@@ -1,4 +1,4 @@
-""" GOST R 34.11-2012 (Streebog) 256-bit hash function
+"""GOST R 34.11-2012 (Streebog) 256-bit hash function
This is implementation of :rfc:`6986`. Most function and variable names are
taken according to specification's terminology.
diff --git a/pygost/gost34112012512.py b/pygost/gost34112012512.py
index f02b061..d41bea6 100644
--- a/pygost/gost34112012512.py
+++ b/pygost/gost34112012512.py
@@ -1,4 +1,4 @@
-""" GOST R 34.11-2012 (Streebog) 512-bit hash function
+"""GOST R 34.11-2012 (Streebog) 512-bit hash function
This is implementation of :rfc:`6986`. Most function and variable names are
taken according to specification's terminology.
diff --git a/pygost/gost341194.py b/pygost/gost341194.py
index 4ffb45e..ba20a6e 100644
--- a/pygost/gost341194.py
+++ b/pygost/gost341194.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.11-94 hash function
+"""GOST R 34.11-94 hash function
This is implementation of :rfc:`5831`. Most function and variable names are
taken according to specification's terminology.
@@ -58,7 +58,7 @@ def P(x):
def _chi(Y):
- """ Chi function
+ """Chi function
This is some kind of LFSR.
"""
@@ -79,7 +79,7 @@ def _chi(Y):
def _step(hin, m, sbox):
- """ Step function
+ """Step function
H_out = f(H_in, m)
"""
@@ -126,7 +126,7 @@ def _step(hin, m, sbox):
class GOST341194(PEP247):
- """ GOST 34.11-94 big-endian hash
+ """GOST 34.11-94 big-endian hash
>>> m = GOST341194()
>>> m.update("foo")
@@ -152,12 +152,12 @@ class GOST341194(PEP247):
return GOST341194(copy(self.data), self.sbox)
def update(self, data):
- """ Append data that has to be hashed
+ """Append data that has to be hashed
"""
self.data += data
def digest(self):
- """ Get hash of the provided data
+ """Get hash of the provided data
"""
_len = 0
checksum = 0
diff --git a/pygost/gost3413.py b/pygost/gost3413.py
index ec16f8c..32be5a3 100644
--- a/pygost/gost3413.py
+++ b/pygost/gost3413.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.13-2015: Modes of operation for block ciphers
+"""GOST R 34.13-2015: Modes of operation for block ciphers
This module currently includes only padding methods.
"""
diff --git a/pygost/kdf.py b/pygost/kdf.py
index 73d716f..3f355a7 100644
--- a/pygost/kdf.py
+++ b/pygost/kdf.py
@@ -61,7 +61,7 @@ def kdf_tree_gostr3411_2012_256(key, label, seed, keys, i_len=1):
return keymat
-def keg(curve, prv, pub, h, mode=2001):
+def keg(curve, prv, pub, h):
"""Export key generation (Р 1323565.1.020-2018)
:param GOST3410Curve curve: curve to use
@@ -75,7 +75,7 @@ def keg(curve, prv, pub, h, mode=2001):
ukm = bytes2long(h[:16])
if ukm == 0:
ukm = 1
- if mode == 2012:
+ if curve.point_size == 64:
return kek_34102012512(curve, prv, pub, ukm)
- k_exp = kek_34102012256(curve, prv, pub, ukm, mode=2001)
+ k_exp = kek_34102012256(curve, prv, pub, ukm)
return b"".join(kdf_tree_gostr3411_2012_256(k_exp, b"kdf tree", h[16:24], 2))
diff --git a/pygost/mgm.py b/pygost/mgm.py
index 0321628..33e297c 100644
--- a/pygost/mgm.py
+++ b/pygost/mgm.py
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" Multilinear Galois Mode (MGM) block cipher mode.
+"""Multilinear Galois Mode (MGM) block cipher mode.
"""
from hmac import compare_digest
diff --git a/pygost/pbkdf2.py b/pygost/pbkdf2.py
index 4bef6c6..0fd6ddc 100644
--- a/pygost/pbkdf2.py
+++ b/pygost/pbkdf2.py
@@ -1,5 +1,5 @@
# coding: utf-8
-""" PBKDF2 implementation suitable for GOST R 34.11-94/34.11-2012.
+"""PBKDF2 implementation suitable for GOST R 34.11-94/34.11-2012.
This implementation is based on Python 3.5.2 source code's one.
PyGOST does not register itself in hashlib anyway, so use it instead.
diff --git a/pygost/stubs/pygost/gost3410.pyi b/pygost/stubs/pygost/gost3410.pyi
index 4be8b1d..7f55fa9 100644
--- a/pygost/stubs/pygost/gost3410.pyi
+++ b/pygost/stubs/pygost/gost3410.pyi
@@ -4,7 +4,6 @@ from typing import Tuple
DEFAULT_CURVE = ... # type: GOST3410Curve
CURVES = ... # type: Dict[str, GOST3410Curve]
-MODE2SIZE = ... # type: Dict[int, int]
PublicKey = Tuple[int, int]
@@ -38,35 +37,26 @@ class GOST3410Curve(object):
def st(self) -> Tuple[int, int]: ...
+ @property
+ def point_size(self) -> int: ...
+
def public_key(curve: GOST3410Curve, prv: int) -> PublicKey: ...
-def sign(
- curve: GOST3410Curve,
- prv: int,
- digest: bytes,
- rand: bytes=None,
- mode: int=...,
-) -> bytes: ...
+def sign(curve: GOST3410Curve, prv: int, digest: bytes, rand: bytes=None) -> bytes: ...
-def verify(
- curve: GOST3410Curve,
- pub: PublicKey,
- digest: bytes,
- signature: bytes,
- mode: int=...,
-) -> bool: ...
+def verify(curve: GOST3410Curve, pub: PublicKey, digest: bytes, signature: bytes) -> bool: ...
def prv_unmarshal(prv: bytes) -> int: ...
-def pub_marshal(pub: PublicKey, mode: int=...) -> bytes: ...
+def pub_marshal(pub: PublicKey) -> bytes: ...
-def pub_unmarshal(pub: bytes, mode: int=...) -> PublicKey: ...
+def pub_unmarshal(pub: bytes) -> PublicKey: ...
def uv2xy(curve: GOST3410Curve, u: int, v: int) -> Tuple[int, int]: ...
diff --git a/pygost/stubs/pygost/gost3410_vko.pyi b/pygost/stubs/pygost/gost3410_vko.pyi
index 6e4531f..c6d35e5 100644
--- a/pygost/stubs/pygost/gost3410_vko.pyi
+++ b/pygost/stubs/pygost/gost3410_vko.pyi
@@ -8,7 +8,7 @@ def ukm_unmarshal(ukm: bytes) -> int: ...
def kek_34102001(curve: GOST3410Curve, prv: int, pub: PublicKey, ukm: int) -> bytes: ...
-def kek_34102012256(curve: GOST3410Curve, prv: int, pub: PublicKey, ukm: int=..., mode: int=...) -> bytes: ...
+def kek_34102012256(curve: GOST3410Curve, prv: int, pub: PublicKey, ukm: int=...) -> bytes: ...
def kek_34102012512(curve: GOST3410Curve, prv: int, pub: PublicKey, ukm: int=...) -> bytes: ...
diff --git a/pygost/stubs/pygost/kdf.pyi b/pygost/stubs/pygost/kdf.pyi
index 78a82e9..932d6ef 100644
--- a/pygost/stubs/pygost/kdf.pyi
+++ b/pygost/stubs/pygost/kdf.pyi
@@ -18,4 +18,4 @@ def kdf_tree_gostr3411_2012_256(
) -> Sequence[bytes]: ...
-def keg(curve: GOST3410Curve, prv: int, pub: PublicKey, h: bytes, mode=2001) -> bytes: ...
+def keg(curve: GOST3410Curve, prv: int, pub: PublicKey, h: bytes) -> bytes: ...
diff --git a/pygost/test.do b/pygost/test.do
index d73b608..fd7e4e6 100644
--- a/pygost/test.do
+++ b/pygost/test.do
@@ -1,20 +1,14 @@
-mods="
-gost28147
-gost28147_mac
-gost341194
-gost34112012
-gost3410
-gost3410_vko
-wrap
-gost3412
-gost3413
-mgm
-kdf
-x509
-cms
-pfx
-"
-
-for mod in $mods ; do
- PYTHONPATH=$PYTHONPATH:.. ${PYTHON:=python} -m unittest test_$mod
-done
+redo-ifchange gost28147.t
+redo-ifchange gost28147_mac.t
+redo-ifchange gost341194.t
+redo-ifchange gost34112012.t
+redo-ifchange gost3410.t
+redo-ifchange gost3410_vko.t
+redo-ifchange wrap.t
+redo-ifchange gost3412.t
+redo-ifchange gost3413.t
+redo-ifchange mgm.t
+redo-ifchange kdf.t
+redo-ifchange x509.t
+redo-ifchange cms.t
+redo-ifchange pfx.t
diff --git a/pygost/test_cms.py b/pygost/test_cms.py
index b659581..31fb7d9 100644
--- a/pygost/test_cms.py
+++ b/pygost/test_cms.py
@@ -86,7 +86,6 @@ class TestSigned(TestCase):
prv_key_raw,
curve_name,
hasher,
- mode,
):
content_info, tail = ContentInfo().decode(content_info_raw)
self.assertSequenceEqual(tail, b"")
@@ -99,7 +98,6 @@ class TestSigned(TestCase):
public_key(curve, prv_unmarshal(prv_key_raw)),
hasher(bytes(signed_data["encapContentInfo"]["eContent"])).digest()[::-1],
bytes(signed_data["signerInfos"][0]["signature"]),
- mode=mode,
))
def test_256(self):
@@ -117,7 +115,6 @@ VNwDQ8enFItJZ8DEX4blZ8QtziNCMl5HbA==
prv_key_raw,
"id-GostR3410-2001-CryptoPro-XchA-ParamSet",
GOST34112012256,
- 2001,
)
def test_512(self):
@@ -136,7 +133,6 @@ PS+KRYxT8vhcsBLWWxDkc1McI7aF09hqtED36mQOfACzeJjEoUjALpmJob1V
prv_key_raw,
"id-tc26-gost-3410-12-512-paramSetB",
GOST34112012512,
- 2012,
)
@@ -313,7 +309,6 @@ pRmMVN+YtRsrEHwH3ToQ/i4vrtgA+eONuKT2uKZFikxA+VNmeeGdhkgqETMihQ==
prv_unmarshal(prv),
pub_unmarshal(pub),
ukm_unmarshal(ukm),
- mode=2001,
)
self.process_cms(
@@ -343,7 +338,7 @@ FTAVBAj+1QzaXaN9FwYJKoUDBwECBQEBgAyK54euw0sHhEVEkA0=
return kek_34102012256(
curve,
prv_unmarshal(prv),
- pub_unmarshal(pub, mode=2012),
+ pub_unmarshal(pub),
ukm_unmarshal(ukm),
)
@@ -446,7 +441,6 @@ UNjyuY+54uVcHw==
prv_unmarshal(prv),
pub_unmarshal(pub),
ukm_unmarshal(ukm),
- mode=2001,
)
self.process_cms(
@@ -476,7 +470,7 @@ WFUZEnEuAKcuG6dTOawEBLhi9hIwOgYJKoZIhvcNAQcBMB8GBiqFAwICFTAVBAiD
return kek_34102012256(
curve,
prv_unmarshal(prv),
- pub_unmarshal(pub, mode=2012),
+ pub_unmarshal(pub),
ukm_unmarshal(ukm),
)
@@ -493,13 +487,14 @@ WFUZEnEuAKcuG6dTOawEBLhi9hIwOgYJKoZIhvcNAQcBMB8GBiqFAwICFTAVBAiD
class TestR132356510252019(TestCase):
"""Test vectors from Р 1323565.1.025-2019
"""
- curve256 = CURVES["id-tc26-gost-3410-2012-256-paramSetA"]
- curve512 = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
- psk = hexdec("8F5EEF8814D228FB2BBC5612323730CFA33DB7263CC2C0A01A6C6953F33D61D5")[::-1]
+ def setUp(self):
+ self.curve256 = CURVES["id-tc26-gost-3410-2012-256-paramSetA"]
+ self.curve512 = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
+ self.psk = hexdec("8F5EEF8814D228FB2BBC5612323730CFA33DB7263CC2C0A01A6C6953F33D61D5")[::-1]
- ca_prv = prv_unmarshal(hexdec("092F8D059E97E22B90B1AE99F0087FC4D26620B91550CBB437C191005A290810")[::-1])
- ca_pub = public_key(curve256, ca_prv)
- ca_cert = Certificate().decod(b64decode("""
+ self.ca_prv = prv_unmarshal(hexdec("092F8D059E97E22B90B1AE99F0087FC4D26620B91550CBB437C191005A290810")[::-1])
+ self.ca_pub = public_key(self.curve256, self.ca_prv)
+ self.ca_cert = Certificate().decod(b64decode("""
MIIB8DCCAZ2gAwIBAgIEAYy6gTAKBggqhQMHAQEDAjA4MQ0wCwYDVQQKEwRUSzI2
MScwJQYDVQQDEx5DQSBUSzI2OiBHT1NUIDM0LjEwLTEyIDI1Ni1iaXQwHhcNMDEw
MTAxMDAwMDAwWhcNNDkxMjMxMDAwMDAwWjA4MQ0wCwYDVQQKEwRUSzI2MScwJQYD
@@ -513,9 +508,9 @@ AgNBAAgv248F4OeNCkhlzJWec0evHYnMBlSzk1lDm0F875B7CqMrKh2MtJHXenbj
Gc2uRn2IwgmSf/LZDrYsKKqZSxk=
"""))
- sender256_prv = prv_unmarshal(hexdec("0B20810E449978C7C3B76C6FF77A16C532421139344A058EF56310B6B6F377E8")[::-1])
- sender256_pub = public_key(curve256, sender256_prv)
- sender256_cert = Certificate().decod(b64decode("""
+ self.sender256_prv = prv_unmarshal(hexdec("0B20810E449978C7C3B76C6FF77A16C532421139344A058EF56310B6B6F377E8")[::-1])
+ self.sender256_pub = public_key(self.curve256, self.sender256_prv)
+ self.sender256_cert = Certificate().decod(b64decode("""
MIIB8zCCAaCgAwIBAgIEAYy6gjAKBggqhQMHAQEDAjA4MQ0wCwYDVQQKEwRUSzI2
MScwJQYDVQQDEx5DQSBUSzI2OiBHT1NUIDM0LjEwLTEyIDI1Ni1iaXQwHhcNMDEw
MTAxMDAwMDAwWhcNNDkxMjMxMDAwMDAwWjA7MQ0wCwYDVQQKEwRUSzI2MSowKAYD
@@ -529,9 +524,9 @@ AQEDAgNBAB41oijaXSEn58l78y2rhxY35/lKEq4XWZ70FtsNlVxWATyzgO5Wliwn
t1O4GoZsxx8r6T/i7VG65UNmQlwdOKQ=
"""))
- recipient256_prv = prv_unmarshal(hexdec("0DC8DC1FF2BC114BABC3F1CA8C51E4F58610427E197B1C2FBDBA4AE58CBFB7CE")[::-1])
- recipient256_pub = public_key(curve256, recipient256_prv)
- recipient256_cert = Certificate().decod(b64decode("""
+ self.recipient256_prv = prv_unmarshal(hexdec("0DC8DC1FF2BC114BABC3F1CA8C51E4F58610427E197B1C2FBDBA4AE58CBFB7CE")[::-1])
+ self.recipient256_pub = public_key(self.curve256, self.recipient256_prv)
+ self.recipient256_cert = Certificate().decod(b64decode("""
MIIB8jCCAZ+gAwIBAgIEAYy6gzAKBggqhQMHAQEDAjA4MQ0wCwYDVQQKEwRUSzI2
MScwJQYDVQQDEx5DQSBUSzI2OiBHT1NUIDM0LjEwLTEyIDI1Ni1iaXQwHhcNMDEw
MTAxMDAwMDAwWhcNNDkxMjMxMDAwMDAwWjA6MQ0wCwYDVQQKEwRUSzI2MSkwJwYD
@@ -545,9 +540,9 @@ AQMCA0EAPP9Oad1/5jwokSjPpccsQ0xCdVYM+mGQ0IbpiZxQj8gnkt8sq4jR6Ya+
I/BDkbZNDNE27TU1p3t5rE9NMEeViA==
"""))
- sender512_prv = prv_unmarshal(hexdec("F95A5D44C5245F63F2E7DF8E782C1924EADCB8D06C52D91023179786154CBDB1561B4DF759D69F67EE1FBD5B68800E134BAA12818DA4F3AC75B0E5E6F9256911")[::-1])
- sender512_pub = public_key(curve512, sender512_prv)
- sender512_cert = Certificate().decod(b64decode("""
+ self.sender512_prv = prv_unmarshal(hexdec("F95A5D44C5245F63F2E7DF8E782C1924EADCB8D06C52D91023179786154CBDB1561B4DF759D69F67EE1FBD5B68800E134BAA12818DA4F3AC75B0E5E6F9256911")[::-1])
+ self.sender512_pub = public_key(self.curve512, self.sender512_prv)
+ self.sender512_cert = Certificate().decod(b64decode("""
MIICNjCCAeOgAwIBAgIEAYy6hDAKBggqhQMHAQEDAjA4MQ0wCwYDVQQKEwRUSzI2
MScwJQYDVQQDEx5DQSBUSzI2OiBHT1NUIDM0LjEwLTEyIDI1Ni1iaXQwHhcNMDEw
MTAxMDAwMDAwWhcNNDkxMjMxMDAwMDAwWjA7MQ0wCwYDVQQKEwRUSzI2MSowKAYD
@@ -562,9 +557,9 @@ zCcRpxRAmFHvlXowCgYIKoUDBwEBAwIDQQAbjA0Q41/rIKOOvjHKsAsoEJM+WJf6
/PKXg2JaStthmw99bdtwwkU/qDbcje2tF6mt+XWyQBXwvfeES1GFY9fJ
"""))
- recipient512_prv = prv_unmarshal(hexdec("A50315981F0A7C7FC05B4EB9591A62B1F84BD6FD518ACFCEDF0A7C9CF388D1F18757C056ADA5B38CBF24CDDB0F1519EF72DB1712CEF1920952E94AF1F9C575DC")[::-1])
- recipient512_pub = public_key(curve512, recipient512_prv)
- recipient512_cert = Certificate().decod(b64decode("""
+ self.recipient512_prv = prv_unmarshal(hexdec("A50315981F0A7C7FC05B4EB9591A62B1F84BD6FD518ACFCEDF0A7C9CF388D1F18757C056ADA5B38CBF24CDDB0F1519EF72DB1712CEF1920952E94AF1F9C575DC")[::-1])
+ self.recipient512_pub = public_key(self.curve512, self.recipient512_prv)
+ self.recipient512_cert = Certificate().decod(b64decode("""
MIICNTCCAeKgAwIBAgIEAYy6hTAKBggqhQMHAQEDAjA4MQ0wCwYDVQQKEwRUSzI2
MScwJQYDVQQDEx5DQSBUSzI2OiBHT1NUIDM0LjEwLTEyIDI1Ni1iaXQwHhcNMDEw
MTAxMDAwMDAwWhcNNDkxMjMxMDAwMDAwWjA6MQ0wCwYDVQQKEwRUSzI2MSkwJwYD
@@ -582,17 +577,17 @@ ja64NaM5h+cAFoHm6t/k+ziLh2A11rTakR+5of4NQ3EjEhuPtomP2tc=
def test_certs(self):
"""Certificates signatures
"""
- for prv, pub, curve, mode, cert in (
- (self.ca_prv, self.ca_pub, self.curve256, 2001, self.ca_cert),
- (self.sender256_prv, self.sender256_pub, self.curve256, 2001, self.sender256_cert),
- (self.recipient256_prv, self.recipient256_pub, self.curve256, 2001, self.recipient256_cert),
- (self.sender512_prv, self.sender512_pub, self.curve512, 2012, self.sender512_cert),
- (self.recipient512_prv, self.recipient512_pub, self.curve512, 2012, self.recipient512_cert),
+ for prv, pub, curve, cert in (
+ (self.ca_prv, self.ca_pub, self.curve256, self.ca_cert),
+ (self.sender256_prv, self.sender256_pub, self.curve256, self.sender256_cert),
+ (self.recipient256_prv, self.recipient256_pub, self.curve256, self.recipient256_cert),
+ (self.sender512_prv, self.sender512_pub, self.curve512, self.sender512_cert),
+ (self.recipient512_prv, self.recipient512_pub, self.curve512, self.recipient512_cert),
):
pub_our = public_key(curve, prv)
self.assertEqual(pub_our, pub)
self.assertSequenceEqual(
- pub_marshal(pub_our, mode=mode),
+ pub_marshal(pub_our),
bytes(OctetString().decod(bytes(
cert["tbsCertificate"]["subjectPublicKeyInfo"]["subjectPublicKey"]
))),
@@ -610,7 +605,6 @@ ja64NaM5h+cAFoHm6t/k+ziLh2A11rTakR+5of4NQ3EjEhuPtomP2tc=
self.ca_pub,
GOST34112012256(cert["tbsCertificate"].encode()).digest()[::-1],
bytes(cert["signatureValue"]),
- mode=2001,
))
def test_signed_with_attrs(self):
@@ -662,7 +656,6 @@ bLx5whxd+mzlpekL5i6ImRX+TpERxrA/xSe5
SignedAttributes(si["signedAttrs"]).encode()
).digest()[::-1],
bytes(si["signature"]),
- mode=2012,
))
def test_signed_without_attrs(self):
@@ -701,7 +694,6 @@ Ni1iaXQCBAGMuoIwCgYIKoUDBwEBAgIwCgYIKoUDBwEBAQEEQC6jZPA59szL9FiA
self.sender256_pub,
GOST34112012256(content).digest()[::-1],
bytes(si["signature"]),
- mode=2001,
))
def test_kari_ephemeral(self):
@@ -730,7 +722,6 @@ ITAfBgkqhQMHAQAGAQExEgQQs1t6D3J3WCEvxunnEE15NQ==
)
orig_pub = pub_unmarshal(
bytes(OctetString().decod(bytes(orig_key["publicKey"]))),
- mode=2012,
)
ukm = bytes(kari["ukm"])
self.assertEqual(
@@ -742,7 +733,7 @@ ITAfBgkqhQMHAQAGAQExEgQQs1t6D3J3WCEvxunnEE15NQ==
id_tc26_agreement_gost3410_2012_512,
)
kexp = bytes(kari["recipientEncryptedKeys"][0]["encryptedKey"])
- keymat = keg(self.curve512, self.recipient512_prv, orig_pub, ukm, mode=2012)
+ keymat = keg(self.curve512, self.recipient512_prv, orig_pub, ukm)
kim, kek = keymat[:KEYSIZE], keymat[KEYSIZE:]
cek = kimp15(
GOST3412Kuznechik(kek).encrypt,
@@ -816,7 +807,6 @@ L0jFhWHTF1tcAxYmd9pX5i89UwIxhtYqyjX1QHju2g==
self.recipient256_prv,
self.sender256_pub,
ukm,
- mode=2001,
)
kim, kek = keymat[:KEYSIZE], keymat[KEYSIZE:]
cek = kimp15(
@@ -876,10 +866,10 @@ LzdPJe1MkYV0qQgdC1zI3nQ7/4taf+4zRA==
)
pub = pub_unmarshal(bytes(OctetString().decod(
bytes(encrypted_key["ephemeralPublicKey"]["subjectPublicKey"])
- )), mode=2001)
+ )))
ukm = bytes(encrypted_key["ukm"])
kexp = bytes(encrypted_key["encryptedKey"])
- keymat = keg(self.curve256, self.recipient256_prv, pub, ukm, mode=2001)
+ keymat = keg(self.curve256, self.recipient256_prv, pub, ukm)
kim, kek = keymat[:KEYSIZE], keymat[KEYSIZE:]
cek = kimp15(
GOST3412Kuznechik(kek).encrypt,
@@ -941,11 +931,10 @@ LuZ22Yw=
bytes(OctetString().decod(
bytes(encrypted_key["ephemeralPublicKey"]["subjectPublicKey"])
)),
- mode=2012,
)
ukm = bytes(encrypted_key["ukm"])
kexp = bytes(encrypted_key["encryptedKey"])
- keymat = keg(self.curve512, self.recipient512_prv, pub, ukm, mode=2012)
+ keymat = keg(self.curve512, self.recipient512_prv, pub, ukm)
kim, kek = keymat[:KEYSIZE], keymat[KEYSIZE:]
cek = kimp15(
GOST3412Magma(kek).encrypt,
diff --git a/pygost/test_gost28147.py b/pygost/test_gost28147.py
index 5ccb687..5e9da8d 100644
--- a/pygost/test_gost28147.py
+++ b/pygost/test_gost28147.py
@@ -37,7 +37,7 @@ from pygost.utils import strxor
class ECBTest(TestCase):
def test_gcl(self):
- """ Test vectors from libgcl3
+ """Test vectors from libgcl3
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
@@ -115,7 +115,7 @@ class ECBTest(TestCase):
self.assertSequenceEqual(decrypted, plaintext)
def test_cryptopp(self):
- """ Test vectors from Crypto++ 5.6.2
+ """Test vectors from Crypto++ 5.6.2
"""
sbox = "AppliedCryptography"
data = (
@@ -135,7 +135,7 @@ class ECBTest(TestCase):
self.assertSequenceEqual(ecb_encrypt(key, pt, sbox=sbox), ct)
def test_cryptomanager(self):
- """ Test vector from http://cryptomanager.com/tv.html
+ """Test vector from http://cryptomanager.com/tv.html
"""
sbox = "id-GostR3411-94-TestParamSet"
key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
@@ -147,7 +147,7 @@ class ECBTest(TestCase):
class CFBTest(TestCase):
def test_cryptomanager(self):
- """ Test vector from http://cryptomanager.com/tv.html
+ """Test vector from http://cryptomanager.com/tv.html
"""
key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
sbox = "id-GostR3411-94-TestParamSet"
@@ -171,7 +171,7 @@ class CFBTest(TestCase):
)
def test_steps(self):
- """ Check step-by-step operation manually
+ """Check step-by-step operation manually
"""
key = urandom(KEYSIZE)
iv = urandom(BLOCKSIZE)
@@ -194,7 +194,7 @@ class CFBTest(TestCase):
self.assertSequenceEqual(step[:4], ciphertext[16:])
def test_random(self):
- """ Random data with various sizes
+ """Random data with various sizes
"""
key = urandom(KEYSIZE)
iv = urandom(BLOCKSIZE)
@@ -208,7 +208,7 @@ class CFBTest(TestCase):
class CTRTest(TestCase):
def test_gcl(self):
- """ Test vectors from libgcl3
+ """Test vectors from libgcl3
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
@@ -287,7 +287,7 @@ class CTRTest(TestCase):
self.assertSequenceEqual(decrypted, plaintext)
def test_gcl2(self):
- """ Test vectors 2 from libgcl3
+ """Test vectors 2 from libgcl3
"""
sbox = "id-Gost28147-89-TestParamSet"
key = hexdec(b"fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a")
diff --git a/pygost/test_gost28147_mac.py b/pygost/test_gost28147_mac.py
index 2f54dd8..d5d5bfe 100644
--- a/pygost/test_gost28147_mac.py
+++ b/pygost/test_gost28147_mac.py
@@ -20,7 +20,7 @@ from pygost.gost28147_mac import MAC
class TestMAC(TestCase):
- """ Test vectors generated with libgcl3 library
+ """Test vectors generated with libgcl3 library
"""
k = b"This is message\xFF length\x0032 bytes"
diff --git a/pygost/test_gost3410.py b/pygost/test_gost3410.py
index 9d0b686..f95c47b 100644
--- a/pygost/test_gost3410.py
+++ b/pygost/test_gost3410.py
@@ -32,7 +32,7 @@ from pygost.utils import long2bytes
class Test341001(TestCase):
def test_rfc(self):
- """ Test vector from :rfc:`5832`
+ """Test vector from :rfc:`5832`
"""
prv = bytes(bytearray((
0x7A, 0x92, 0x9A, 0xDE, 0x78, 0x9B, 0xB9, 0xBE,
@@ -85,8 +85,8 @@ class Test341001(TestCase):
pubX, pubY = public_key(c, prv)
for _ in range(20):
digest = urandom(32)
- s = sign(c, prv, digest, mode=2001)
- self.assertTrue(verify(c, (pubX, pubY), digest, s, mode=2001))
+ s = sign(c, prv, digest)
+ self.assertTrue(verify(c, (pubX, pubY), digest, s))
class Test34102012(TestCase):
@@ -116,13 +116,13 @@ class Test34102012(TestCase):
prv = bytes2long(hexdec("0BA6048AADAE241BA40936D47756D7C93091A0E8514669700EE7508E508B102072E8123B2200A0563322DAD2827E2714A2636B7BFD18AADFC62967821FA18DD4"))
digest = hexdec("3754F3CFACC9E0615C4F4A7C4D8DAB531B09B6F9C170C533A71D147035B0C5917184EE536593F4414339976C647C5D5A407ADEDB1D560C4FC6777D2972075B8C")
rand = hexdec("0359E7F4B1410FEACC570456C6801496946312120B39D019D455986E364F365886748ED7A44B3E794434006011842286212273A6D14CF70EA3AF71BB1AE679F1")
- signature = sign(curve, prv, digest, rand, mode=2012)
+ signature = sign(curve, prv, digest, rand)
r = "2f86fa60a081091a23dd795e1e3c689ee512a3c82ee0dcc2643c78eea8fcacd35492558486b20f1c9ec197c90699850260c93bcbcd9c5c3317e19344e173ae36"
s = "1081b394696ffe8e6585e7a9362d26b6325f56778aadbc081c0bfbe933d52ff5823ce288e8c4f362526080df7f70ce406a6eeb1f56919cb92a9853bde73e5b4a"
self.assertSequenceEqual(hexenc(signature), s + r)
def test_gcl3(self):
- """ Test vector from libgcl3
+ """Test vector from libgcl3
"""
p = bytes2long(bytes(bytearray((
0x45, 0x31, 0xAC, 0xD1, 0xFE, 0x00, 0x23, 0xC7,
@@ -248,9 +248,9 @@ class Test34102012(TestCase):
pubX, pubY = public_key(c, prv)
self.assertSequenceEqual(long2bytes(pubX), pub_x)
self.assertSequenceEqual(long2bytes(pubY), pub_y)
- s = sign(c, prv, digest, mode=2012)
- self.assertTrue(verify(c, (pubX, pubY), digest, s, mode=2012))
- self.assertTrue(verify(c, (pubX, pubY), digest, signature, mode=2012))
+ s = sign(c, prv, digest)
+ self.assertTrue(verify(c, (pubX, pubY), digest, s))
+ self.assertTrue(verify(c, (pubX, pubY), digest, signature))
def test_sequence(self):
c = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
@@ -258,8 +258,8 @@ class Test34102012(TestCase):
pubX, pubY = public_key(c, prv)
for _ in range(20):
digest = urandom(64)
- s = sign(c, prv, digest, mode=2012)
- self.assertTrue(verify(c, (pubX, pubY), digest, s, mode=2012))
+ s = sign(c, prv, digest)
+ self.assertTrue(verify(c, (pubX, pubY), digest, s))
self.assertNotIn(b"\x00" * 8, s)
diff --git a/pygost/test_gost3410_vko.py b/pygost/test_gost3410_vko.py
index 9907759..8305350 100644
--- a/pygost/test_gost3410_vko.py
+++ b/pygost/test_gost3410_vko.py
@@ -64,9 +64,9 @@ class TestVKO34102012256(TestCase):
curve = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
ukm = ukm_unmarshal(hexdec("1d80603c8544c727"))
prvA = prv_unmarshal(hexdec("c990ecd972fce84ec4db022778f50fcac726f46708384b8d458304962d7147f8c2db41cef22c90b102f2968404f9b9be6d47c79692d81826b32b8daca43cb667"))
- pubA = pub_unmarshal(hexdec("aab0eda4abff21208d18799fb9a8556654ba783070eba10cb9abb253ec56dcf5d3ccba6192e464e6e5bcb6dea137792f2431f6c897eb1b3c0cc14327b1adc0a7914613a3074e363aedb204d38d3563971bd8758e878c9db11403721b48002d38461f92472d40ea92f9958c0ffa4c93756401b97f89fdbe0b5e46e4a4631cdb5a"), mode=2012)
+ pubA = pub_unmarshal(hexdec("aab0eda4abff21208d18799fb9a8556654ba783070eba10cb9abb253ec56dcf5d3ccba6192e464e6e5bcb6dea137792f2431f6c897eb1b3c0cc14327b1adc0a7914613a3074e363aedb204d38d3563971bd8758e878c9db11403721b48002d38461f92472d40ea92f9958c0ffa4c93756401b97f89fdbe0b5e46e4a4631cdb5a"))
prvB = prv_unmarshal(hexdec("48c859f7b6f11585887cc05ec6ef1390cfea739b1a18c0d4662293ef63b79e3b8014070b44918590b4b996acfea4edfbbbcccc8c06edd8bf5bda92a51392d0db"))
- pubB = pub_unmarshal(hexdec("192fe183b9713a077253c72c8735de2ea42a3dbc66ea317838b65fa32523cd5efca974eda7c863f4954d1147f1f2b25c395fce1c129175e876d132e94ed5a65104883b414c9b592ec4dc84826f07d0b6d9006dda176ce48c391e3f97d102e03bb598bf132a228a45f7201aba08fc524a2d77e43a362ab022ad4028f75bde3b79"), mode=2012)
+ pubB = pub_unmarshal(hexdec("192fe183b9713a077253c72c8735de2ea42a3dbc66ea317838b65fa32523cd5efca974eda7c863f4954d1147f1f2b25c395fce1c129175e876d132e94ed5a65104883b414c9b592ec4dc84826f07d0b6d9006dda176ce48c391e3f97d102e03bb598bf132a228a45f7201aba08fc524a2d77e43a362ab022ad4028f75bde3b79"))
vko = hexdec("c9a9a77320e2cc559ed72dce6f47e2192ccea95fa648670582c054c0ef36c221")
self.assertSequenceEqual(kek_34102012256(curve, prvA, pubB, ukm), vko)
self.assertSequenceEqual(kek_34102012256(curve, prvB, pubA, ukm), vko)
@@ -94,9 +94,9 @@ class TestVKO34102012512(TestCase):
curve = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
ukm = ukm_unmarshal(hexdec("1d80603c8544c727"))
prvA = prv_unmarshal(hexdec("c990ecd972fce84ec4db022778f50fcac726f46708384b8d458304962d7147f8c2db41cef22c90b102f2968404f9b9be6d47c79692d81826b32b8daca43cb667"))
- pubA = pub_unmarshal(hexdec("aab0eda4abff21208d18799fb9a8556654ba783070eba10cb9abb253ec56dcf5d3ccba6192e464e6e5bcb6dea137792f2431f6c897eb1b3c0cc14327b1adc0a7914613a3074e363aedb204d38d3563971bd8758e878c9db11403721b48002d38461f92472d40ea92f9958c0ffa4c93756401b97f89fdbe0b5e46e4a4631cdb5a"), mode=2012)
+ pubA = pub_unmarshal(hexdec("aab0eda4abff21208d18799fb9a8556654ba783070eba10cb9abb253ec56dcf5d3ccba6192e464e6e5bcb6dea137792f2431f6c897eb1b3c0cc14327b1adc0a7914613a3074e363aedb204d38d3563971bd8758e878c9db11403721b48002d38461f92472d40ea92f9958c0ffa4c93756401b97f89fdbe0b5e46e4a4631cdb5a"))
prvB = prv_unmarshal(hexdec("48c859f7b6f11585887cc05ec6ef1390cfea739b1a18c0d4662293ef63b79e3b8014070b44918590b4b996acfea4edfbbbcccc8c06edd8bf5bda92a51392d0db"))
- pubB = pub_unmarshal(hexdec("192fe183b9713a077253c72c8735de2ea42a3dbc66ea317838b65fa32523cd5efca974eda7c863f4954d1147f1f2b25c395fce1c129175e876d132e94ed5a65104883b414c9b592ec4dc84826f07d0b6d9006dda176ce48c391e3f97d102e03bb598bf132a228a45f7201aba08fc524a2d77e43a362ab022ad4028f75bde3b79"), mode=2012)
+ pubB = pub_unmarshal(hexdec("192fe183b9713a077253c72c8735de2ea42a3dbc66ea317838b65fa32523cd5efca974eda7c863f4954d1147f1f2b25c395fce1c129175e876d132e94ed5a65104883b414c9b592ec4dc84826f07d0b6d9006dda176ce48c391e3f97d102e03bb598bf132a228a45f7201aba08fc524a2d77e43a362ab022ad4028f75bde3b79"))
vko = hexdec("79f002a96940ce7bde3259a52e015297adaad84597a0d205b50e3e1719f97bfa7ee1d2661fa9979a5aa235b558a7e6d9f88f982dd63fc35a8ec0dd5e242d3bdf")
self.assertSequenceEqual(kek_34102012512(curve, prvA, pubB, ukm), vko)
self.assertSequenceEqual(kek_34102012512(curve, prvB, pubA, ukm), vko)
diff --git a/pygost/test_gost341194.py b/pygost/test_gost341194.py
index 96009b9..f4d2f1e 100644
--- a/pygost/test_gost341194.py
+++ b/pygost/test_gost341194.py
@@ -98,7 +98,7 @@ class TestVectors(TestCase):
class TestVectorsCryptoPro(TestCase):
- """ CryptoPro S-box test vectors
+ """CryptoPro S-box test vectors
"""
def test_empty(self):
self.assertSequenceEqual(
diff --git a/pygost/test_x509.py b/pygost/test_x509.py
index ce7f3ff..00ad25f 100644
--- a/pygost/test_x509.py
+++ b/pygost/test_x509.py
@@ -87,7 +87,7 @@ class TestCertificate(TestCase):
(TK26IOK.pdf)
"""
- def process_cert(self, curve_name, mode, hasher, prv_key_raw, cert_raw):
+ def process_cert(self, curve_name, hasher, prv_key_raw, cert_raw):
cert, tail = Certificate().decode(cert_raw, ctx={
"defines_by_path": (
(
@@ -115,14 +115,13 @@ class TestCertificate(TestCase):
spk = cert["tbsCertificate"]["subjectPublicKeyInfo"]["subjectPublicKey"]
self.assertIsNotNone(spk.defined)
_, pub_key_raw = spk.defined
- pub_key = pub_unmarshal(bytes(pub_key_raw), mode=mode)
+ pub_key = pub_unmarshal(bytes(pub_key_raw))
self.assertSequenceEqual(pub_key, public_key(curve, prv_key))
self.assertTrue(verify(
curve,
pub_key,
hasher(cert["tbsCertificate"].encode()).digest()[::-1],
bytes(cert["signatureValue"]),
- mode=mode,
))
def test_256(self):
@@ -144,7 +143,6 @@ dqQfmHrz6TI6Xojdh/t8ckODv/587NS5/6KsM77vc6Wh90NAT2s=
prv_key_raw = hexdec("BFCF1D623E5CDD3032A7C6EABB4A923C46E43D640FFEAAF2C3ED39A8FA399924")[::-1]
self.process_cert(
"id-GostR3410-2001-CryptoPro-XchA-ParamSet",
- 2001,
GOST34112012256,
prv_key_raw,
cert_raw,
@@ -172,7 +170,6 @@ o3eUNFkNyHJwQCk2WoOlO16zwGk2tdKH4KmD5w==
prv_key_raw = hexdec("3FC01CDCD4EC5F972EB482774C41E66DB7F380528DFE9E67992BA05AEE462435757530E641077CE587B976C8EEB48C48FD33FD175F0C7DE6A44E014E6BCB074B")[::-1]
self.process_cert(
"id-tc26-gost-3410-12-512-paramSetB",
- 2012,
GOST34112012512,
prv_key_raw,
cert_raw,
@@ -187,7 +184,6 @@ class TestRFC4491bis(TestCase):
def _test_vector(
self,
curve_name,
- mode,
hsh,
ai_spki,
ai_sign,
@@ -204,7 +200,7 @@ class TestRFC4491bis(TestCase):
prv = prv_unmarshal(prv_raw)
curve = CURVES[curve_name]
pub = public_key(curve, prv)
- pub_raw = pub_marshal(pub, mode=mode)
+ pub_raw = pub_marshal(pub)
subj = Name(("rdnSequence", RDNSequence([
RelativeDistinguishedName((
AttributeTypeAndValue((
@@ -231,7 +227,6 @@ class TestRFC4491bis(TestCase):
pub,
hsh(cri.encode()).digest()[::-1],
sign,
- mode=mode,
))
cr = CertificationRequest((
("certificationRequestInfo", cri),
@@ -268,7 +263,6 @@ class TestRFC4491bis(TestCase):
pub,
hsh(tbs.encode()).digest()[::-1],
sign,
- mode=mode,
))
cert = Certificate((
("tbsCertificate", tbs),
@@ -291,7 +285,6 @@ class TestRFC4491bis(TestCase):
pub,
hsh(tbs.encode()).digest()[::-1],
sign,
- mode=mode,
))
crl = CertificateList((
("tbsCertList", tbs),
@@ -303,7 +296,6 @@ class TestRFC4491bis(TestCase):
def test_256_test_paramset(self):
self._test_vector(
"id-GostR3410-2001-TestParamSet",
- 2001,
GOST34112012256,
AlgorithmIdentifier((
("algorithm", id_tc26_gost3410_2012_256),
@@ -349,7 +341,6 @@ RstQv19CIaADrT0XJ1PJSpw3ox0gQaoo0vGrFIKAzZ7Vb+2kGXQFNVSkJ2e4OtBD
def test_256a_paramset(self):
self._test_vector(
"id-tc26-gost-3410-2012-256-paramSetA",
- 2001,
GOST34112012256,
AlgorithmIdentifier((
("algorithm", id_tc26_gost3410_2012_256),
@@ -394,7 +385,6 @@ B/6y571v4JY/VjJnNZ9c2Oq0UFmtHQ4dpb40fG8bUlbHrqwgCtZKx3pvWzoOCXMY
def test_512_test_paramset(self):
self._test_vector(
"id-tc26-gost-3410-2012-512-paramSetTest",
- 2012,
GOST34112012512,
AlgorithmIdentifier((
("algorithm", id_tc26_gost3410_2012_512),
diff --git a/pygost/utils.py b/pygost/utils.py
index 0ec91fc..fb0ccca 100644
--- a/pygost/utils.py
+++ b/pygost/utils.py
@@ -23,7 +23,7 @@ xrange = range if version_info[0] == 3 else xrange
def strxor(a, b):
- """ XOR of two strings
+ """XOR of two strings
This function will process only shortest length of both strings,
ignoring remaining one.
@@ -52,7 +52,7 @@ def hexenc(data):
def bytes2long(raw):
- """ Deserialize big-endian bytes into long number
+ """Deserialize big-endian bytes into long number
:param bytes raw: binary string
:returns: deserialized long number
@@ -62,7 +62,7 @@ def bytes2long(raw):
def long2bytes(n, size=32):
- """ Serialize long number into big-endian bytestring
+ """Serialize long number into big-endian bytestring
:param long n: long number
:returns: serialized bytestring
@@ -78,7 +78,7 @@ def long2bytes(n, size=32):
def modinvert(a, n):
- """ Modular multiplicative inverse
+ """Modular multiplicative inverse
:returns: inverse number. -1 if it does not exist
diff --git a/www.do b/www.do
index 3406d00..b1198ba 100644
--- a/www.do
+++ b/www.do
@@ -1,9 +1,10 @@
+redo-ifchange *.texi VERSION
rm -f pygost.html/*.html
-makeinfo --html \
+${MAKEINFO:-makeinfo} --html \
+ -D "VERSION `cat VERSION`" \
--set-customization-variable EXTRA_HEAD='<link rev="made" href="mailto:webmaster@cypherpunks.ru">' \
--set-customization-variable CSS_LINES="`cat style.css`" \
--set-customization-variable SHOW_TITLE=0 \
- --set-customization-variable USE_ACCESSKEY=0 \
--set-customization-variable DATE_IN_HEADER=1 \
--set-customization-variable TOP_NODE_UP_URL=index.html \
--set-customization-variable CLOSE_QUOTE_SYMBOL=\" \
diff --git a/www.texi b/www.texi
index a7b565f..89e419f 100644
--- a/www.texi
+++ b/www.texi
@@ -81,9 +81,9 @@ Example 34.10-2012 keypair generation, signing and verifying:
>>> data_for_signing = b"some data"
>>> dgst = gost34112012256.new(data_for_signing).digest()[::-1]
>>> from pygost.gost3410 import sign
->>> signature = sign(curve, prv, dgst, mode=2012)
+>>> signature = sign(curve, prv, dgst)
>>> from pygost.gost3410 import verify
->>> verify(curve, pub, dgst, signature, mode=2012)
+>>> verify(curve, pub, dgst, signature)
True
@end example