Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > AES256 in PyCrypto

Reply
Thread Tools

AES256 in PyCrypto

 
 
mirandacascade@yahoo.com
Guest
Posts: n/a
 
      01-07-2007
Attempting to determine whether the PyCrypto package has the capability
to perform AES256 encryption. I received the following C# snippet:

CryptoProvider provider = new CryptoProvider();
Encrypted_Type password = new Encrypted_Type();
password.EncryptedData = new EncryptedDataType();
password.EncryptedData.EncryptionMethod = new EncryptionMethodType();
password.EncryptedData.EncryptionMethod.Algorithm = "AES256-cbc";

and I was told that it was the setup code for code that later on
performs AES256 encryption. I'm assuming that setting the Algorithm
property is what informs the system as to the type of encryption to
perform. I included the above snippet as a reference point, because
I'm attempting to understand how to do something equivalent in Python.

Would the following Python code perform AES256 encryption on plainText
from Crypto.Cipher import AES
x = AES.new(a, AES.MODE_CBC, iv)
x.encrypt(plainText)

assuming:
a = the key value
iv = an initialization vector
?

If the above Python code does not perform AES256 encryption:
a) is there functionality within PyCrypto that allows one to perform
AES256 encryption?
b) if such functionality does not exist in PyCrypto, does it exist in
some other Python package?

Operating System: Windows XP
Vsn of Python: 2.4

Thank you.

 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      01-07-2007
In < .com>, mirandacascade
wrote:

> Would the following Python code perform AES256 encryption on plainText
> from Crypto.Cipher import AES
> x = AES.new(a, AES.MODE_CBC, iv)
> x.encrypt(plainText)
>
> assuming:
> a = the key value
> iv = an initialization vector
> ?


`a` must be of length 32 for AES256. And the length of `plainText` must
be a multiple of 16 because it's a block cypher algorithm.

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
 
 
 
mirandacascade@yahoo.com
Guest
Posts: n/a
 
      01-07-2007

Marc 'BlackJack' Rintsch wrote:

> `a` must be of length 32 for AES256. And the length of `plainText` must
> be a multiple of 16 because it's a block cypher algorithm.


Thank you. I have some follow up questions and 1 tangential question.

Follow up question:
Would it be correct to infer that:
a) the AES.pyd extension module (plus whatever additional files within
the PyCrypto package that it uses) has the capability to perform AES256
encryption?
b) the AES256 encryption happens based on the characteristics of the
input to the new() method...if the first argument has a length of 32,
the result will be AES256-style encryption?
c) will AES256-style encryption also happen if the first argument to
the new() method has a length that is a multiple of 32, e.g. 64?

Tangential question:
Is there functionality available (either in the PyCrypto package or
some other package) that generates an initialization vector that can be
used as input to the new() method? What prompts this question is that
the original posting referenced a snippet of C# code; some other
related snippets I saw seemed to suggest that:
a) a RijndaelManaged() class gets instantiated
b) that class has a GenerateIV() method which appears to populate
someting in a IV property
c) the application that was employing the AES256 encryption made use of
the left-most 16 characters of the IV property
So, I was curious whether something analgous exists in the Python
world.

Thank you.

 
Reply With Quote
 
Sebastian 'lunar' Wiesner
Guest
Posts: n/a
 
      01-07-2007
[ <> ]

>
> Marc 'BlackJack' Rintsch wrote:
>
>> `a` must be of length 32 for AES256. And the length of `plainText`
>> must be a multiple of 16 because it's a block cypher algorithm.

>
> Thank you. I have some follow up questions and 1 tangential question.
>
> Follow up question:
> Would it be correct to infer that:
> a) the AES.pyd extension module (plus whatever additional files
> within the PyCrypto package that it uses) has the capability to
> perform AES256 encryption?
> b) the AES256 encryption happens based on the characteristics of the
> input to the new() method...if the first argument has a length of 32,
> the result will be AES256-style encryption?


Since you are apparently unable to read to docstrings of this module, I
will give you a short hint: yes, pycrypto supports AES with 256 bit
keys.

