Skip to content

Commit

Permalink
Remove Julia 0.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Nov 15, 2016
1 parent f769066 commit c5b337c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 37 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- linux
- osx
julia:
- 0.3
- 0.4
- 0.5
- nightly
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.3
julia 0.4
Compat 0.9.4
16 changes: 8 additions & 8 deletions src/base_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Ch(x,y,z) = ((x & y) ⊻ (~x & z))
Maj(x,y,z) = ((x & y) (x & z) (y & z))

# Four of six logical functions used in SHA-256:
Sigma0_256(x) = (S32(2, @compat(UInt32(x))) S32(13, @compat(UInt32(x))) S32(22, @compat(UInt32(x))))
Sigma1_256(x) = (S32(6, @compat(UInt32(x))) S32(11, @compat(UInt32(x))) S32(25, @compat(UInt32(x))))
sigma0_256(x) = (S32(7, @compat(UInt32(x))) S32(18, @compat(UInt32(x))) R(3 , @compat(UInt32(x))))
sigma1_256(x) = (S32(17, @compat(UInt32(x))) S32(19, @compat(UInt32(x))) R(10, @compat(UInt32(x))))
Sigma0_256(x) = (S32(2, UInt32(x)) S32(13, UInt32(x)) S32(22, UInt32(x)))
Sigma1_256(x) = (S32(6, UInt32(x)) S32(11, UInt32(x)) S32(25, UInt32(x)))
sigma0_256(x) = (S32(7, UInt32(x)) S32(18, UInt32(x)) R(3 , UInt32(x)))
sigma1_256(x) = (S32(17, UInt32(x)) S32(19, UInt32(x)) R(10, UInt32(x)))

# Four of six logical functions used in SHA-384 and SHA-512:
Sigma0_512(x) = (S64(28, @compat(UInt64(x))) S64(34, @compat(UInt64(x))) S64(39, @compat(UInt64(x))))
Sigma1_512(x) = (S64(14, @compat(UInt64(x))) S64(18, @compat(UInt64(x))) S64(41, @compat(UInt64(x))))
sigma0_512(x) = (S64( 1, @compat(UInt64(x))) S64( 8, @compat(UInt64(x))) R( 7, @compat(UInt64(x))))
sigma1_512(x) = (S64(19, @compat(UInt64(x))) S64(61, @compat(UInt64(x))) R( 6, @compat(UInt64(x))))
Sigma0_512(x) = (S64(28, UInt64(x)) S64(34, UInt64(x)) S64(39, UInt64(x)))
Sigma1_512(x) = (S64(14, UInt64(x)) S64(18, UInt64(x)) S64(41, UInt64(x)))
sigma0_512(x) = (S64( 1, UInt64(x)) S64( 8, UInt64(x)) R( 7, UInt64(x)))
sigma1_512(x) = (S64(19, UInt64(x)) S64(61, UInt64(x)) R( 6, UInt64(x)))

# Let's be able to bswap arrays of these types as well
bswap!{T<:Integer}(x::Vector{T}) = map!(bswap, x)
4 changes: 2 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# 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<:@compat(Union{SHA1_CTX,SHA2_CTX,SHA3_CTX})}(context::T, data::Array{UInt8,1})
function update!{T<: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)

Expand Down Expand Up @@ -33,7 +33,7 @@ end


