[PYTHON-CRYPTO] RSA exponent

Dan Berger dberger at CS.UCR.EDU
Wed Aug 4 00:42:30 CEST 2004


It's likely because OpenSSL (and the M2 wrapper) are returning an MPI -
which has it's length as the first four bytes and remainder being the
number in big-endian byte order.

On Tue, 2004-08-03 at 21:39 +0200, Larry Bugbee wrote:
> I could use some help...
> 
> When I generate a RSA key pair I use 65537 as the exponent.  Later when I go
> to extract the exponent I get 50397185.  In hex it's actually 00 00 00 03 01
> 00 01, but if I discard the 4 high order bytes, 01 00 01 evaluates to 65537.
>  Perhaps you have a suggestion?
> 
> Here is a minimalist version of my code.
> 
> from M2Crypto import RSA
> key = RSA.gen_key(1024, 65537)
> print type(key.e)
> print len(key.e)
> for c in key.e:
>     print ord(c),
> print
> e = 0
> for c in key.e:
> # e = (e << 8) + ord(c)
>  e = (e*256) + ord(c)
> print e
> 
> I get the same results on both MacOSX and Win2000.
>  - OSX 10.3.4, python 2.3, openssl 0.9.7b, M2Crypto 0.13 (with DSA patches)
>  - Win2000, python 2.3.4, openssl 0.9.7b, M2Crypto 0.13 (no patches)
> 
> OpenSSL is not the latest version, but I should be OK.
> 
> Thanks,
> 
> Larry
--

...Dan Berger [dberger at cs.ucr.edu]
   Department of Computer Science
   Surge Building, Room 357
   University of California, Riverside
   http://www.cs.ucr.edu/~dberger

   "Man had always assumed that he was more intelligent than dolphins
    because he had achieved so much... the wheel, New York, wars, and
    so on, whilst all the dolphins had ever done was muck about in the
    water having a good time. But conversely the dolphins believed
    themselves to be more intelligent than man for precisely the same
    reasons."

        - Douglas Adams, The Hitchhiker's Guide to the Galaxy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-crypto/attachments/20040803/c4fd6d35/attachment.pgp>


More information about the python-crypto mailing list