> c) will AES256-style encryption also happen if the first argument to
> the new() method has a length that is a multiple of 32, e.g. 64?


Why didn't you try this? It would have answered your question:

[12]--> AES.new(os.urandom(64), AES.MODE_CBC, os.urandom(16))
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)

/home/lunar/<ipython console>

ValueError: AES key must be either 16, 24, or 32 bytes long


> Tangential question:
> Is there functionality available (either in the PyCrypto package or
> some other package) that generates an initialization vector that can
> be used as input to the new() method? What prompts this question is
> that the original posting referenced a snippet of C# code; some other
> related snippets I saw seemed to suggest that:
> a) a RijndaelManaged() class gets instantiated
> b) that class has a GenerateIV() method which appears to populate
> someting in a IV property
> c) the application that was employing the AES256 encryption made use
> of the left-most 16 characters of the IV property
> So, I was curious whether something analgous exists in the Python
> world.


os.urandom will be your friend...

--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
 
Reply With Quote
 
mirandacascade@yahoo.com
Guest
Posts: n/a
 
      01-07-2007
Sebastian 'lunar' Wiesner wrote:

> Since you are apparently unable to read to docstrings of this module, I
> will give you a short hint: yes, pycrypto supports AES with 256 bit
> keys.

Thank you for the information.

The material I consulted was:
a) the PyCrypto manual: http://www.amk.ca/python/writing/pycrypt/
b) the .py files that shipped with the PyCrypto package

Is a docstring is the text between the three consecutive quote
characters in a .py file? The reason for the question is that I looked
at the .py files that shipped with PyCrypto. Of the various .py files
that shipped with PyCrypto, there were two files (both __init__.py)
that contained information seemed to pertain to AES. The stuff between
the 3 consecutive quote chars in:
Crypto.__init__.py
Crypto.Cipher.__init__.py
make reference to AES, but I wasn't able to determine from what I read
if that was AES256.
Which .py file contain the docstrings that flesh out the information
summarized in the short hint?

Can docstrings be embedded within the .pyd extension modules as well?
Does the AES.pyd extension module have docstrings? How does one view
the docstrings in a .pyd file? When I reference AES from the
interactive of Pythonwin:
>>> from Crypto.Cipher import AES
>>> x = AES.new(

As soon as I type the '(' character, the IDE displays:
new(key, [mode], [IV]): Return a new AES encryption object

then when x gets instantiated, and the encrypt method gets called...
>>> x.encrypt(

As soon as I type the '(' character, the IDE displays:
Encrypt the provided string of binary data

I'm guessing that what the IDE is displaying is the first line of what
may be multiple-line docstring that is embedded within the .pyd
extension module? Might there be more lines in the docstring?

Thank you.

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-08-2007
At Sunday 7/1/2007 18:23, wrote:

>Is a docstring is the text between the three consecutive quote
>characters in a .py file? The reason for the question is that I looked


See section 4.6 in the Python Tutorial - I strongly suggest you read
it (or any other introductory text like diveintopython)

>Can docstrings be embedded within the .pyd extension modules as well?


Yes - if the original module writer has provided it.

> >>> x = AES.new(

>As soon as I type the '(' character, the IDE displays:
>new(key, [mode], [IV]): Return a new AES encryption object [...]
>I'm guessing that what the IDE is displaying is the first line of what
>may be multiple-line docstring that is embedded within the .pyd
>extension module? Might there be more lines in the docstring?


I don't know which IDE are you using, but try typing "help(AES.new)"
or simply "help" (without quotes) in the interpreter.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDK 1.6.0_24 and AES256 ciphers Stone Java 6 06-19-2011 06:14 PM
PyCrypto 2.0, pysco 1.4 - Windows Binaries for 2.4 Fuzzyman Python 0 01-12-2005 09:47 AM
ANN: PyCrypto 2.0 Binary Installer Fuzzyman Python 0 12-13-2004 09:43 AM
PyCrypto and RSA Carmine Noviello Python 2 03-01-2004 08:11 AM
compile pycrypto on windows Haim Ashkenazi Python 2 02-11-2004 12:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57