in reply to Re: Handling encryption safely
in thread Handling encryption safely
I was not trivializing it. As you well know Perl is a memory pig and optimized for speed. Part of this optimization is the over allocation of memory for scalars (as the test case shows). In fact Perl over allocates memory for just about all its data types. The reason is simple optimisation. If you don't have to reallocate memory simply to add an extra few bytes to a string, or add an extra element to an array you avoid the memory allocation and copy costs. I can't see a good reason why the gnomes should change this behaviour other than to save memory. I can't see ANY reason why overwriting the value in a scalar with the same number of bytes should EVER change to the situation where Perl is reallocating memory and doing a copy every time. This would be inefficient and is completely unnecessary.
As noted before physically securing the box is to my mind far more important. Just look at the banks for example. How many root kits are there that let you escalate user level privilege to root whereby you can just read the script/config without having to go to the extent of trawling through memory?
package Config; $key = 'hello'; package Foo; use Devel::Peek; my $str = 'the key is:'; Dump($Config::key); decrypt( $str, $Config::key ); $Config::key = 'x'x19; Dump($Config::key); decrypt( $str, $Config::key ); $Config::key = 'x'x20; Dump($Config::key); decrypt( $str, $Config::key ); sub decrypt{ warn "Got: @_\n" } __DATA__ SV = PV(0x15d5284) at 0x1a454a0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x15dd0ac "hello"\0 CUR = 5 LEN = 6 Got: the key is: hello SV = PV(0x15d5284) at 0x1a454a0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x15dd0ac "xxxxxxxxxxxxxxxxxxx"\0 <--- Same Pointer == overwrit +e CUR = 19 LEN = 20 Got: the key is: xxxxxxxxxxxxxxxxxxx SV = PV(0x15d5284) at 0x1a454a0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1a48edc "xxxxxxxxxxxxxxxxxxxx"\0 <--- Reallocation has occurr +ed CUR = 20 LEN = 21 Got: the key is: xxxxxxxxxxxxxxxxxxxx
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handling encryption safely
by Abigail-II (Bishop) on Oct 29, 2003 at 11:49 UTC | |
by tachyon (Chancellor) on Oct 29, 2003 at 12:34 UTC |