SHA-2

هذا المقال يتضمن أسماءً أعجمية تتطلب حروفاً إضافية (پ چ ژ گ ڤ ڠ).
لمطالعة نسخة مبسطة، بدون حروف إضافية

قالب:SHA-box قالب:Infobox cryptographic hash function SHA-2 (Secure Hash Algorithm 2)، هي مجموعة من دوال الهاش التشفيرية طورتها وكالة الأمن القومي الأمريكية.[1] They are built using the Merkle–Damgård structure, from a one-way compression function itself built using the Davies–Meyer structure from a (classified) specialized block cipher.

SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of six hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256.

SHA-256 and SHA-512 are novel hash functions computed with 32-bit and 64-bit words, respectively. They use different shift amounts and additive constants, but their structures are otherwise virtually identical, differing only in the number of rounds. SHA-224 and SHA-384 are truncated versions of SHA-256 and SHA-512 respectively, computed with different initial values. SHA-512/224 and SHA-512/256 are also truncated versions of SHA-512, but the initial values are generated using the method described in Federal Information Processing Standards (FIPS) PUB 180-4. SHA-2 was published in 2001 by the National Institute of Standards and Technology (NIST) a U.S. federal standard (FIPS). The SHA-2 family of algorithms are patented in US patent 6829355.[2] The الولايات المتحدة has released the patent under a royalty-free license.[3]

Currently, the best public attacks break preimage resistance for 52 out of 64 rounds of SHA-256 or 57 out of 80 rounds of SHA-512, and collision resistance for 46 out of 64 rounds of SHA-256.[4][5]

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

معيار الهاش

One iteration in a SHA-2 family compression function. المكونات الزرقاء تنفذ العمليات التالية:
${\displaystyle \operatorname {Ch} (E,F,G)=(E\land F)\oplus (\neg E\land G)}$
${\displaystyle \operatorname {Ma} (A,B,C)=(A\land B)\oplus (A\land C)\oplus (B\land C)}$
${\displaystyle \Sigma _{0}(A)=(A\!\ggg \!2)\oplus (A\!\ggg \!13)\oplus (A\!\ggg \!22)}$
${\displaystyle \Sigma _{1}(E)=(E\!\ggg \!6)\oplus (E\!\ggg \!11)\oplus (E\!\ggg \!25)}$
The bitwise rotation uses different constants for SHA-512. The given numbers are for SHA-256.
The red ${\displaystyle \color {red}\boxplus }$ is addition modulo 232 for SHA-256, or 264 for SHA-512.

التطبيقات

The SHA-2 hash function is implemented in some widely used security applications and protocols, including TLS and SSL, PGP, SSH, S/MIME, and IPsec.

SHA-256 partakes in the process of authenticating Debian software packages[6] and in the DKIM message signing standard; SHA-512 is part of a system to authenticate archival video from the International Criminal Tribunal of the Rwandan genocide.[7] SHA-256 and SHA-512 are proposed for use in DNSSEC.[8] Unix and Linux vendors are moving to using 256- and 512-bit SHA-2 for secure password hashing.[9]

Several cryptocurrencies like Bitcoin use SHA-256 for verifying transactions and calculating proof of work or proof of stake.[10] The rise of ASIC SHA-2 accelerator chips has led to the use of scrypt-based proof-of-work schemes.

SHA-1 and SHA-2 are the Secure Hash Algorithms required by law for use in certain U.S. Government applications, including use within other cryptographic algorithms and protocols, for the protection of sensitive unclassified information. FIPS PUB 180-1 also encouraged adoption and use of SHA-1 by private and commercial organizations. SHA-1 is being retired for most government uses; the U.S. National Institute of Standards and Technology says, "Federal agencies should stop using SHA-1 for...applications that require collision resistance as soon as practical, and must use the SHA-2 family of hash functions for these applications after 2010" (emphasis in original).[11] NIST's directive that U.S. government agencies must stop uses of SHA-1 after 2010[12] was hoped to accelerate migration away from SHA-1.

