Skip to content

Commit

Permalink
Switch to 4 double-rounds (i.e. to ChaCha8) by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelmethod committed May 13, 2024
1 parent 38fd5d9 commit be3380c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/keystream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mutable struct ChaChaStream <: AbstractChaChaStream
nonce,
counter = UInt64(0),
position = 1;
doublerounds = 10
doublerounds = 4
)
if doublerounds 0
error("`doublerounds` must be an even positive number")
Expand All @@ -75,17 +75,24 @@ end
"""
ChaCha20Stream(args...)
Create a keystream for a ChaCha20 stream cipher.
Create a random stream from the ChaCha20 stream cipher.
"""
ChaCha20Stream(args...) = ChaChaStream(args...; doublerounds=10)

"""
ChaCha12Stream(args...)
Create a keystream for a ChaCha12 stream cipher.
Create a random stream from the ChaCha12 stream cipher.
"""
ChaCha12Stream(args...) = ChaChaStream(args...; doublerounds=6)

"""
ChaCha8Stream(args...)
Create a random stream from the ChaCha8 stream cipher.
"""
ChaCha8Stream(args...) = ChaChaStream(args...; doublerounds=4)

function Base.show(io::IO, rng::ChaChaStream)
msg = """
ChaChaStream(
Expand Down
5 changes: 3 additions & 2 deletions test/test_keystream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ using Test
stream = ChaChaStream()
@test stream.nonce == 0
@test stream.position == 1

stream = ChaChaStream(; doublerounds=4)
@test stream.doublerounds == 4

stream = ChaChaStream(; doublerounds=6)
@test stream.doublerounds == 6

# We should receive an error if we try to create a
# keystream with non-positive number of doublerounds
@test_throws ErrorException ChaChaStream(; doublerounds=0)
Expand Down

0 comments on commit be3380c

Please sign in to comment.