Bugs: Browse | Submit New | Admin

[#20796] Ciphtertext Is (Incorrectly) Null-Terminated

Date:
2008-06-23 19:09
Priority:
3
Submitted By:
foo foo (hawleyal)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Ciphtertext Is (Incorrectly) Null-Terminated

Detailed description
The ciphertext output from "Aes.encrypt_buffer" is (incorrectly) null-terminated. That is, it contains an
extra null character.

Using "ruby-aes-normal-1.1" version.

This code:
........................................

require 'ruby-aes'

pt0 = "\x80" + ("\x0" * 15)
puts "pt0: #{pt0.inspect}"
puts "pt0 length: #{pt0.length}"
puts "pt0 hex: #{pt0.unpack('H2' * (pt0.length / 2 * 8)).join}"

mode = 'ECB'
puts "mode: #{mode}"

key = ('0' * (128 / 8 * 2))
puts "key: #{key}"
puts "key length: #{key.length / 2 * 8}"

iv = ('0' * (128 / 8 * 2))
puts "iv: #{iv}"

ct = Aes.encrypt_buffer((key.length / 2 * 8), mode, key, iv, pt0)
puts "ct: #{ct.inspect}"
puts "ct length: #{ct.length}"
puts "ct hex: #{(ct.unpack('H2' * (ct.length / 2 * 8)).join).upcase}"

pt1 = Aes.decrypt_buffer((key.length / 2 * 8), mode, key, iv, ct)
puts "pt1: #{pt1.inspect}"
puts "pt1 length: #{pt1.length}"
puts "pt1 hex: #{pt1.unpack('H2' * (pt1.length / 2 * 8)).join}"
........................................

Produces this output:
........................................

pt0: "\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
pt0 length: 16
pt0 hex: 80000000000000000000000000000000
mode: ECB
key: 00000000000000000000000000000000
key length: 128
iv: 00000000000000000000000000000000
ct: ":\327\216rl\036\300+~\277\351+#\331\3544\000"
ct length: 17
ct hex: 3AD78E726C1EC02B7EBFE92B23D9EC3400
pt1: "\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
pt1 length: 16
pt1 hex: 80000000000000000000000000000000
........................................

From the NIST test vectors:
........................................

KEYSIZE=128
KEY=00000000000000000000000000000000
PT=80000000000000000000000000000000
CT=3AD78E726C1EC02B7EBFE92B23D9EC34
........................................

Thanks.


-AH

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item