The SHA-2 functions were not quickly adopted initially, despite better security than SHA-1. Reasons might include lack of support for SHA-2 on systems running Windows XP SP2 or older[13] and a lack of perceived urgency since SHA-1 collisions had not yet been found. The Google Chrome team announced a plan to make their web browser gradually stop honoring SHA-1-dependent TLS certificates over a period from late 2014 and early 2015.[14][15][16] Similarly, Microsoft announced[17] that Internet Explorer and Edge would stop honoring public SHA-1-signed TLS certificates from February 2017. Mozilla disabled SHA-1 in early January 2016, but had to re-enable it temporarily via a Firefox update, after problems with web-based user interfaces of some router models and security appliances.[18]

تحليل الشفرة والتحقق منها

نُشر في السنة طريقة الهجوم الهجوم المتغير الجولات التعقيد
New Collision Attacks Against
Up To 24-step SHA-2
[19]
2008 Deterministic Collision SHA-256 24/64 228.5
SHA-512 24/80 232.5
Preimages for step-reduced SHA-2[20] 2009 Meet-in-the-middle Preimage SHA-256 42/64 2251.7
43/64 2254.9
SHA-512 42/80 2502.3
46/80 2511.5
preimage attacks
[21]
2010 Meet-in-the-middle Preimage SHA-256 42/64 2248.4
SHA-512 42/80 2494.6
Higher-Order Differential Attack
on Reduced SHA-256
[5]
2011 Differential Pseudo-collision SHA-256 46/64 2178
33/64 246
Bicliques for Preimages: Attacks on
Skein-512 and the SHA-2 family
[4]
2011 Biclique Preimage SHA-256 45/64 2255.5
SHA-512 50/80 2511.5
Pseudo-preimage SHA-256 52/64 2255
SHA-512 57/80 2511
Improving Local Collisions: New
Attacks on Reduced SHA-256
[22]
2013 Differential Collision SHA-256 31/64 265.5
Pseudo-collision SHA-256 38/64 237
Branching Heuristics in Differential Collision
Search with Applications to SHA-512
[23]
2014 Heuristic differential Pseudo-collision SHA-512 38/80 240.5
Analysis of SHA-512/224 and SHA-512/256[24] 2016 Differential Collision SHA-256 28/64 practical
SHA-512 27/80 practical
Pseudo-collision SHA-512 39/80 practical

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

عوامل الاختبار

```SHA224("")
0x d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
SHA256("")
0x e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
SHA384("")
SHA512("")
0x cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
SHA512/224("")
0x 6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4
SHA512/256("")
```
```SHA224("The quick brown fox jumps over the lazy dog")
SHA224("The quick brown fox jumps over the lazy dog.")
0x 619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4c
```

السودوكود

```Initialize hash values:
(first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
h0 := 0x6a09e667
h1 := 0xbb67ae85
h2 := 0x3c6ef372
h3 := 0xa54ff53a
h4 := 0x510e527f
h5 := 0x9b05688c
h6 := 0x1f83d9ab
h7 := 0x5be0cd19

Initialize array of round constants:
(first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311):
k[0..63] :=
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2

begin with the original message of length L bits
append a single '1' bit
append K '0' bits, where K is the minimum number >= 0 such that L + 1 + K + 64 is a multiple of 512
append L as a 64-bit big-endian integer, making the total post-processed length a multiple of 512 bits

Process the message in successive 512-bit chunks:
break message into 512-bit chunks
for each chunk
create a 64-entry message schedule array w[0..63] of 32-bit words
(The initial values in w[0..63] don't matter, so many implementations zero them here)
copy chunk into first 16 words w[0..15] of the message schedule array

Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array:
for i from 16 to 63
s0 := (w[i-15] rightrotate  7) xor (w[i-15] rightrotate 18) xor (w[i-15] rightshift  3)
s1 := (w[i- 2] rightrotate 17) xor (w[i- 2] rightrotate 19) xor (w[i- 2] rightshift 10)
w[i] := w[i-16] + s0 + w[i-7] + s1

Initialize working variables to current hash value:
a := h0
b := h1
c := h2
d := h3
e := h4
f := h5
g := h6
h := h7

Compression function main loop:
for i from 0 to 63
S1 := (e rightrotate 6) xor (e rightrotate 11) xor (e rightrotate 25)
ch := (e and f) xor ((not e) and g)
temp1 := h + S1 + ch + k[i] + w[i]
S0 := (a rightrotate 2) xor (a rightrotate 13) xor (a rightrotate 22)
maj := (a and b) xor (a and c) xor (b and c)
temp2 := S0 + maj

h := g
g := f
f := e
e := d + temp1
d := c
c := b
b := a
a [ك‍] := temp1 + temp2

Add the compressed chunk to the current hash value:
h0 := h0 + a
h1 := h1 + b
h2 := h2 + c
h3 := h3 + d
h4 := h4 + e
h5 := h5 + f
h6 := h6 + g
h7 := h7 + h

Produce the final hash value (big-endian):
digest := hash := h0 append h1 append h2 append h3 append h4 append h5 append h6 append h7
```

