python - pycrypto does not reproduce NIST test vectors for AES (CFB mode) -


this small python program should encrypt plain cipher using aes in cfb mode using 128bit key

from crypto.cipher import aes  #            1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16 key   = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' iv    = b'\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' plain = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'  aes = aes.new(key, aes.mode_cfb, iv) cipher = aes.encrypt(plain)  print(' '.join('{:2x}'.format(b) b in cipher)) 

i took key, iv , plain cipher combination 1 of nist test vectors (cfb128vartxt128.rsp). particular combination expect cipher:

3a d7 8e 72 6c 1e c0 2b 7e bf e9 2b 23 d9 ec 34 

but pycrypto calculates

3a 81 e1 d4 b8 24 75 61 46 31 63 4b 5c 79 d6 bc 

the first byte correct, whereas others do not match. tried different test vectors, result stays same. bytes, except first byte, not match.

i quite sure, nist test vectors valid since used them before when using aes crypto++ , pretty sure, implementation of pycrypto correct since output agrees online tools such this page. obviously, me, using tools in incorrect way...

does have clue, how reproduce nist test vectors pycrypto?

this nist example

# cavs 11.1 # config info aes_values # aesvs vartxt test data cfb128 # state : encrypt , decrypt # key length : 128 # generated on fri apr 22 15:11:53 2011 ... count = 0 key = 00000000000000000000000000000000 iv = 80000000000000000000000000000000 plaintext = 00000000000000000000000000000000 ciphertext = 3ad78e726c1ec02b7ebfe92b23d9ec34 

you missing keyword argument, segment_size, in aes.new(...) call. feedback size, , defaults 8. if line of code changed

aes = aes.new(key, aes.mode_cfb, iv, segment_size=128) 

you correct result.

as stated in docs:

segment_size (integer) - (only mode_cfb).the number of bits plaintext , ciphertext segmented in. must multiple of 8. if 0 or not specified, assumed 8.

your results correspond labeled "cfb8" in nist docs.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -