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

SELECT statements not grabbing data with Python Flask
python 3 class instances calling each others' attributes/variables?
“myobject” is not Iterable, but my obect is erased
SSL Certification Error > hostname doesn't match
Sequencing of elements in dict python
Keras error : Expected to see 1 array
import mxnet dmlc error Entry add_n already registered under different entry
How to open and execute kill task code through html
how do I remove unwanted empty dimension from xarray DataArray (squeeze doesn't work)
How to do math expression from input() in Python?
opening luigi.LocalTarget in binary read mode (decoding error)
GPU slows way down after a few loops
Google's verify_id_token function not working
ImportError: libgomp.so.1: cannot open shared object file: No such file or directory
Django Iterating through an object set with unique_together and no pk
Can i deploy a Django project using Apache that is not located in /var/www?

Categories

HOME
erlang
firebase-app-indexing
ocaml
translation
d
ruby-on-rails-3
apache2
javamail
onenote-api
jboss-eap-7
iso
wysiwyg
uiview
rebol2
ssms-2016
uicollectionview
ada
internet-explorer-8
vs2017
plsqldeveloper
embedly
google-ima
jquery-waypoints
java-ee-7
rhmap
i3
pcre
multichoiceitems
positioning
graph-databases
geo
google-drive-realtime-api
modulo
css-counter
mms
image-compression
soundjs
onbackpressed
stdclass
react-native-router-flux
taglib
jdbi
asmx
maintenance
ticker
tofixed
butterknife
info
svn-merge
pspice
audioqueue
gitweb
tuxedo
shipitjs
mercurial-hook
string-parsing
codesign
scriptlet
concur
amazon-kcl
drf-nested-routers
optionbutton
affix
wikitext
unity5.3
p-np
python-winshell
futuretask
graphical-logo
httpie
sqoop2
pisa
ember-components
system.web
bsp
data-generation
kraken.js
opensocial
apache2.2
grunt-contrib-compass
qss
mozart-mvc
git-filter-branch
osi
tfs-power-tools
plone-funnelweb
hinstance
serp
testunit
dcpu-16
collect
nagle
yajl
chdatastructures
rtsp-client
odbc-sql-server-driver

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