The computation of the `ch` and `maj` values can be optimized the same way as described for SHA-1.

SHA-224 is identical to SHA-256, except that:

• the initial hash values `h0` through `h7` are different, and
• the output is constructed by omitting `h7`.
```SHA-224 initial hash values (in big endian):
(The second 32 bits of the fractional parts of the square roots of the 9th through 16th primes 23..53)
h[0..7] :=
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
```

SHA-512 is identical in structure to SHA-256, but:

• the message is broken into 1024-bit chunks,
• the initial hash values and round constants are extended to 64 bits,
• there are 80 rounds instead of 64,
• the message schedule array w has 80 64-bit words instead of 64 32-bit words,
• to extend the message schedule array w, the loop is from 16 to 79 instead of from 16 to 63,
• the round constants are based on the first 80 primes 2..409,
• the word size used for calculations is 64 bits long,
• the appended length of the message (before pre-processing), in bits, is a 128-bit big-endian integer, and
• the shift and rotate amounts used are different.
```SHA-512 initial hash values (in big-endian):

h[0..7] := 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,

SHA-512 round constants:

k[0..79] := [ 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538,
0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe,
0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235,
0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, 0x983e5152ee66dfab,
0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725,
0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed,
0x53380d139d95b3df, 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b,
0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218,
0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, 0x19a4c116b8d2d0c8, 0x1e376c085141ab53,
0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373,
0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c,
0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc,

SHA-512 Sum & Sigma:

S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)

s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
```

SHA-384 is identical to SHA-512, except that:

• the initial hash values `h0` through `h7` are different (taken from the 9th through 16th primes), and
• the output is constructed by omitting `h6` and `h7`.
```SHA-384 initial hash values (in big-endian):

h[0..7] := 0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939,
0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4
```

SHA-512/t is identical to SHA-512 except that:

• the initial hash values `h0` through `h7` are given by the SHA-512/t IV generation function,
• the output is constructed by truncating the concatenation of `h0` through `h7` at t bits,
• t equal to 384 is not allowed, instead SHA-384 should be used as specified, and
• t values 224 and 256 are especially mentioned as approved.

The SHA-512/t IV generation function evaluates a modified SHA-512 on the ASCII string "SHA-512/t", substituted with the decimal representation of t. The modified SHA-512 is the same as SHA-512 except its initial values `h0` through `h7` have each been XORed with the hexadecimal constant `0xa5a5a5a5a5a5a5a5`.

Sample C implementation for SHA-2 family of hash functions can be found in RFC 6234.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

مقارنة دوال SHA

CPU architecture Frequency Algorithm Word size (bits) Cycles/byte x86 MiB/s x86 Cycles/byte x86-64 MiB/s x86-64
Intel Ivy Bridge 3.5 GHz SHA-256 32 16.80 199 13.05 256
SHA-512 64 43.66 76 8.48 394
AMD Piledriver APU 3.8 GHz SHA-256 32 22.87 158 18.47 196
SHA-512 64 88.36 41 12.43 292

المصادر

