Skip to content

Commit

Permalink
Merge pull request #18 from tkelman/patch-1
Browse files Browse the repository at this point in the history
test separately on 0.3 and 0.4 on travis
  • Loading branch information
staticfloat authored Jul 25, 2016
2 parents 70b51d1 + 80e58af commit 010a6e8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ os:
- linux
- osx
julia:
- release
- 0.3
- 0.4
- nightly
notifications:
email: false
Expand All @@ -12,4 +13,4 @@ script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.test("SHA", coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("SHA")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
- julia -e 'cd(Pkg.dir("SHA")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
10 changes: 5 additions & 5 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# update! takes in variable-length data, buffering it into blocklen()-sized pieces,
# calling transform!() when necessary to update the internal hash state.
function update!{T<:Union{SHA1_CTX,SHA2_CTX,SHA3_CTX}}(context::T, data::Array{UInt8,1})
function update!{T<:@compat(Union{SHA1_CTX,SHA2_CTX,SHA3_CTX})}(context::T, data::Array{UInt8,1})
# We need to do all our arithmetic in the proper bitwidth
UIntXXX = typeof(context.bytecount)

# Process as many complete blocks as possible
len = UIntXXX(length(data))
data_idx = UIntXXX(0)
len = convert(UIntXXX, length(data))
data_idx = convert(UIntXXX, 0)
usedspace = context.bytecount % blocklen(T)
while len - data_idx + usedspace >= blocklen(T)
# Fill up as much of the buffer as we can with the data given us
Expand All @@ -19,7 +19,7 @@ function update!{T<:Union{SHA1_CTX,SHA2_CTX,SHA3_CTX}}(context::T, data::Array{U
transform!(context)
context.bytecount += blocklen(T) - usedspace
data_idx += blocklen(T) - usedspace
usedspace = UIntXXX(0)
usedspace = convert(UIntXXX, 0)
end

# There is less than a complete block left, but we need to save the leftovers into context.buffer:
Expand All @@ -33,7 +33,7 @@ end


# Clear out any saved data in the buffer, append total bitlength, and return our precious hash!
function digest!{T<:Union{SHA1_CTX,SHA2_CTX}}(context::T)
function digest!{T<:@compat(Union{SHA1_CTX,SHA2_CTX})}(context::T)
usedspace = context.bytecount % blocklen(T)
# If we have anything in the buffer still, pad and transform that data
if usedspace > 0
Expand Down
4 changes: 2 additions & 2 deletions src/sha2.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function transform!{T<:Union{SHA2_224_CTX,SHA2_256_CTX}}(context::T)
function transform!{T<:@compat(Union{SHA2_224_CTX,SHA2_256_CTX})}(context::T)
buffer = reinterpret(eltype(context.state), context.buffer)
# Initialize registers with the previous intermediate values (our state)
a = context.state[1]
Expand Down Expand Up @@ -65,7 +65,7 @@ function transform!{T<:Union{SHA2_224_CTX,SHA2_256_CTX}}(context::T)
end


function transform!(context::Union{SHA2_384_CTX,SHA2_512_CTX})
function transform!(context::@compat(Union{SHA2_384_CTX,SHA2_512_CTX}))
buffer = reinterpret(eltype(context.state), context.buffer)
# Initialize registers with the prev. intermediate value
a = context.state[1]
Expand Down
2 changes: 1 addition & 1 deletion src/sha3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function transform!{T<:SHA3_CTX}(context::T)
for idx in 1:div(blocklen(T),8)
context.state[idx] $= buffer_as_uint64[idx]
end
bc = Array{UInt64,1}(5)
bc = Array(UInt64, 5)

# We always assume 24 rounds
for round in 0:23
Expand Down
20 changes: 10 additions & 10 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ state_type(::Type{SHA2_384_CTX}) = UInt64
state_type(::Type{SHA2_512_CTX}) = UInt64

# blocklen is the number of bytes of data processed by the transform!() function at once
blocklen(::Type{SHA1_CTX}) = UInt64(64)
blocklen(::Type{SHA2_224_CTX}) = UInt64(64)
blocklen(::Type{SHA2_256_CTX}) = UInt64(64)
blocklen(::Type{SHA2_384_CTX}) = UInt64(128)
blocklen(::Type{SHA2_512_CTX}) = UInt64(128)
blocklen(::Type{SHA1_CTX}) = @compat UInt64(64)
blocklen(::Type{SHA2_224_CTX}) = @compat UInt64(64)
blocklen(::Type{SHA2_256_CTX}) = @compat UInt64(64)
blocklen(::Type{SHA2_384_CTX}) = @compat UInt64(128)
blocklen(::Type{SHA2_512_CTX}) = @compat UInt64(128)

blocklen(::Type{SHA3_224_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_224_CTX))
blocklen(::Type{SHA3_256_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_256_CTX))
blocklen(::Type{SHA3_384_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_384_CTX))
blocklen(::Type{SHA3_512_CTX}) = UInt64(25*8 - 2*digestlen(SHA3_512_CTX))
blocklen(::Type{SHA3_224_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_224_CTX))
blocklen(::Type{SHA3_256_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_256_CTX))
blocklen(::Type{SHA3_384_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_384_CTX))
blocklen(::Type{SHA3_512_CTX}) = @compat UInt64(25*8 - 2*digestlen(SHA3_512_CTX))


# short_blocklen is the size of a block minus the width of bytecount
short_blocklen{T<:Union{SHA1_CTX,SHA2_CTX}}(::Type{T}) = blocklen(T) - 2*sizeof(state_type(T))
short_blocklen{T<:@compat(Union{SHA1_CTX,SHA2_CTX})}(::Type{T}) = blocklen(T) - 2*sizeof(state_type(T))

# Once the "blocklen" methods are defined, we can define our outer constructors for SHA types:
SHA2_224_CTX() = SHA2_224_CTX(copy(SHA2_224_initial_hash_value), 0, zeros(UInt8, blocklen(SHA2_224_CTX)))
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data = Any["", "test", lorem, so_many_as]

# Descriptions of the data, the SHA functions we'll run on the data, etc...
data_desc = ["the empty string", "the string \"test\"", "lorem ipsum", "one million a's"]
sha_types =Dict(sha1 => SHA.SHA1_CTX,
sha_types = @compat Dict(sha1 => SHA.SHA1_CTX,
sha2_224 => SHA.SHA2_224_CTX, sha2_256 => SHA.SHA2_256_CTX, sha2_384 => SHA.SHA2_384_CTX, sha2_512 => SHA.SHA2_512_CTX,
sha3_224 => SHA.SHA3_224_CTX, sha3_256 => SHA.SHA3_256_CTX, sha3_384 => SHA.SHA3_384_CTX, sha3_512 => SHA.SHA3_512_CTX)
sha_funcs = [sha1,
Expand Down

0 comments on commit 010a6e8

Please sign in to comment.