python


Can't use 256-bits counter in AES.MODE_CTR cipher in python


guys. I use crypto library for AES encryption and decryption. AES-128 works perfect:
ctr = Counter.new(128)
key = os.urandom(16)
obj = AES.new(key, AES.MODE_CTR, counter=ctr)
But when I change 128 to 256, and 16 to 32 error occurs:
ValueError: unsupported format character 'b' (0x62) at index 29
Could you help me, any suggestions?

The counter size is the same as the block size of the block cipher. The block size and key size of a cipher are not directly related.
Now AES-256 has a key size of 256 bit and a block size of 128 bits. Rijndael, of which AES is a subset, can have a block size of 256 bit. But AES, using a key size of 128, 192 or 256 bits, will still have a block size of precisely 128 bits. And that's just because it has been defined that way.
So basically you should always leave ctr to Counter.new(128). If you want to use AES-256, increase your key to 32 bytes using os.urandom(32).
If you want to have hints on how to use / format the counter, please take a look at NIST SP 800-38A, Appendix B.


Related Links

When does Python decode a byte string while reading a file?
Wordnet synset - strange list index out of range Error
python subprocess, No such file or directory
c mmap write long to mmaped-area
ModelForm has no model class specified when use model forms
python scipy load mat file error
How can i make a time counter using QTime()
How do I convert this string to an array with all the proper formatting? [duplicate]
Iterate through a static image folder in django
Python Sklearn import error for scaler, pdalda file error?
PyYAML YAML load_all to Objects (nicely)
ttf_lookup_cache attribute not found in FontManager when using plot()
How to sort keys of dict by values?
a data structure with key as a cluster of words and value as a single word or string
Disable python warnings only for specific module via commandline
Error running GAE tutorial code - Guestbook

Categories

HOME
udp
signalr
vhdl
bing
google-tag-manager
rocketmq
iis-7.5
websphere-liberty
vuex
powershell-v3.0
arm-template
ng-show
tweets
plsqldeveloper
cruisecontrol.net
avplayeritem
cocoa-touch
jquery-waypoints
myob
novnc
python-textprocessing
ab-initio
owl-api
superagent
websauna
encase
strophe
read-write
pljson
modulo
precedence
bing-maps-api
npm-publish
fltk
agent
s3cmd
web-development-server
nashorn
mediawiki-extensions
android-maps-v2
html-agility-pack
ivona
startapp
recycle-bin
udev
mbaas
google-maps-ios
pagefile
uicollectionviewlayout
ingres
qos
keycode
typhoon
push-diffusion
mongo-c-driver
mirrorlink
wikitext
android-snackbar
windowlistener
webhdfs
base32
subversion-edge
musl
cpu-speed
cloudpebble
log4cplus
java-collections-api
csplit
dache
codeigniter-a3m
unison
operations
fogbugz-api
onselect
image-zoom
shiva3d
pep8
vertical-scrolling
icefaces-3
flash-cs5.5
qtembedded
testunit
for-xml-path
symbol-server
rijndael
libavformat
svn-hooks
msn
querypath
unreachable-code
aio
writing





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss