Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Paint it Black by the Rolling Stones #5324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/download_openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
def get_response(session, url, token):
response = session.get(url, headers={"Authorization": "token " + token})
if response.status_code != 200:
raise ValueError("Got HTTP {} fetching {}: ".format(
response.status_code, url
))
raise ValueError(
"Got HTTP {} fetching {}: ".format(response.status_code, url)
)
return response


Expand All @@ -28,9 +28,7 @@ def main(platform, target):
raise ValueError("Invalid platform")

session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
max_retries=Retry()
)
adapter = requests.adapters.HTTPAdapter(max_retries=Retry())
session.mount("https://", adapter)
session.mount("http://", adapter)

Expand Down
72 changes: 43 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath("."))

# -- General configuration ----------------------------------------------------

Expand All @@ -45,33 +45,33 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'cryptography-docs',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"cryptography-docs",
]

if spelling is not None:
extensions.append('sphinxcontrib.spelling')
extensions.append("sphinxcontrib.spelling")

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

nitpicky = True

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'Cryptography'
copyright = '2013-2017, Individual Contributors'
project = "Cryptography"
copyright = "2013-2017, Individual Contributors"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -81,7 +81,7 @@
base_dir = os.path.join(os.path.dirname(__file__), os.pardir)
about = {}
with open(os.path.join(base_dir, "src", "cryptography", "__about__.py")) as f:
exec(f.read(), about)
exec (f.read(), about)

version = release = about["__version__"]

Expand All @@ -97,7 +97,7 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]

# The reST default role (used for this markup: `text`) to use for all documents
# default_role = None
Expand All @@ -114,7 +114,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# -- Options for HTML output --------------------------------------------------

Expand All @@ -130,31 +130,40 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Output file base name for HTML help builder.
htmlhelp_basename = 'Cryptographydoc'
htmlhelp_basename = "Cryptographydoc"


# -- Options for LaTeX output -------------------------------------------------

latex_elements = {
}
latex_elements = {}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual])
latex_documents = [
('index', 'Cryptography.tex', 'Cryptography Documentation',
'Individual Contributors', 'manual'),
(
"index",
"Cryptography.tex",
"Cryptography Documentation",
"Individual Contributors",
"manual",
),
]

# -- Options for manual page output -------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'cryptography', 'Cryptography Documentation',
['Individual Contributors'], 1)
(
"index",
"cryptography",
"Cryptography Documentation",
["Individual Contributors"],
1,
)
]

# -- Options for Texinfo output -----------------------------------------------
Expand All @@ -163,16 +172,21 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Cryptography', 'Cryptography Documentation',
'Individual Contributors', 'Cryptography',
'One line description of project.',
'Miscellaneous'),
(
"index",
"Cryptography",
"Cryptography Documentation",
"Individual Contributors",
"Cryptography",
"One line description of project.",
"Miscellaneous",
),
]

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/3': None}
intersphinx_mapping = {"https://docs.python.org/3": None}

epub_theme = 'epub'
epub_theme = "epub"

# Retry requests in the linkcheck builder so that we're resillient against
# transient network errors.
Expand Down
51 changes: 30 additions & 21 deletions docs/development/custom-vectors/arc4/generate_arc4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@


_RFC6229_KEY_MATERIALS = [
(True,
8 * '0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20'),
(False,
8 * '1ada31d5cf688221c109163908ebe51debb46227c6cc8b37641910833222772a')
(
True,
8 * "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20",
),
(
False,
8 * "1ada31d5cf688221c109163908ebe51debb46227c6cc8b37641910833222772a",
),
]


Expand All @@ -37,62 +41,67 @@
3056,
3072,
4080,
4096
4096,
]


_SIZES_TO_GENERATE = [
160
]
_SIZES_TO_GENERATE = [160]


