Skip Menu |

This queue is for tickets about the File-KeePass CPAN distribution.

Report information
The Basics
Id: 82582
Status: open
Priority: 0/
Queue: File-KeePass

People
Owner: Nobody in particular
Requestors: cjm [...] cpan.org
radu.cpan-file-keepass [...] ohmi.org
radu [...] ohmi.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: Integer overflow bug in salsa20 implementation
Date: Wed, 09 Jan 2013 11:26:03 +0000
To: bug-File-KeePass [...] rt.cpan.org
From: "Radu Hociung" <radu [...] ohmi.org>
Hello, The File::KeePass module uses a salsa20 stream crypt implementation to protect the password field when stored in KeePass v2/kdbx database files. However, at the current version, 2.03, all passwords stored in v2 databases are not recoverable with File::KeePass. Also, passwords that the module writes to kdbx databases are not readable by the KeePass application (they appear garbled in KeePass). I looked into the problem, and I found the cause is that the arithmetic addition operation in the salsa20 implementation saturates to 0xffffffff in perl, while the algorithm specification expects it to wrap around. I have a temporary workaround, but I don't believe it's correct for 64-bit as well as 32-bit perls. Also building the module for CentOS with cpanspec and the enclosed patch warns that my fix is not portable. However, the patched build works correctly on my 32-bit system The fix does this substitution wherever "& 0xffffffff" occurs. Apparently modulo 0x1_0000_0000 works correctly: - $x[ 4] ^= $rotl32->(($x[ 0] + $x[12]) & 0xffffffff, 7); + $x[ 4] ^= $rotl32->(($x[ 0] + $x[12]) % 0x100000000, 7); I tested this on "perl, v5.10.1 (*) built for i386-linux-thread-multi" Please find enclosed the patch I used, as well as two simplified scripts with and without the fix, that attempt to generate a few test-vectors from http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors The file "salsa20-perl-integer-overflow/salsa20-with-integer-overflow.pl" shows wrong output and "salsa20-perl-integer-overflow/salsa20-correct.pl" shows correct output, matching the test-vectors from ecrypt. I am not a perl expert and I don't know how to properly fix the arithmetic overflow, but I trust you will be able to find a fix that works on all platforms. If I can help further, please don't hesitate to contact me. Regards Radu Hociung radu.cpan-file-keepass@ohmi.org
Download salsa20-perl-integer-overflow.tgz
application/octet-stream 2.7k

Message body not shown because it is not plain text.

Subject: Integer overflow bug in salsa20 implementation
The File::KeePass module uses a salsa20 stream crypt implementation to protect the password field when stored in KeePass v2/kdbx database files. However, at the current version, 2.03, all passwords stored in v2 databases are not recoverable with File::KeePass. Also, passwords that the module writes to kdbx databases are not readable by the KeePass application (they appear garbled in KeePass). Effectively, it corrupts v2 databases, but it still works correctly with v1 databases. I looked into the problem, and I found the cause is that the arithmetic addition operation in the salsa20 implementation saturates to 0xffffffff in perl, while the algorithm specification expects it to wrap around. I have a temporary workaround, but I don't believe it's correct for 64- bit as well as 32-bit perls. Also building the module for CentOS with cpanspec and the enclosed patch warns that my fix is not portable. However, the patched build works correctly on my 32-bit system The fix does this substitution wherever "& 0xffffffff" occurs. Apparently modulo 0x1_0000_0000 works correctly: - $x[ 4] ^= $rotl32->(($x[ 0] + $x[12]) & 0xffffffff, 7); + $x[ 4] ^= $rotl32->(($x[ 0] + $x[12]) % 0x100000000, 7); I tested this on "perl, v5.10.1 (*) built for i386-linux-thread-multi", "Linux 2.6.32-279.19.1.el6.i686 #1 SMP Wed Dec 19 04:30:58 UTC 2012 i686 i686 i386 GNU/Linux" Please find enclosed the patch I used, as well as two simplified scripts with and without the fix, that attempt to generate a few test-vectors from http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions /salsa20/full/verified.test-vectors The file "salsa20-perl-integer-overflow/salsa20-with-integer- overflow.pl" shows wrong output and "salsa20-perl-integer- overflow/salsa20-correct.pl" shows correct output, matching the test- vectors from ecrypt. I am not a perl expert and I don't know how to properly fix the arithmetic overflow, but I trust you will be able to find a fix that works on all platforms.
Subject: salsa20-perl-integer-overflow.tgz
Download salsa20-perl-integer-overflow.tgz
application/octet-stream 2.7k

Message body not shown because it is not plain text.

From: mu77ley [...] gmail.com
On Wed Jan 09 06:26:22 2013, radu@ohmi.org wrote: Show quoted text
> I have a temporary workaround, but I don't believe it's correct for > 64-bit as well as 32-bit perls. Also building the module for CentOS > with cpanspec and the enclosed patch warns that my fix is not > portable. > However, the patched build works correctly on my 32-bit system
I tried this patch, but perl complained about "Hexadecimal number > 0xffffffff non-portable at..." a lot so I reverted the patch. I have now found that just adding "use bigint;" to File/KeePass.pm appears to solve the issue and my limited testing reveals that this has no detrimental effect when running on a 64bit perl. This is with perl 5.16.1 Muttley
I have a new patch for this bug in RT#87109 (see the Links section above) that doesn't have the 0xffffffff non-portable warning or the big slowdown caused by "use bigint".