Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a4c2202

Browse files
authoredApr 4, 2022
Merge pull request #255 from tomato42/doc-generation
Doc generation
2 parents f18c6d8 + ef898fc commit a4c2202

22 files changed

+355
-88
lines changed
 

‎docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

‎docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

‎docs/source/conf.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
16+
sys.path.insert(0, os.path.abspath("../../src"))
17+
18+
19+
# -- Project information -----------------------------------------------------
20+
21+
project = "python-ecdsa"
22+
copyright = "2021, Brian Warner and Hubert Kario"
23+
author = "Brian Warner and Hubert Kario"
24+
25+
# The full version, including alpha/beta/rc tags
26+
release = "0.17.0"
27+
28+
29+
# -- General configuration ---------------------------------------------------
30+
31+
# Add any Sphinx extension module names here, as strings. They can be
32+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
33+
# ones.
34+
extensions = [
35+
"sphinx.ext.autodoc",
36+
"sphinx.ext.intersphinx",
37+
"sphinx.ext.coverage",
38+
"sphinx.ext.imgmath",
39+
"sphinx.ext.viewcode",
40+
]
41+
42+
# Add any paths that contain templates here, relative to this directory.
43+
templates_path = ["_templates"]
44+
45+
# List of patterns, relative to source directory, that match files and
46+
# directories to ignore when looking for source files.
47+
# This pattern also affects html_static_path and html_extra_path.
48+
exclude_patterns = []
49+
50+
todo_include_todos = False
51+
52+
# -- Options for HTML output -------------------------------------------------
53+
54+
# The theme to use for HTML and HTML Help pages. See the documentation for
55+
# a list of builtin themes.
56+
#
57+
html_theme = "sphinx_rtd_theme"
58+
59+
# Add any paths that contain custom static files (such as style sheets) here,
60+
# relative to this directory. They are copied after the builtin static files,
61+
# so a file named "default.css" will overwrite the builtin "default.css".
62+
html_static_path = ["_static"]
63+
64+
autodoc_default_options = {
65+
"undoc-members": True,
66+
"inherited-members": True,
67+
}
68+
69+
intersphinx_mapping = {"https://docs.python.org/": None}

‎docs/source/ecdsa.curves.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.curves module
2+
===================
3+
4+
.. automodule:: ecdsa.curves
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.der.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.der module
2+
================
3+
4+
.. automodule:: ecdsa.der
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.ecdh.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.ecdh module
2+
=================
3+
4+
.. automodule:: ecdsa.ecdh
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.ecdsa.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.ecdsa module
2+
==================
3+
4+
.. automodule:: ecdsa.ecdsa
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.ellipticcurve.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.ellipticcurve module
2+
==========================
3+
4+
.. automodule:: ecdsa.ellipticcurve
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.errors.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.errors module
2+
===================
3+
4+
.. automodule:: ecdsa.errors
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.keys.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.keys module
2+
=================
3+
4+
.. automodule:: ecdsa.keys
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.numbertheory.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.numbertheory module
2+
=========================
3+
4+
.. automodule:: ecdsa.numbertheory
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.rfc6979.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.rfc6979 module
2+
====================
3+
4+
.. automodule:: ecdsa.rfc6979
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/ecdsa.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ecdsa package
2+
=============
3+
4+
.. automodule:: ecdsa
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
Submodules
10+
----------
11+
12+
.. toctree::
13+
:maxdepth: 4
14+
15+
ecdsa.curves
16+
ecdsa.der
17+
ecdsa.ecdh
18+
ecdsa.ecdsa
19+
ecdsa.ellipticcurve
20+
ecdsa.errors
21+
ecdsa.keys
22+
ecdsa.numbertheory
23+
ecdsa.rfc6979
24+
ecdsa.util

‎docs/source/ecdsa.util.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ecdsa.util module
2+
=================
3+
4+
.. automodule:: ecdsa.util
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

