[ntl] A bug, I think in BytesFromZZ when built with gmp
Patrick Horgan
phorgan1 at gmail.com
Sun Aug 4 20:34:03 CDT 2013
Linux localhost.localdomain 3.9.11-200.fc18.x86_64 #1 SMP Mon Jul 22
21:04:50 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
g++ (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
ntl 6.0.0 downloaded recently and build with gmp 5.1.2 and gf2x 1.1.
With a particular value in a variable pt, where NumBytes(pt)==80, I
expect that BytesFromZZ will output the bytes such that the byte in
ptc[0] will correspond to the highest portion of the value in pt, and
ptc[79] will correspond to the least significant 256 bits of the value
of pt. In this instance pt is the plaintext from an RSA decryption, and
we would hope that the text reads from left to right. Instead, we get
the opposite result.
The code below was used to demonstrate this, and to show what we
expected by doing it ourselves. The output follows. You'll see that
ptc1 and ptc2 are reversals of each other, with ptc1 being from
BytesFromZZ and ptc2 being the output of the loop below it. The last 28
bytes are the ascii values in hex for the string "Factoring lets us
break RSA."
unsigned char *ptc=new unsigned char[NumBytes(pt)];
BytesFromZZ(ptc, pt, NumBytes(pt)+1);
std::cout << "ptc: ";
for(ssize_t i=0;i<NumBytes(pt);i++){
std::cout << std::hex << std::setw(2) << std::setfill('0') <<
int(static_cast<unsigned char>(ptc[i]));
}
std::cout << '\n';
ZZ pt2=pt;
unsigned char *ptc2=new unsigned char[NumBytes(pt)];
for(ssize_t i=NumBytes(pt)-1;i>=0;i--){
ptc2[i]=pt2%256;
pt2>>=8;
}
std::cout << "ptc2: ";
for(ssize_t i=0;i<NumBytes(pt);i++){
std::cout << std::hex << std::setw(2) << std::setfill('0') <<
int(ptc2[i]);
}
std::cout << '\n';
pt:
1426451879856214510330646002400995578367008996472114748613075557222561055795115728891177961543008315503915963697040212956606852659174678995486154430410613475683931167558406894855729746691128122753013281227792585556718735417914059214670504827025036737390143278850922860075246427162405295463406302195816284462
ptc:
2e415352206b61657262207375207374656c20676e69726f74636146006de4dae124b0985cb52d5d939ecba7e171fe398218ed904176262bb6d569b62c25730f1a090e64b42fab10e82569739fa250ebf97a577eea2075389d97af4d2d099a9539274ec6d092131117981e730396f043f6bb5d1de594053324b5107690050802
ptc2:
020805907610b524330594e51d5dbbf643f09603731e9817111392d0c64e2739959a092d4daf979d387520ea7e577af9eb50a29f736925e810ab2fb4640e091a0f73252cb669d5b62b26764190ed188239fe71e1a7cb9e935d2db55c98b024e1dae46d00466163746f72696e67206c65747320757320627265616b205253412e
Patrick
More information about the ntl
mailing list