-
Notifications
You must be signed in to change notification settings - Fork 1.7k
PKCS7 padding #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PKCS7 padding #192
Conversation
Docs are missing for |
For reference, work is almost exclusively donalds :) |
Also the inner loops of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we think these helper functions should be left out similarly to encrypt()
and decrypt()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they make sense here, there's not really any other alternative
parameters or whatever you'd have.
On Tue, Oct 29, 2013 at 11:00 AM, Donald Stufft notifications@github.comwrote:
In cryptography/hazmat/primitives/padding.py:
super(PKCS7, self).**init**()
if not (0 <= block_size < 256):
raise ValueError("block_size must be in range(0, 256)")
if block_size % 8 != 0:
raise ValueError("block_size must be a multiple of 8")
self.block_size = block_size
- def padder(self):
return _PaddingContext(self.block_size)
- def unpadder(self):
return _UnpaddingContext(self.block_size)
- def pad(self, data):
Do we think these helper functions should be left out similarly to
encrypt() and decrypt() ?—
Reply to this email directly or view it on GitHubhttps://github.com//pull/192/files#r7288249
.
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be documented as returning an object that conforms to some ABC? Maybe even just CipherContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raising early like this leads to a timing side-channel in the padding validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We looked at the OpenSSL implementation, it also bails immediately.
On Tue, Oct 29, 2013 at 11:58 AM, Alex Stapleton
notifications@github.comwrote:
In cryptography/hazmat/primitives/padding.py:
return result
- def finalize(self):
if self._buffer is None:
raise ValueError("Context was already finalized")
if not self._buffer:
raise ValueError("Invalid padding bytes")
pad_size = six.indexbytes(self._buffer, -1)
if pad_size > self.block_size // 8:
raise ValueError("Invalid padding bytes")
for b in six.iterbytes(self._buffer[-pad_size:]):
if b != pad_size:
raising early like this leads to a timing side-channel in the padding
validation?—
Reply to this email directly or view it on GitHubhttps://github.com//pull/192/files#r7290507
.
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which implementation? tls1_cbc_remove_padding (which removes the almost but not quite PKCS5 padding in TLS) was specifically updated with constant time fixes to mitigate Lucky 13. Maybe they didn't copy this over to the PKCS5/7 verification too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PKCS7 is easily turned into a padding oracle if the encryption is malleable. TLS' problem, if I recall correctly, is that it doesn't verify the MAC before unpadding the message. Exploiting this, in a properly designed system, would require being able to forge the MAC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That exposes the flaw in the padding verification yes.
Assuming that all users will be implementing properly designed systems seems optimistic to me and avoiding known timing channels is in the list of things we are meant to be avoiding :)
The constant time version isn't terrifyingly complicated. I'm happy to port it over unless the consensus is that it's not worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does http://bpaste.net/show/144990/ address your concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
Sent with AquaMail for Android
http://www.aqua-mail.com
On October 29, 2013 9:34:44 PM Alex Gaynor notifications@github.com wrote:
return result
- def finalize(self):
if self._buffer is None:
raise ValueError("Context was already finalized")
if not self._buffer:
raise ValueError("Invalid padding bytes")
pad_size = six.indexbytes(self._buffer, -1)
if pad_size > self.block_size // 8:
raise ValueError("Invalid padding bytes")
for b in six.iterbytes(self._buffer[-pad_size:]):
if b != pad_size:
Does http://bpaste.net/show/144990/ address your concern?
Reply to this email directly or view it on GitHub:
https://github.com/pyca/cryptography/pull/192/files#r7295565
padder()
andunpadder()
update()
PKCS7(128)
, calling itpadder
is confusing