1. ^ "On the Secure Hash Algorithm family" (PDF). Archived from the original (PDF) on 2016-03-30. Unknown parameter `|deadurl=` ignored (help)
2. ^ US patent 6829355
3. ^ "Licensing Declaration for US patent 6829355". Retrieved 2008-02-17. Cite journal requires `|journal=` (help)
4. ^ أ ب Dmitry Khovratovich, Christian Rechberger & Alexandra Savelieva (2011). "Bicliques for Preimages: Attacks on Skein-512 and the SHA-2 family" (PDF). IACR Cryptology ePrint Archive. 2011:286. Cite uses deprecated parameter `|lastauthoramp=` (help)
5. ^ أ ب Mario Lamberger & Florian Mendel (2011). "Higher-Order Differential Attack on Reduced SHA-256" (PDF). IACR Cryptology ePrint Archive. 2011:37. Cite uses deprecated parameter `|lastauthoramp=` (help)
6. ^ "Debian codebase in Google Code". Archived from the original on November 7, 2011. Retrieved 2011-11-08. Unknown parameter `|deadurl=` ignored (help)
7. ^ John Markoff, A Tool to Verify Digital Records, Even as Technology Shifts, New York Times, January 26, 2009
8. ^ RFC 5702,RFC-Editor.org
9. ^ Ulrich Drepper, Unix crypt with SHA-256/512
10. ^ "What Is SHA-256 And How Is It Related to Bitcoin? - Mycryptopedia". Mycryptopedia (in الإنجليزية). 2017-09-21. Retrieved 2018-09-17.
11. ^ National Institute on Standards and Technology Computer Security Resource Center, NIST's Policy on Hash Functions Archived 2011-06-09 at the Wayback Machine., accessed March 29, 2009.
12. ^ "Secure Hashing". NIST. Archived from the original on 2011-06-25. Retrieved 2010-11-25. Unknown parameter `|dead-url=` ignored (help)
13. ^ "Overview of Windows XP Service Pack 3" (PDF). Microsoft Corporation. Archived from the original (PDF) on May 30, 2008. Unknown parameter `|dead-url=` ignored (help)
14. ^ Chromium Blog, September 5, 2014, Gradually sunsetting SHA-1
15. ^ Eric Mill. "SHAAAAAAAAAAAAA". SHAAAAAAAAAAAAA.com.
16. ^ Filippo Valsorda, The Unofficial Chrome SHA1 Deprecation FAQ
17. ^ "An update to our SHA-1 deprecation roadmap – Microsoft Edge Dev BlogMicrosoft Edge Dev Blog". blogs.windows.com. Retrieved 2016-11-28.
18. ^ Fabian A. Scherschel, HeiseSecurity: Firefox: Mozilla schaltet SHA-1 ab … und direkt wieder an (german)
19. ^ Somitra Kumar Sanadhya & Palash Sarkar (2008). "New Collision Attacks Against Up To 24-step SHA-2" (PDF). IACR Cryptology ePrint Archive. 2008:270. Cite uses deprecated parameter `|lastauthoramp=` (help)
20. ^ Kazumaro Aoki; Jian Guo; Krystian Matusiewicz; Yu Sasaki & Lei Wang (2009). Preimages for step-reduced SHA-2. Advances in Cryptology – ASIACRYPT 2009. Lecture Notes in Computer Science. 5912. Springer Berlin Heidelberg. pp. 578–597. doi:10.1007/978-3-642-10366-7_34. ISBN 978-3-642-10366-7. ISSN 0302-9743. Cite uses deprecated parameter `|last-author-amp=` (help)
21. ^ Jian Guo; San Ling; Christian Rechberger & Huaxiong Wang (2010). Advanced meet-in-the-middle preimage attacks: First results on full Tiger, and improved results on MD4 and SHA-2 (PDF). Advances in Cryptology – ASIACRYPT 2010. Lecture Notes in Computer Science. 6477. Springer Berlin Heidelberg. pp. 56–75. doi:10.1007/978-3-642-17373-8_4. ISBN 978-3-642-17373-8. ISSN 0302-9743. Cite uses deprecated parameter `|last-author-amp=` (help)
22. ^ Florian Mendel; Tomislav Nad; Martin Schläffer (2013). Improving Local Collisions: New Attacks on Reduced SHA-256. Advances in Cryptology – EUROCRYPT 2013. Lecture Notes in Computer Science. 7881. Springer Berlin Heidelberg. pp. 262–278. doi:10.1007/978-3-642-38348-9_16. ISBN 978-3-642-38348-9. ISSN 0302-9743.
23. ^ Maria Eichlseder and Florian Mendel and Martin Schläffer (2014). "Branching Heuristics in Differential Collision Search with Applications to SHA-512" (PDF). IACR Cryptology ePrint Archive. 2014:302.
24. ^ Christoph Dobraunig; Maria Eichlseder & Florian Mendel (2016). "Analysis of SHA-512/224 and SHA-512/256" (PDF). Cite uses deprecated parameter `|last-author-amp=` (help); Cite journal requires `|journal=` (help)