def _key_for_size(size, keyinfo):
msb, key = keyinfo
if msb:
return key[:size // 4]
return key[: size // 4]
else:
return key[-size // 4:]
return key[-size // 4 :]


def _build_vectors():
count = 0
output = []
key = None
plaintext = binascii.unhexlify(32 * '0')
plaintext = binascii.unhexlify(32 * "0")
for size in _SIZES_TO_GENERATE:
for keyinfo in _RFC6229_KEY_MATERIALS:
key = _key_for_size(size, keyinfo)
cipher = ciphers.Cipher(
algorithms.ARC4(binascii.unhexlify(key)),
None,
default_backend())
default_backend(),
)
encryptor = cipher.encryptor()
current_offset = 0
for offset in _RFC6229_OFFSETS:
if offset % 16 != 0:
raise ValueError(
"Offset {} is not evenly divisible by 16"
.format(offset))
"Offset {} is not evenly divisible by 16".format(
offset
)
)
while current_offset < offset:
encryptor.update(plaintext)
current_offset += len(plaintext)
output.append("\nCOUNT = {}".format(count))
count += 1
output.append("KEY = {}".format(key))
output.append("OFFSET = {}".format(offset))
output.append("PLAINTEXT = {}".format(
binascii.hexlify(plaintext)))
output.append("CIPHERTEXT = {}".format(
binascii.hexlify(encryptor.update(plaintext))))
output.append(
"PLAINTEXT = {}".format(binascii.hexlify(plaintext))
)
output.append(
"CIPHERTEXT = {}".format(
binascii.hexlify(encryptor.update(plaintext))
)
)
current_offset += len(plaintext)
assert not encryptor.finalize()
return "\n".join(output)


def _write_file(data, filename):
with open(filename, 'w') as f:
with open(filename, "w") as f:
f.write(data)


if __name__ == '__main__':
_write_file(_build_vectors(), 'arc4.txt')
if __name__ == "__main__":
_write_file(_build_vectors(), "arc4.txt")
8 changes: 5 additions & 3 deletions docs/development/custom-vectors/cast5/generate_cast5.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def encrypt(mode, key, iv, plaintext):
cipher = base.Cipher(
algorithms.CAST5(binascii.unhexlify(key)),
mode(binascii.unhexlify(iv)),
default_backend()
default_backend(),
)
encryptor = cipher.encryptor()
ct = encryptor.update(binascii.unhexlify(plaintext))
Expand All @@ -34,8 +34,10 @@ def build_vectors(mode, filename):
line = line.strip()
if line.startswith("KEY"):
if count != 0:
output.append("CIPHERTEXT = {}".format(
encrypt(mode, key, iv, plaintext))
output.append(
"CIPHERTEXT = {}".format(
encrypt(mode, key, iv, plaintext)
)
)
output.append("\nCOUNT = {}".format(count))
count += 1
Expand Down
16 changes: 10 additions & 6 deletions docs/development/custom-vectors/hkdf/generate_hkdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
IKM = binascii.unhexlify(b"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
L = 1200
OKM = HKDF(
algorithm=hashes.SHA256(), length=L, salt=None, info=None,
backend=default_backend()
algorithm=hashes.SHA256(),
length=L,
salt=None,
info=None,
backend=default_backend(),
).derive(IKM)


Expand All @@ -23,17 +26,18 @@ def _build_vectors():
"COUNT = 0",
"Hash = SHA-256",
"IKM = " + binascii.hexlify(IKM).decode("ascii"),
"salt = ", "info = ",
"salt = ",
"info = ",
"L = {}".format(L),
"OKM = " + binascii.hexlify(OKM).decode("ascii"),
]
return "\n".join(output)


def _write_file(data, filename):
with open(filename, 'w') as f:
with open(filename, "w") as f:
f.write(data)


if __name__ == '__main__':
_write_file(_build_vectors(), 'hkdf.txt')
if __name__ == "__main__":
_write_file(_build_vectors(), "hkdf.txt")
8 changes: 5 additions & 3 deletions docs/development/custom-vectors/idea/generate_idea.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def encrypt(mode, key, iv, plaintext):
cipher = base.Cipher(
algorithms.IDEA(binascii.unhexlify(key)),
mode(binascii.unhexlify(iv)),
backend
backend,
)
encryptor = cipher.encryptor()
ct = encryptor.update(binascii.unhexlify(plaintext))
Expand All @@ -29,8 +29,10 @@ def build_vectors(mode, filename):
line = line.strip()
if line.startswith("KEY"):
if count != 0:
output.append("CIPHERTEXT = {0}".format(
encrypt(mode, key, iv, plaintext))
output.append(
"CIPHERTEXT = {0}".format(
encrypt(mode, key, iv, plaintext)
)
)
output.append("\nCOUNT = {0}".format(count))
count += 1
Expand Down
17 changes: 7 additions & 10 deletions docs/development/custom-vectors/idea/verify_idea.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@


def encrypt(mode, key, iv, plaintext):
encryptor = botan.Cipher("IDEA/{0}/NoPadding".format(mode), "encrypt",
binascii.unhexlify(key))
encryptor = botan.Cipher(
"IDEA/{0}/NoPadding".format(mode), "encrypt", binascii.unhexlify(key)
)

cipher_text = encryptor.cipher(binascii.unhexlify(plaintext),
binascii.unhexlify(iv))
cipher_text = encryptor.cipher(
binascii.unhexlify(plaintext), binascii.unhexlify(iv)
)
return binascii.hexlify(cipher_text)


Expand All @@ -22,12 +24,7 @@ def verify_vectors(mode, filename):

vectors = load_nist_vectors(vector_file)
for vector in vectors:
ct = encrypt(
mode,
vector["key"],
vector["iv"],
vector["plaintext"]
)
ct = encrypt(mode, vector["key"], vector["iv"], vector["plaintext"])
assert ct == vector["ciphertext"]


Expand Down
Loading