‎docs/source/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. python-ecdsa documentation master file, created by
2+
sphinx-quickstart on Sat May 29 18:34:49 2021.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to python-ecdsa's documentation!
7+
========================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`

‎docs/source/modules.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
src
2+
===
3+
4+
.. toctree::
5+
:maxdepth: 4
6+
7+
ecdsa

‎src/ecdsa/_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def a2b_hex(val):
128128
raise ValueError("base16 error: %s" % e)
129129

130130
# pylint: disable=invalid-name
131-
# pylint is stupid here and deson't notice it's a function, not
131+
# pylint is stupid here and doesn't notice it's a function, not
132132
# constant
133133
bytes_to_int = int.from_bytes
134134
# pylint: enable=invalid-name

‎src/ecdsa/ecdh.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def generate_private_key(self):
116116
:raises NoCurveError: Curve must be set before key generation.
117117
118118
:return: public (verifying) key from this private key.
119-
:rtype: VerifyingKey object
119+
:rtype: VerifyingKey
120120
"""
121121
if not self.curve:
122122
raise NoCurveError("Curve must be set prior to key generation.")
@@ -135,7 +135,7 @@ def load_private_key(self, private_key):
135135
:raises InvalidCurveError: private_key curve not the same as self.curve
136136
137137
:return: public (verifying) key from this private key.
138-
:rtype: VerifyingKey object
138+
:rtype: VerifyingKey
139139
"""
140140
if not self.curve:
141141
self.curve = private_key.curve
@@ -158,7 +158,7 @@ def load_private_key_bytes(self, private_key):
158158
:raises NoCurveError: Curve must be set before loading.
159159
160160
:return: public (verifying) key from this private key.
161-
:rtype: VerifyingKey object
161+
:rtype: VerifyingKey
162162
"""
163163
if not self.curve:
164164
raise NoCurveError("Curve must be set prior to key load.")
@@ -183,7 +183,7 @@ def load_private_key_der(self, private_key_der):
183183
:raises InvalidCurveError: private_key curve not the same as self.curve
184184
185185
:return: public (verifying) key from this private key.
186-
:rtype: VerifyingKey object
186+
:rtype: VerifyingKey
187187
"""
188188
return self.load_private_key(SigningKey.from_der(private_key_der))
189189

@@ -204,7 +204,7 @@ def load_private_key_pem(self, private_key_pem):
204204
:raises InvalidCurveError: private_key curve not the same as self.curve
205205
206206
:return: public (verifying) key from this private key.
207-
:rtype: VerifyingKey object
207+
:rtype: VerifyingKey
208208
"""
209209
return self.load_private_key(SigningKey.from_pem(private_key_pem))
210210

@@ -215,7 +215,7 @@ def get_public_key(self):
215215
Needs to be sent to the remote party.
216216
217217
:return: public (verifying) key from local private key.
218-
:rtype: VerifyingKey object
218+
:rtype: VerifyingKey
219219
"""
220220
return self.private_key.get_verifying_key()
221221

@@ -310,7 +310,7 @@ def generate_sharedsecret_bytes(self):
310310
:raises NoKeyError: public_key or private_key is not set
311311
312312
:return: shared secret
313-
:rtype: byte string
313+
:rtype: bytes
314314
"""
315315
return number_to_string(
316316
self.generate_sharedsecret(), self.private_key.curve.curve.p()
@@ -323,9 +323,9 @@ def generate_sharedsecret(self):
323323
The objects needs to have both private key and received public key
324324
before generation is allowed.
325325
326-
It's the same for local and remote party.
327-
shared secret(local private key, remote public key ) ==
328-
shared secret (local public key, remote private key)
326+
It's the same for local and remote party,
327+
shared secret(local private key, remote public key) ==
328+
shared secret(local public key, remote private key)
329329
330330
:raises InvalidCurveError: public_key curve not the same as self.curve
331331
:raises NoKeyError: public_key or private_key is not set

‎src/ecdsa/ecdsa.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
11
#! /usr/bin/env python
22

33
"""
4-
Implementation of Elliptic-Curve Digital Signatures.
4+
Low level implementation of Elliptic-Curve Digital Signatures.
5+
6+
.. note ::
7+
You're most likely looking for the :py:class:`~ecdsa.keys` module.
8+
This is a low-level implementation of the ECDSA that operates on
9+
integers, not byte strings.
510
611
NOTE: This a low level implementation of ECDSA, for normal applications
712
you should be looking at the keys.py module.
813
914
Classes and methods for elliptic-curve signatures:
1015
private keys, public keys, signatures,
11-
NIST prime-modulus curves with modulus lengths of
12-
192, 224, 256, 384, and 521 bits.
16+
and definitions of prime-modulus curves.
1317
1418
Example:
1519
16-
# (In real-life applications, you would probably want to
17-
# protect against defects in SystemRandom.)
18-
from random import SystemRandom
19-
randrange = SystemRandom().randrange
20+
.. code-block:: python
2021
21-
# Generate a public/private key pair using the NIST Curve P-192:
22+
# (In real-life applications, you would probably want to
23+
# protect against defects in SystemRandom.)
24+
from random import SystemRandom
25+
randrange = SystemRandom().randrange
2226
23-
g = generator_192
24-
n = g.order()
25-
secret = randrange( 1, n )
26-
pubkey = Public_key( g, g * secret )
27-
privkey = Private_key( pubkey, secret )
27+
# Generate a public/private key pair using the NIST Curve P-192:
2828
29-
# Signing a hash value:
29+
g = generator_192
30+
n = g.order()
31+
secret = randrange( 1, n )
32+
pubkey = Public_key( g, g * secret )
33+
privkey = Private_key( pubkey, secret )
3034
31-
hash = randrange( 1, n )
32-
signature = privkey.sign( hash, randrange( 1, n ) )
35+
# Signing a hash value:
3336
34-
# Verifying a signature for a hash value:
37+
hash = randrange( 1, n )
38+
signature = privkey.sign( hash, randrange( 1, n ) )
3539
36-
if pubkey.verifies( hash, signature ):
37-
print_("Demo verification succeeded.")
38-
else:
39-
print_("*** Demo verification failed.")
40+
# Verifying a signature for a hash value:
4041
41-
# Verification fails if the hash value is modified:
42+
if pubkey.verifies( hash, signature ):
43+
print_("Demo verification succeeded.")
44+
else:
45+
print_("*** Demo verification failed.")
4246
43-
if pubkey.verifies( hash-1, signature ):
44-
print_("**** Demo verification failed to reject tampered hash.")
45-
else:
46-
print_("Demo verification correctly rejected tampered hash.")
47+
# Verification fails if the hash value is modified:
4748
48-
Version of 2009.05.16.
49+
if pubkey.verifies( hash-1, signature ):
50+
print_("**** Demo verification failed to reject tampered hash.")
51+
else:
52+
print_("Demo verification correctly rejected tampered hash.")
4953
5054
Revision history:
5155
2005.12.31 - Initial version.
56+
5257
2008.11.25 - Substantial revisions introducing new classes.
58+
5359
2009.05.16 - Warn against using random.randrange in real applications.
60+
5461
2009.05.17 - Use random.SystemRandom by default.
5562
56-
Written in 2005 by Peter Pearson and placed in the public domain.
63+
Originally written in 2005 by Peter Pearson and placed in the public domain,
64+
modified as part of the python-ecdsa package.
5765
"""
5866

5967
from six import int2byte, b
@@ -72,16 +80,26 @@ class InvalidPointError(RuntimeError):
7280

7381

7482
class Signature(object):
75-
"""ECDSA signature."""
83+
"""
84+
ECDSA signature.
85+
86+
:ivar int r: the ``r`` element of the ECDSA signature
87+
:ivar int s: the ``s`` element of the ECDSA signature
88+
"""
7689

7790
def __init__(self, r, s):
7891
self.r = r
7992
self.s = s
8093

8194
def recover_public_keys(self, hash, generator):
82-
"""Returns two public keys for which the signature is valid
83-
hash is signed hash
84-
generator is the used generator of the signature
95+
"""
96+
Returns two public keys for which the signature is valid
97+
98+
:param int hash: signed hash
99+
:param AbstractPoint generator: is the generator used in creation
100+
of the signature
101+
:rtype: tuple(Public_key, Public_key)
102+
:return: a pair of public keys that can validate the signature
85103
"""
86104
curve = generator.curve()
87105
n = generator.order()

‎src/ecdsa/ellipticcurve.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def from_bytes(
342342
:param data: single point encoding of the public key
343343
:type data: :term:`bytes-like object`
344344
:param curve: the curve on which the public key is expected to lay
345-
:type curve: ecdsa.ellipticcurve.CurveFp
345+
:type curve: ~ecdsa.ellipticcurve.CurveFp
346346
:param validate_encoding: whether to verify that the encoding of the
347347
point is self-consistent, defaults to True, has effect only
348348
on ``hybrid`` encoding
@@ -353,8 +353,8 @@ def from_bytes(
353353
name). All formats by default (specified with ``None``).
354354
:type valid_encodings: :term:`set-like object`
355355
356-
:raises MalformedPointError: if the public point does not lay on the
357-
curve or the encoding is invalid
356+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
357+
not lay on the curve or the encoding is invalid
358358
359359
:return: x and y coordinates of the encoded point
360360
:rtype: tuple(int, int)
@@ -547,7 +547,7 @@ def from_bytes(
547547
:param data: single point encoding of the public key
548548
:type data: :term:`bytes-like object`
549549
:param curve: the curve on which the public key is expected to lay
550-
:type curve: ecdsa.ellipticcurve.CurveFp
550+
:type curve: ~ecdsa.ellipticcurve.CurveFp
551551
:param validate_encoding: whether to verify that the encoding of the
552552
point is self-consistent, defaults to True, has effect only
553553
on ``hybrid`` encoding
@@ -563,8 +563,8 @@ def from_bytes(
563563
such, it will be commonly used with scalar multiplication. This
564564
will cause to precompute multiplication table generation for it
565565
566-
:raises MalformedPointError: if the public point does not lay on the
567-
curve or the encoding is invalid
566+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
567+
not lay on the curve or the encoding is invalid
568568
569569
:return: Point on curve
570570
:rtype: PointJacobi
@@ -1110,7 +1110,7 @@ def from_bytes(
11101110
:param data: single point encoding of the public key
11111111
:type data: :term:`bytes-like object`
11121112
:param curve: the curve on which the public key is expected to lay
1113-
:type curve: ecdsa.ellipticcurve.CurveFp
1113+
:type curve: ~ecdsa.ellipticcurve.CurveFp
11141114
:param validate_encoding: whether to verify that the encoding of the
11151115
point is self-consistent, defaults to True, has effect only
11161116
on ``hybrid`` encoding
@@ -1123,8 +1123,8 @@ def from_bytes(
11231123
:param int order: the point order, must be non zero when using
11241124
generator=True
11251125
1126-
:raises MalformedPointError: if the public point does not lay on the
1127-
curve or the encoding is invalid
1126+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
1127+
not lay on the curve or the encoding is invalid
11281128
11291129
:return: Point on curve
11301130
:rtype: Point
@@ -1320,8 +1320,8 @@ def from_bytes(
13201320
this will cause the library to pre-compute some values to
13211321
make repeated usages of the point much faster
13221322
1323-
:raises MalformedPointError: if the public point does not lay on the
1324-
curve or the encoding is invalid
1323+
:raises `~ecdsa.errors.MalformedPointError`: if the public point does
1324+
not lay on the curve or the encoding is invalid
13251325
13261326
:return: Initialised point on an Edwards curve
13271327
:rtype: PointEdwards

‎src/ecdsa/keys.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@
5757
portable and cross-platform way.
5858
5959
bytes-like object
60-
All the types that implement the buffer protocol. That includes ``str``
61-
(only on python2), ``bytes``, ``bytesarray``, ``array.array` and
62-
``memoryview`` of those objects. Please note that ``array.array`
63-
serialisation (converting it to byte string) is endianness dependent!
64-
Signature computed over ``array.array`` of integers on a big-endian
65-
system will not be verified on a little-endian system and vice-versa.
60+
All the types that implement the buffer protocol. That includes
61+
``str`` (only on python2), ``bytes``, ``bytesarray``, ``array.array``
62+
and ``memoryview`` of those objects.
63+
Please note that ``array.array`` serialisation (converting it to byte
64+
string) is endianess dependant! Signature computed over ``array.array``
65+
of integers on a big-endian system will not be verified on a
66+
little-endian system and vice-versa.
6667
6768
set-like object
6869
All the types that support the ``in`` operator, like ``list``,
@@ -159,13 +160,13 @@ class VerifyingKey(object):
159160
"""
160161
Class for handling keys that can verify signatures (public keys).
161162
162-
:ivar ecdsa.curves.Curve curve: The Curve over which all the cryptographic
163-
operations will take place
163+
:ivar `~ecdsa.curves.Curve` ~.curve: The Curve over which all the
164+
cryptographic operations will take place
164165
:ivar default_hashfunc: the function that will be used for hashing the
165166
data. Should implement the same API as hashlib.sha1
166167
:vartype default_hashfunc: callable
167168
:ivar pubkey: the actual public key
168-
:vartype pubkey: ecdsa.ecdsa.Public_key
169+
:vartype pubkey: ~ecdsa.ecdsa.Public_key
169170
"""
170171

171172
def __init__(self, _error__please_use_generate=None):
@@ -208,13 +209,13 @@ def from_public_point(
208209
This is a low-level method, generally you will not want to use it.
209210
210211
:param point: The point to wrap around, the actual public key
211-
:type point: ecdsa.ellipticcurve.Point
212+
:type point: ~ecdsa.ellipticcurve.AbstractPoint
212213
:param curve: The curve on which the point needs to reside, defaults
213214
to NIST192p
214-
:type curve: ecdsa.curves.Curve
215+
:type curve: ~ecdsa.curves.Curve
215216
:param hashfunc: The default hash function that will be used for
216217
verification, needs to implement the same interface
217-
as hashlib.sha1
218+
as :py:class:`hashlib.sha1`
218219
:type hashfunc: callable
219220
:type bool validate_point: whether to check if the point lays on curve
220221
should always be used if the public point is not a result
@@ -308,7 +309,7 @@ def from_string(
308309
:param string: single point encoding of the public key
309310
:type string: :term:`bytes-like object`
310311
:param curve: the curve on which the public key is expected to lay
311-
:type curve: ecdsa.curves.Curve
312+
:type curve: ~ecdsa.curves.Curve
312313
:param hashfunc: The default hash function that will be used for
313314
verification, needs to implement the same interface as
314315
hashlib.sha1. Ignored for EdDSA.
@@ -372,7 +373,7 @@ def from_pem(
372373
By default :term:`uncompressed`, :term:`compressed`, and
373374
:term:`hybrid`. To read malformed files, include
374375
:term:`raw encoding` with ``raw`` in the list.
375-
:type valid_encodings: :term:`set-like object
376+
:type valid_encodings: :term:`set-like object`
376377
:param valid_curve_encodings: list of allowed encoding formats
377378
for curve parameters. By default (``None``) all are supported:
378379
``named_curve`` and ``explicit``.
@@ -425,7 +426,7 @@ def from_der(
425426
By default :term:`uncompressed`, :term:`compressed`, and
426427
:term:`hybrid`. To read malformed files, include
427428
:term:`raw encoding` with ``raw`` in the list.
428-
:type valid_encodings: :term:`set-like object
429+
:type valid_encodings: :term:`set-like object`
429430
:param valid_curve_encodings: list of allowed encoding formats
430431
for curve parameters. By default (``None``) all are supported:
431432
``named_curve`` and ``explicit``.
@@ -499,7 +500,7 @@ def from_public_key_recovery(
499500
:param data: the data to be hashed for signature verification
500501
:type data: bytes-like object
501502
:param curve: the curve over which the signature was performed
502-
:type curve: ecdsa.curves.Curve
503+
:type curve: ~ecdsa.curves.Curve
503504
:param hashfunc: The default hash function that will be used for
504505
verification, needs to implement the same interface as hashlib.sha1
505506
:type hashfunc: callable
@@ -551,7 +552,7 @@ def from_public_key_recovery_with_digest(
551552
:param digest: the hash value of the message signed by the signature
552553
:type digest: bytes-like object
553554
:param curve: the curve over which the signature was performed
554-
:type curve: ecdsa.curves.Curve
555+
:type curve: ~ecdsa.curves.Curve
555556
:param hashfunc: The default hash function that will be used for
556557
verification, needs to implement the same interface as hashlib.sha1
557558
:type hashfunc: callable
@@ -800,14 +801,14 @@ class SigningKey(object):
800801
"""
801802
Class for handling keys that can create signatures (private keys).
802803
803-
:ivar ecdsa.curves.Curve curve: The Curve over which all the cryptographic
804-
operations will take place
804+
:ivar `~ecdsa.curves.Curve` ~.curve: The Curve over which all the
805+
cryptographic operations will take place
805806
:ivar default_hashfunc: the function that will be used for hashing the
806-
data. Should implement the same API as hashlib.sha1
807+
data. Should implement the same API as :py:class:`hashlib.sha1`
807808
:ivar int baselen: the length of a :term:`raw encoding` of private key
808-
:ivar ecdsa.keys.VerifyingKey verifying_key: the public key
809+
:ivar `~ecdsa.keys.VerifyingKey` verifying_key: the public key
809810
associated with this private key
810-
:ivar ecdsa.ecdsa.Private_key privkey: the actual private key
811+
:ivar `~ecdsa.ecdsa.Private_key` privkey: the actual private key
811812
"""
812813

813814
def __init__(self, _error__please_use_generate=None):
@@ -868,7 +869,7 @@ def generate(cls, curve=NIST192p, entropy=None, hashfunc=sha1):
868869
869870
:param curve: The curve on which the point needs to reside, defaults
870871
to NIST192p
871-
:type curve: ecdsa.curves.Curve
872+
:type curve: ~ecdsa.curves.Curve
872873
:param entropy: Source of randomness for generating the private keys,
873874
should provide cryptographically secure random numbers if the keys
874875
need to be secure. Uses os.urandom() by default.
@@ -896,7 +897,7 @@ def from_secret_exponent(cls, secexp, curve=NIST192p, hashfunc=sha1):
896897
:param int secexp: secret multiplier (the actual private key in ECDSA).
897898
Needs to be an integer between 1 and the curve order.
898899
:param curve: The curve on which the point needs to reside
899-
:type curve: ecdsa.curves.Curve
900+
:type curve: ~ecdsa.curves.Curve
900901
:param hashfunc: The default hash function that will be used for
901902
signing, needs to implement the same interface
902903
as hashlib.sha1
@@ -948,7 +949,7 @@ def from_string(cls, string, curve=NIST192p, hashfunc=sha1):
948949
:param string: the raw encoding of the private key
949950
:type string: bytes like object
950951
:param curve: The curve on which the point needs to reside
951-
:type curve: ecdsa.curves.Curve
952+
:type curve: ~ecdsa.curves.Curve
952953
:param hashfunc: The default hash function that will be used for
953954
signing, needs to implement the same interface
954955
as hashlib.sha1
@@ -1063,7 +1064,7 @@ def from_der(cls, string, hashfunc=sha1, valid_curve_encodings=None):
10631064
is part of the PrivateKeyAlgorithmIdentifier.
10641065
10651066
The PKCS #8 format includes an ECPrivateKey object as the `privateKey`
1066-
field within a larger structure:
1067+
field within a larger structure::
10671068
10681069
OneAsymmetricKey ::= SEQUENCE {
10691070
version Version,

‎src/ecdsa/rfc6979.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ def bits2octets(data, order):
4242
# https://tools.ietf.org/html/rfc6979#section-3.2
4343
def generate_k(order, secexp, hash_func, data, retry_gen=0, extra_entropy=b""):
4444
"""
45-
order - order of the DSA generator used in the signature
46-
secexp - secure exponent (private key) in numeric form
47-
hash_func - reference to the same hash function used for generating
48-
hash
49-
data - hash in binary form of the signing data
50-
retry_gen - int - how many good 'k' values to skip before returning
51-
extra_entropy - extra added data in binary form as per section-3.6 of
52-
rfc6979
45+
Generate the ``k`` value - the nonce for DSA.
46+
47+
:param int order: order of the DSA generator used in the signature
48+
:param int secexp: secure exponent (private key) in numeric form
49+
:param hash_func: reference to the same hash function used for generating
50+
hash, like :py:class:`hashlib.sha1`
51+
:param bytes data: hash in binary form of the signing data
52+
:param int retry_gen: how many good 'k' values to skip before returning
53+
:param bytes extra_entropy: additional added data in binary form as per
54+
section-3.6 of rfc6979
55+
:rtype: int
5356
"""
5457

5558
qlen = bit_length(order)

0 commit comments

Comments
 (0)
Please sign in to comment.