POK Flag Weirdness wth binary files

W

Wayne Myers

Hi,

(Apologies for repost; this was originally sent to comp.lang.perl, which
turns out to be widely considered not to exist, whatever Google thinks)

This week I got bitten by something very strange. I was writing
code that needed to decrypt something encrypted using Rijndael
encryption, but when I read the key in, for some reason, the
Crypt::Rijndael module refused to accept the key as a valid
scalar string.

Digging around in the Crypt::Rijndael code and testing the string
with Devel::peek revealed that no matter what method I used to
read the key (a stream of random binary digits), the internal POK
flag was not being set. Crypt::Rijndael explicitly tests the POK
flag before accepting a key: this is why that was failing.

However, I am not the first person to come across this problem,
and found an extremely strange workaround here:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&th=b088f2ae7045eb62&seekm=3CE
+0C77A.5030404%40hexaflux.com&frame=off

I have written a short script reproducing the problem (under Perl
5.6.1 and Perl 5.8.3) and demonstrating the same workaround, here:

http://www.waz.easynet.co.uk/pok/pok.pl.txt

Is it a bug in Perl, a bug in Crypt::Rijndael, or a bug in my
understanding of how to read in binary files?

I'd be grateful if anyone could help me shed light on the matter

Cheers etc.,

Wayne
 
B

Ben Morrow

Quoth (e-mail address removed) (Wayne Myers):
This week I got bitten by something very strange. I was writing
code that needed to decrypt something encrypted using Rijndael
encryption, but when I read the key in, for some reason, the
Crypt::Rijndael module refused to accept the key as a valid
scalar string.

I have written a short script reproducing the problem (under Perl
5.6.1 and Perl 5.8.3) and demonstrating the same workaround, here:

http://www.waz.easynet.co.uk/pok/pok.pl.txt

I get 404 for this... (and for /pok).
Is it a bug in Perl, a bug in Crypt::Rijndael, or a bug in my
understanding of how to read in binary files?

I'm not sure... I can't reproduce the problem. I have tried:

#!/usr/bin/perl -l

use Crypt::Rijndael;

use Inline C => <<'EOC';
int is_scalar_POK(SV *sv)
{
return SvPOK(sv) ? 1 : 0;
}
EOC

my $k;
for (0..31) {
$k .= chr;
}
print is_scalar_POK $k;
my $c = Crypt::Rijndael->new($k, Crypt::Rijndael::MODE_CBC);
print $c ? 'success' : 'failure';
print is_scalar_POK $k;

__END__

which works as expected, but I don't really understand the difference
between obtaining a key for encryption and for decryption. Could you
post a modification of the above that fails, together with a hex dump of
the key you read from the file?

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top