"Fossies" - the Fresh Open Source Software Archive

Member "julia-1.1.1/share/julia/stdlib/v1.1/SHA/src/base_functions.jl" (16 May 2019, 1917 Bytes) of package /linux/misc/julia-1.1.1-linux-i686.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Julia source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is a part of Julia. License is MIT: https://julialang.org/license
    2 
    3 # THE SIX LOGICAL FUNCTIONS
    4 #
    5 # Bit shifting and rotation (used by the six SHA-XYZ logical functions:
    6 #
    7 #   NOTE:  The naming of R and S appears backwards here (R is a SHIFT and
    8 #   S is a ROTATION) because the SHA2-256/384/512 description document
    9 #   (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this
   10 #   same "backwards" definition.
   11 
   12 # 32-bit Rotate-right (equivalent to S32 in SHA-256) and rotate-left
   13 rrot(b,x,width) = ((x >> b) | (x << (width - b)))
   14 lrot(b,x,width) = ((x << b) | (x >> (width - b)))
   15 
   16 # Shift-right (used in SHA-256, SHA-384, and SHA-512):
   17 R(b,x)   = (x >> b)
   18 # 32-bit Rotate-right (used in SHA-256):
   19 S32(b,x) = rrot(b,x,32)
   20 # 64-bit Rotate-right (used in SHA-384 and SHA-512):
   21 S64(b,x) = rrot(b,x,64)
   22 # 64-bit Rotate-left (used in SHA3)
   23 L64(b,x) = lrot(b,x,64)
   24 
   25 # Two of six logical functions used in SHA-256, SHA-384, and SHA-512:
   26 Ch(x,y,z)  = ((x & y)(~x & z))
   27 Maj(x,y,z) = ((x & y)(x & z)(y & z))
   28 
   29 # Four of six logical functions used in SHA-256:
   30 Sigma0_256(x) = (S32(2,  UInt32(x))S32(13, UInt32(x))S32(22, UInt32(x)))
   31 Sigma1_256(x) = (S32(6,  UInt32(x))S32(11, UInt32(x))S32(25, UInt32(x)))
   32 sigma0_256(x) = (S32(7,  UInt32(x))S32(18, UInt32(x))R(3 ,   UInt32(x)))
   33 sigma1_256(x) = (S32(17, UInt32(x))S32(19, UInt32(x))R(10,   UInt32(x)))
   34 
   35 # Four of six logical functions used in SHA-384 and SHA-512:
   36 Sigma0_512(x) = (S64(28, UInt64(x))S64(34, UInt64(x))S64(39, UInt64(x)))
   37 Sigma1_512(x) = (S64(14, UInt64(x))S64(18, UInt64(x))S64(41, UInt64(x)))
   38 sigma0_512(x) = (S64( 1, UInt64(x))S64( 8, UInt64(x))R( 7,   UInt64(x)))
   39 sigma1_512(x) = (S64(19, UInt64(x))S64(61, UInt64(x))R( 6,   UInt64(x)))
   40 
   41 # Let's be able to bswap arrays of these types as well
   42 bswap!(x::Vector{<:Integer}) = map!(bswap, x, x)