# Clear out any saved data in the buffer, append total bitlength, and return our precious hash!
function digest!{T<:@compat(Union{SHA1_CTX,SHA2_CTX})}(context::T)
function digest!{T<: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
14 changes: 7 additions & 7 deletions src/sha1.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Nonlinear functions, in order to encourage inlining, these sadly are not an array of lambdas
function Round0(b,c,d)
return @compat(UInt32((b & c) | (~b & d)))
return UInt32((b & c) | (~b & d))
end

function Round1And3(b,c,d)
return @compat(UInt32(b c d))
return UInt32(b c d)
end

function Round2(b,c,d)
return @compat(UInt32((b & c) | (b & d) | (c & d)))
return UInt32((b & c) | (b & d) | (c & d))
end

function transform!(context::SHA1_CTX)
Expand Down Expand Up @@ -43,7 +43,7 @@ function transform!(context::SHA1_CTX)
# really kills performance and causes a huge number of allocations, so we make it easy on the compiler
for i = 1:20
@inbounds begin
temp = @compat(UInt32(lrot(5, a, 32) + Round0(b,c,d) + e + context.W[i] + K1[1]))
temp = UInt32(lrot(5, a, 32) + Round0(b,c,d) + e + context.W[i] + K1[1])
e = d
d = c
c = lrot(30, b, 32)
Expand All @@ -54,7 +54,7 @@ function transform!(context::SHA1_CTX)

for i = 21:40
@inbounds begin
temp = @compat(UInt32(lrot(5, a, 32) + Round1And3(b,c,d) + e + context.W[i] + K1[2]))
temp = UInt32(lrot(5, a, 32) + Round1And3(b,c,d) + e + context.W[i] + K1[2])
e = d
d = c
c = lrot(30, b, 32)
Expand All @@ -65,7 +65,7 @@ function transform!(context::SHA1_CTX)

for i = 41:60
@inbounds begin
temp = @compat(UInt32(lrot(5, a, 32) + Round2(b,c,d) + e + context.W[i] + K1[3]))
temp = UInt32(lrot(5, a, 32) + Round2(b,c,d) + e + context.W[i] + K1[3])
e = d
d = c
c = lrot(30, b, 32)
Expand All @@ -76,7 +76,7 @@ function transform!(context::SHA1_CTX)

for i = 61:80
@inbounds begin
temp = @compat(UInt32(lrot(5, a, 32) + Round1And3(b,c,d) + e + context.W[i] + K1[4]))
temp = UInt32(lrot(5, a, 32) + Round1And3(b,c,d) + e + context.W[i] + K1[4])
e = d
d = c
c = lrot(30, b, 32)
Expand Down
12 changes: 6 additions & 6 deletions src/sha2.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function transform!{T<:@compat(Union{SHA2_224_CTX,SHA2_256_CTX})}(context::T)
function transform!{T<: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 All @@ -22,11 +22,11 @@ function transform!{T<:@compat(Union{SHA2_224_CTX,SHA2_256_CTX})}(context::T)
h = g
g = f
f = e
e = @compat UInt32(d + T1)
e = UInt32(d + T1)
d = c
c = b
b = a
a = @compat UInt32(T1 + T2)
a = UInt32(T1 + T2)
end
end

Expand All @@ -45,11 +45,11 @@ function transform!{T<:@compat(Union{SHA2_224_CTX,SHA2_256_CTX})}(context::T)
h = g
g = f
f = e
e = @compat UInt32(d + T1)
e = UInt32(d + T1)
d = c
c = b
b = a
a = @compat UInt32(T1 + T2)
a = UInt32(T1 + T2)
end
end

Expand All @@ -65,7 +65,7 @@ function transform!{T<:@compat(Union{SHA2_224_CTX,SHA2_256_CTX})}(context::T)
end


function transform!(context::@compat(Union{SHA2_384_CTX,SHA2_512_CTX}))
function transform!(context::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
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}) = @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{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{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))
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))


# short_blocklen is the size of a block minus the width of bytecount
short_blocklen{T<:@compat(Union{SHA1_CTX,SHA2_CTX})}(::Type{T}) = blocklen(T) - 2*sizeof(state_type(T))
short_blocklen{T<: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
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data = Any["", "test", lorem, file, 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", "0 file", "one million a's"]
sha_types = @compat Dict(sha1 => SHA.SHA1_CTX,
sha_types = 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 All @@ -25,7 +25,7 @@ shws = ["SHA1 hash state",
"SHA2 224-bit hash state", "SHA2 256-bit hash state", "SHA2 384-bit hash state", "SHA2 512-bit hash state",
"SHA3 224-bit hash state", "SHA3 256-bit hash state", "SHA3 384-bit hash state", "SHA3 512-bit hash state"]

answers = @compat Dict(
answers = Dict(
sha1 => [
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
Expand Down

0 comments on commit c5b337c

Please sign in to comment.