[python-crypto] Test Vector verification in AES_CTR

Kaushal Bhandankar kaushalgoa at gmail.com
Wed Jan 12 06:39:03 CET 2011


I have figured out that the below code gives the correct ciphered output as
per the Test Vectors in RFC 3686. I have tried this for *"Test Vector
#1"*and I can see that

a) Prefix in counter is concatenated AES-CTR IV and nonce
b) nbits = 32


from Crypto.Cipher import AES
from Crypto.Util import Counter
import binascii

def main():

    plaintext = '53696e676c6520626c6f636b206d7367'
    ctr = Counter.new(nbits=32,
prefix=binascii.a2b_hex('000000300000000000000000'))

    crypto =
AES.new(binascii.a2b_hex('ae6852f8121067cc4bf7a5765577f39e'),AES.MODE_CTR,counter
= ctr)
    encrypted = crypto.encrypt(binascii.a2b_hex(plaintext))
    encrypted_2 = binascii.b2a_hex(encrypted)
    print encrypted_2

if __name__ == "__main__":
    main()

Regards,
Kaushal

On Wed, Jan 12, 2011 at 12:43 AM, Kaushal Bhandankar
<kaushalgoa at gmail.com>wrote:

> Hi,
> An old thread<http://mail.python.org/pipermail/python-crypto/2008-October/001060.html>describes how to use PyCrypto . However, I am not able to get the desired
> ciphered output as per the Test Vectors in SelfTests for AES in AES_CTR
> mode. ( lib/Crypto/SelfTest/Cipher/test_AES.py - RFC 3686 test vectors).
>
> Any help would be greatly appreciated.
>
> Thanks,
> Kaushal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-crypto/attachments/20110112/5c6c2435/attachment.html>


More information about the python-crypto mailing list