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

Python : NaN value in Pandas for a single value only
Add duration to time in python
Python When to OOP and When Not to OOP
Changing an arg in __new__ is not carrying over to __init__
Python : which importing module is calling my function at runtime
Python regression with bounded Y values?
how do you replace every value in a list with another value?
Randomness algorithm in python that integrates a demi-Gaussian curve?
How to resolve “NameError: global name 'x' is not defined” error while running Robot Framework testcase using custom Library?
Removing first character from string
Python: how can I override a complicated function during unittest?
subprocess stdin buffer not flushing on newline with bufsize=1
urllib3 download a file using specified user agent
AttributeError - QThread and Win32com
Python error when trying to use multiple functions in a class. Tkinter
Find min value in a CSV and print every row that includes it in Python

Categories

HOME
json
numpy
crate
jar
webrtc
windows-7
puppet
steam
aem
google-sheets-api
sbt-assembly
ios10
schemacrawler
deeplearning4j
wicket
nixos
xlsx
tee
local
spring-cloud-config
bootstrap-popover
off-canvas-menu
multicore
plsqldeveloper
raphael
excel-2010
google-ima
facebook4j
source-maps
delete-file
csh
python-textprocessing
data-cleansing
superscript
consumer
stocks
getline
salesforce-chatter
npm-shrinkwrap
large-data
text-files
xamarin.uitest
equivalence
ssh.net
microdata
cppunit
worker
ajp
azure-availability-set
production-environment
maintenance
chrome-remote-desktop
launch
vici
onresume
build-process
nsfetchedresultscontrolle
audioqueue
spoofing
linkageerror
soda
listadapter
scriptlet
concur
approval-tests
servlet-3.0
loose-typing
insertion-sort
cpu-cores
gulp-livereload
callstack
jai
line-numbers
ultrawingrid
errorprovider
bsp
ssms-addin
jstack
internal
healthvault
nservicebus4
multiple-conditions
ng-pattern
manage.py
symphony-cms
soa-suite
maven-ear-plugin
blockingqueue
getusermedia
getstring
jpf
objective-c-protocol
visual-web-gui
hinstance
testunit
associative
exitstatus
dirty-data
virtualquery
project-lifecycle
divx





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