Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 558837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:10:26+00:00 2026-05-13T12:10:26+00:00

I am running this code to see the performance impact of the keyczar encryption

  • 0

I am running this code to see the performance impact of the keyczar encryption library from google:

from keyczar import keyczar, keys

def main(iters):
    key = keys.RsaPrivateKey.Generate()
    msg = "ciao"
    crypt = None
    for i in range(iters):
        print i, "\r",
        crypt = key.Encrypt(msg)
    for i in range(iters):
        print i, "\r",
        key.Decrypt(crypt)

if __name__ == '__main__':
    main(500)

Under Windows, 500 iterations takes about 16 minutes. Under an Ubuntu 9.04 partition on the same machine, 500 iterations takes about 6 seconds.

I’ve tried profiling this (cProfile + pstats) but I don’t have much experience in interpreting the results.

Can someone tell me why the same code runs 150+ times slower under Windows?


Edit 2010-01-16

Here is my generate_key.py script:

from keyczar import keyczar, keys

key = keys.RsaPrivateKey.Generate()

Here is my command line to create a stats file in generate_key:

C:\temp\python-keyczar-0.6b\tests\keyczar>python -m cProfile -o generate_key generate_key.py

Here is my python session to expand the results:

>>> import pstats
>>> p = pstats.Stats('generate_key')
>>> p.strip_dirs().sort_stats(-1).print_stats(25)
Sat Jan 16 12:18:43 2010    generate_key

         83493 function calls (82974 primitive calls) in 5.131 CPU seconds

   Ordered by: standard name
   List reduced from 564 to 25 due to restriction <25>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.210    0.210 AES.py:1(<module>)
        1    0.022    0.022    0.210    0.210 AES.py:1(__bootstrap__)
        1    0.000    0.000    0.000    0.000 DSA.py:115(DSAobj)
        1    0.001    0.001    0.005    0.005 DSA.py:14(<module>)
        1    0.000    0.000    0.000    0.000 DSA.py:174(DSAobj_c)
        1    0.000    0.000    0.000    0.000 DSA.py:26(error)
        1    0.000    0.000    0.001    0.001 RSA.py:125(size)
        1    0.000    0.000    0.000    0.000 RSA.py:13(<module>)
        1    0.000    0.000    0.000    0.000 RSA.py:140(publickey)
        1    0.000    0.000    0.000    0.000 RSA.py:146(RSAobj_c)
        1    0.000    0.000    0.000    0.000 RSA.py:23(error)
        1    0.000    0.000    4.816    4.816 RSA.py:26(generate)
        1    0.000    0.000    0.000    0.000 RSA.py:63(construct)
        1    0.000    0.000    0.000    0.000 RSA.py:85(RSAobj)
        1    0.003    0.003    0.004    0.004 SHA.py:4(<module>)
        1    0.000    0.000    0.000    0.000 __future__.py:48(<module>)
        1    0.000    0.000    0.000    0.000 __future__.py:74(_Feature)
        7    0.000    0.000    0.000    0.000 __future__.py:75(__init__)
        8    0.000    0.000    0.000    0.000 __init__.py:1(<module>)
        1    0.000    0.000    0.000    0.000 __init__.py:11(<module>)
        1    0.000    0.000    0.000    0.000 __init__.py:13(<module>)
        1    0.000    0.000    0.000    0.000 __init__.py:18(<module>)
        1    0.000    0.000    0.000    0.000 __init__.py:20(<module>)
        2    0.000    0.000    0.000    0.000 __init__.py:24(<module>)


<pstats.Stats instance at 0x023F5E40>
>>>

So the Windows code does execute in python. Most of the runtime is spent here:

def generate(bits, randfunc, progress_func=None):
    """generate(bits:int, randfunc:callable, progress_func:callable)

    Generate an RSA key of length 'bits', using 'randfunc' to get
    random data and 'progress_func', if present, to display
    the progress of the key generation.
    """
    obj=RSAobj()

    # Generate the prime factors of n
    if progress_func:
        progress_func('p,q\n')
    p = q = 1L
    while number.size(p*q) < bits:
        p = pubkey.getPrime(bits/2, randfunc)
        q = pubkey.getPrime(bits/2, randfunc)

    # p shall be smaller than q (for calc of u)
    if p > q:
        (p, q)=(q, p)
    obj.p = p
    obj.q = q

    if progress_func:
        progress_func('u\n')
    obj.u = pubkey.inverse(obj.p, obj.q)
    obj.n = obj.p*obj.q

    obj.e = 65537L
    if progress_func:
        progress_func('d\n')
    obj.d=pubkey.inverse(obj.e, (obj.p-1)*(obj.q-1))

    assert bits <= 1+obj.size(), "Generated key is too small"

    return obj

I am running PyCrypto downloade from here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:10:26+00:00Added an answer on May 13, 2026 at 12:10 pm

    PyCrypto has a C module called _fastmath which uses GNU MP for the public key operations. If it is not available, it instead uses Python’s native long integers, which are much much slower.

    The two files are src/_fastmath.c and lib/Crypto/PublicKey/_slowmath.py

    It’s likely that Python on Windows does not include GNU MP, so on Windows it’s instead using _slowmath.py

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running this code in Firefox 11 on Windows 7. (See http://jsfiddle.net/QStkd/ ). $('<div><input
Okay so, I'm currently running this code to move a bunch of data from
While I am running this code it showing me a following error:- Column 'virtuemart_product_id'
I get a segmentation fault when running this code. Anyone know why? Thanks. #include
I'm a beginner with jdbc ... I have a problem running this code :
I'm running this C# code in Visual Studio in debug mode: public class MyHandlerFactory
I have this code running great in ff, opera and chrome: <script type=text/javascript> $(document).ready(function(){
I wanted to generate a list view using below code. But after running this
Running the static analyzer on this piece of code: - (id) readForeignPref { CFPropertyListRef
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.