Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES-CTR IV broken(!) - IV is not increasing #8

Closed
DopeforHope opened this issue May 20, 2019 · 1 comment
Closed

AES-CTR IV broken(!) - IV is not increasing #8

DopeforHope opened this issue May 20, 2019 · 1 comment

Comments

@DopeforHope
Copy link
Contributor

Hey,

Didn't expected this but the AES-CTR implementation has a flaw. The counter/IV is not increasing at all.

Critical code snippet:

function AESCTR(blocks::Array{UInt8, 1}, key::Array{UInt8, 1},
	iv::Array{UInt8, 1})
	noBlocks = keyStreamCheck(blocks, key, iv)
	curr = copy(iv)
	o = Array{UInt8}(undef, length(blocks))

	for i=1:noBlocks
		indices = blockIndices(blocks, i)
		eb = AESEncrypt(curr, key)
    	o[indices] = xor.(eb[1:length(indices)] , blocks[indices])
		for bi=(length(curr) - 7):length(curr)
			tmp = curr[bi]
			curr[bi] = UInt8(Int(tmp) + 1)
			if curr[bi] > tmp
				# no byte overflow
				break
			end
		end
	end

	return o
end

If one puts a print before the AESEncrypt call:

function AESCTR(blocks::Array{UInt8, 1}, key::Array{UInt8, 1},
	iv::Array{UInt8, 1})
	noBlocks = keyStreamCheck(blocks, key, iv)
	curr = copy(iv)
	o = Array{UInt8}(undef, length(blocks))

	for i=1:noBlocks
		indices = blockIndices(blocks, i)
		println("######LIB Iv: ", curr)
		eb = AESEncrypt(curr, key)
    	o[indices] = xor.(eb[1:length(indices)] , blocks[indices])
		for bi=(length(curr) - 7):length(curr)
			tmp = curr[bi]
			curr[bi] = UInt8(Int(tmp) + 1)
			if curr[bi] > tmp
				# no byte overflow
				break
			end
		end
	end

	return o
end

You will see that the IV is not increasing. The error lies perhaps in the scopes of variables. I'm not sure but this may have been changed from 0.6 to 1.0?

JuliaLang/julia#28750 seems to be something similiar.

Version: Julia 1.0.2 (LTS)

@DopeforHope
Copy link
Contributor Author

Bullshit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant