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

os.walk for loop not executing [duplicate]
python matplotlib polar plot
Django - not showing properly one of my tables in template
Datalab: How to export Big Query standard SQL query to dataframe?
Pandas: count difference between dates
Skip one line in .csv file by using genfromtxt function in python
Dealing with NaNs in Pandas
Python Script? - Logging serial output from arduino
Iterate links from selenium into bs4 and print stripped strings
Query for only part of objects of related_name (from ForeignKey)
How to fill in missing sequence lines in a TSV file
Django website optimization: Too many calls to core python functions?
How to post issues to gitlab using python?
Coverage and nose shows files from django and not just my tests
Hexbin scatter plot between two 2D numpy arrays
How to assign a ForeignKey field when a new instance is created

Categories

HOME
jsf
winapi
facebook-graph-api
jasmine
puppet
actionscript
command
recyclerview
jpanel
triggers
nodemailer
currency
metronic
keystore
jboss-eap-7
cakephp-2.9
nixos
dlib
sign
session-timeout
chocolatey
aws-cognito
sql-update
k2
explode
bcrypt
scalajs-react
reactiveui
xor
referenceerror
postgresql-9.2
outsystems
canvasjs
polymorphism
gettext
css-counter
android-download-manager
coreclr
sql-like
equivalence
linq-to-entities
soundjs
powermta
greenhills
struts-layout
execl
python-hypothesis
project-template
typhoon
activeweb
pax-web
kendo-combobox
gmsmapview
mfc-feature-pack
aerogear
fortran90
git-rebase
hateoas
evo
matcaffe
python-winshell
divide-by-zero
debian-based
uptodate
magento-1.12
google-earth-plugin
jcr-sql2
cpu-speed
microblaze
fragment-tab-host
aquafold
surrogate-key
spdy
ssms-addin
ifft
joox
lov
dynamic-proxy
modeshape
nimrod
image-zoom
manage.py
resgen
fraud-prevention
prng
trailing-slash
mozart-mvc
dropdownlistfor
usn
javascriptserializer
static-variables
responsetext
objectbrowser
selectmanycheckbox
newsstand-kit
posting
dcpu-16
collect
exitstatus
msn
asp.net-routing
hibernate3-maven-plugin
aio
chdatastructures
graniteds
iphone-sdk-3.2
usability-testing
rd

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App