Skip to content
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
51 changes: 51 additions & 0 deletions pkgs/development/python-modules/pyaes/default-iv.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From 034c7eea63a155582109233d2fc1de8e14121908 Mon Sep 17 00:00:00 2001
From: Martin Weinelt <hexa@darmstadt.ccc.de>
Date: Mon, 2 Mar 2026 12:55:44 +0100
Subject: [PATCH] Raise on default IV

This disables the static default IV for CBC, CFB and OFB by raising when
not IV gets passed. We make sure not to break the API contract this way,
so that existing consumers who rely on the default IV get a useful
exception message instead of an API break, which could be done in a
future version.

In CBC mode an IV cannot be predictable or it breaks IND-CPA, this is
also described as CWE-329.

In CFB and OFB mode an IV still requires to be unique, which does not
really hold when initializing it statically.
---
pyaes/aes.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pyaes/aes.py b/pyaes/aes.py
index c6e8bc0..fd25547 100644
--- a/pyaes/aes.py
+++ b/pyaes/aes.py
@@ -376,7 +376,7 @@ class AESModeOfOperationCBC(AESBlockModeOfOperation):

def __init__(self, key, iv = None):
if iv is None:
- self._last_cipherblock = [ 0 ] * 16
+ raise ValueError("Missing IV parameter. This is a security problem, see https://github.com/ricmoo/pyaes/issues/56.")
elif len(iv) != 16:
raise ValueError('initialization vector must be 16 bytes')
else:
@@ -423,7 +423,7 @@ def __init__(self, key, iv, segment_size = 1):
if segment_size == 0: segment_size = 1

if iv is None:
- self._shift_register = [ 0 ] * 16
+ raise ValueError("Missing IV parameter. This is a security problem, see https://github.com/ricmoo/pyaes/issues/56.")
elif len(iv) != 16:
raise ValueError('initialization vector must be 16 bytes')
else:
@@ -495,7 +495,7 @@ class AESModeOfOperationOFB(AESStreamModeOfOperation):

def __init__(self, key, iv = None):
if iv is None:
- self._last_precipherblock = [ 0 ] * 16
+ raise ValueError("Missing IV parameter. This is a security problem, see https://github.com/ricmoo/pyaes/issues/56.")
elif len(iv) != 16:
raise ValueError('initialization vector must be 16 bytes')
else:
6 changes: 6 additions & 0 deletions pkgs/development/python-modules/pyaes/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ buildPythonPackage rec {
sha256 = "02c1b1405c38d3c370b085fb952dd8bea3fadcee6411ad99f312cc129c536d8f";
};

patches = [
# https://github.com/ricmoo/pyaes/issues/56
# https://blog.trailofbits.com/2026/02/18/carelessness-versus-craftsmanship-in-cryptography/
./default-iv.patch
];

meta = {
description = "Pure-Python AES";
license = lib.licenses.mit;
Expand Down
Loading