Cryptography Reference
In-Depth Information
list of bits to the decimal integer it represents (in Maple version 12 and above this
may be done with the built-in function Bits:-Join ):
> bits2integer := proc(lis::list)
local l;
l := nops(lis);
add(lis[j]*2ˆ(l-j), j=1..l)
end proc:
The next function will be used to convert a list of 32 bits to a hexadecimal string
with eight hex digits (it can be easily adapted for other sizes but here we only use it
as mentioned). Note that if the number represented by the list uses fewer than eight
hex digits, leading zeros are added to the string to make its length equal to eight.
> bits2hex := proc(l::list)
local h;
h := StringTools:-LowerCase(convert(bits2integer(l), hex));
cat("0"$(8-length(h)), h)
end proc:
Now we are ready to construct the 64 SHA-256 constants. These are 32-bit words
which are computed as the first 32 bits of the fractional part of the cube roots of the
first 64 primes. We will use a precision of 16 decimal digits in this computation to
prevent round-off errors. The next function computes the first 32bits of the fractional
part of x q , where x and q are real numbers:
> frac32bin := (x, q) -> integer2bits(floor(evalf(2ˆ32*frac(xˆq), 16)), 32):
Now, the list K of SHA-256 constants is the following (we do not print it as the
binary form of these constants is not very readable):
> K := map(x -> frac32bin(x, 1/3), map(ithprime,[$1..64])):
We print these constants in hexadecimal, as they appear in [74]:
> map(bits2hex, K);
["428a2f98", "71374491", "b5c0fbcf", "e9b5dba5", "3956c25b", "59f111f1",
"923f82a4", "ab1c5ed5", "d807aa98", "12835b01", "243185be", "550c7dc3",
"72be5d74", "80deb1fe", "9bdc06a7", "c19bf174", "e49b69c1", "efbe4786",
"0fc19dc6", "240ca1cc", "2de92c6f", "4a7484aa", "5cb0a9dc", "76f988da",
"983e5152", "a831c66d", "b00327c8", "bf597fc7", "c6e00bf3", "d5a79147",
"06ca6351", "14292967", "27b70a85", "2e1b2138", "4d2c6dfc", "53380d13",
"650a7354", "766a0abb", "81c2c92e", "92722c85", "a2bfe8a1", "a81a664b",
"c24b8b70", "c76c51a3", "d192e819", "d6990624", "f40e3585", "106aa070",
"19a4c116", "1e376c08", "2748774c", "34b0bcb5", "391c0cb3", "4ed8aa4a",
"5b9cca4f", "682e6ff3", "748f82ee", "78a5636f", "84c87814", "8cc70208",
"90befffa", "a4506ceb", "bef9a3f7", "c67178f2"]
Next we define some of the operations used in SHA-256 and, as a preliminary
step, we start with the bitwise operations
which will be defined here for
bit lists (and used only in the case of 32-bit lists) and called bitAnd , bitXor and
bitNot , respectively.
,
and
¬
has frequently been used already (usually for bytes) but
here we define it again for bit lists (thus bitXor is different from the previously
defined function BitXor ):
> bitAnd := proc(l,m)
[seq(l[i]*m[i], i=1..nops(l))];
end proc:
 
Search WWH ::




Custom Search