How to pack 128- or 256-bit numbers

Is it possible to pack 128- or 256-bit numbers (AES / ivs keys created using Crypt :: Random :: makerandom) using the built-in perl package? If so, what should my X template be in

pack('X', ($256_bit_number)); 

be?

Thanks.

+4
source share
1 answer

Perl cannot store large numbers, so they cannot be packaged.

So let's see what makerandom really returns.

 $ perl -MData::Dumper -MCrypt::Random=makerandom \ -e'print(Dumper(makerandom(Size => 256, Strength => 1)));' $VAR1 = bless( do{\(my $o = 148076988)}, 'Math::Pari' ); 

Ah, a Math :: Pari object. Looking at the documents, there seems to be no easy way to pack them. But it seems that we do not need this. Crypt :: Random provides a makerandom_octet that returns a "packed" number.

 $ perl -MCrypt::Random=makerandom_octet \ -e'print(unpack("H*", makerandom_octet(Size => 256, Strength => 1)));' 1432698ef28c63d9cb0bba474c1644b4a6f9736616bd070102a612785332e94bb4 
+11
source

Source: https://habr.com/ru/post/1347828/


All Articles