Patches: Browse | Submit New | Admin

[#8448] Block padding fix

Date:
2007-02-06 09:48
Priority:
3
Submitted By:
Daniel Brahneborg (basic)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Block padding fix

Detailed description
Hi,

When using this library to talk to an OpenSSL server, I needed this little fix to get the padding right.

/Daniel

--- /usr/lib/ruby/gems/1.8/gems/crypt-1.1.4/crypt/cbc.rb.orig   2007-02-06 10:40:54.000000000 +0100
+++ /usr/lib/ruby/gems/1.8/gems/crypt-1.1.4/crypt/cbc.rb        2007-02-06 10:41:37.000000000 +0100
@@ -43,10 +43,8 @@
     # bytes in the final block
     block = '' if block.nil?
     buffer = block.split('')
-    remainingMessageBytes = buffer.length
-    # we use 7-bit characters to avoid possible strange behavior on the Mac
-    remainingMessageBytes.upto(block_size()-2) { buffer << rand(128).chr }
-    buffer << remainingMessageBytes.chr
+    remainingMessageBytes = block_size() - buffer.length
+    buffer << remainingMessageBytes.chr * remainingMessageBytes
     block = buffer.join('')
     block = block ^ chain
     encrypted = encrypt_block(block)
@@ -67,7 +65,7 @@

     # write the final block, omitting the padding
     buffer = plainText.split('')
-    remainingMessageBytes = buffer.last.unpack('C').first
+    remainingMessageBytes = block_size() - buffer.last.unpack('C').first
     remainingMessageBytes.times { plainStream.write(buffer.shift) }
   end

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-02-09 06:50
Sender: Daniel Brahneborg

This one works better, adding an optional with_padding
parameter, that should be set to false for blocks that
are sent without the final padding.

/Daniel

Attached Files:

Name Description Download
padding.patch Patch file, adding with_padding parameter Download

Changes:

Field Old Value Date By
File Added1228: padding.patch2007-02-09 06:50basic