I'm giving a look to the code of OpenSSL as I'm very interested in RSA
encryptation / decryp. specially for a subject called Discrete Math. My
problem is that I have to work on an algorithm by myself and, of course, I'm
trying to implement and understand some things that OSSL uses like the
Arbitrary Precision Numbers (BIGNUM).
What I can't understand is how the function BN_bin2bn works (or at least, I
know what it does but I think doesn't do it correctly). For example, imagine
that I have to transform the string "1234" to the BIGNUM->d (that it's a
pointer to a long):
Initial params:
s = "1234"
m = 3
n = 4
i = 1
The initial long l is a 32 bit full of zeros. So then when you do:
l=(l<<8L)| *(s++);
This then write to the long the char value of '1', '2', '3', and at last '4'
moving the bits to the left. For example for the '1' it writes 110001. When
it writes the '2' the chain of bits is something like: 110001 00110010, and
so on... At the end I have this:
00110001001100100011001100110100 - 32 bit long
And that, of course, it's not the number 1234 in binary, is the number
825373492. What is what I'm not understanding? (I think anything at all).
Please help me! Thank You!!
_________________________________________________________________
Protege tu correo contra los virus con MSN Premium. Pruébalo gratis dos
meses.
http://join.msn.com/?pgmarket=es-es&page=features/firewall&XAPID=1684&DI=1055&HL=TAG2OPENINGTEXT_MSNPREMIUM_VIRUS
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org
charlychango> I'm giving a look to the code of OpenSSL as I'm very
charlychango> interested in RSA encryptation / decryp. specially for a
charlychango> subject called Discrete Math. My problem is that I have
charlychango> to work on an algorithm by myself and, of course, I'm
charlychango> trying to implement and understand some things that OSSL
charlychango> uses like the Arbitrary Precision Numbers (BIGNUM).
charlychango>
charlychango> What I can't understand is how the function BN_bin2bn
charlychango> works (or at least, I know what it does but I think
charlychango> doesn't do it correctly). For example, imagine that I
charlychango> have to transform the string "1234" to the BIGNUM->d
charlychango> (that it's a pointer to a long):
If the string "1234" is to be interpreted as a hexadecimal number, you
should use BN_hex2bn(). If it's to be interpreted as a decimal
number, you should use BN_dec2bn().
BN_bin2bn() is supposed to be used when you get a number in raw binary
form. If you have the number 1234 stored in a unsigned char array (in
big-endian form, which is required by BN_bin2bn()), then it could look
like this (I trust you understand C enough to understand what this
does):
unsigned char raw_input[] = { 4, 210 }; /* 1234 = 4 * 256 + 210 */
BIGNUM *bn = BN_bin2bn(raw_input, sizeof(raw_input));
-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.
--
Richard Levitte \ Tunnlandsvägen 52 \ LeV...@stacken.kth.se
Redakteur@Stacken \ S-168 36 BROMMA \ T: +46-708-26 53 44
\ SWEDEN \
Procurator Odiosus Ex Infernis -- po...@bofh.se
Member of the OpenSSL development team: http://www.openssl.org/
Unsolicited commercial email is subject to an archival fee of $400.
See <http://www.stacken.kth.se/~levitte/mail/> for more info.