Commit 495fa3b3 authored by Niels Möller's avatar Niels Möller

Generate SHA512 intermediate values.

parent 5831b559
......@@ -27,6 +27,19 @@
# include "config.h"
#endif
#ifndef SHA512_DEBUG
# define SHA512_DEBUG 0
#endif
#if SHA512_DEBUG
# include <stdio.h>
# define DEBUG(i) \
fprintf(stderr, "%2d: %8lx %8lx %8lx %8lx\n %8lx %8lx %8lx %8lx\n", \
i, A, B, C, D ,E, F, G, H)
#else
# define DEBUG(i)
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
......@@ -117,23 +130,24 @@ _nettle_sha512_compress(uint64_t *state, const uint8_t *input, const uint64_t *k
/* Heavy mangling */
/* First 16 subrounds that act on the original data */
DEBUG(-1);
for (i = 0, d = data; i<16; i+=8, k += 8, d+= 8)
{
ROUND(A, B, C, D, E, F, G, H, k[0], d[0]);
ROUND(H, A, B, C, D, E, F, G, k[1], d[1]);
ROUND(A, B, C, D, E, F, G, H, k[0], d[0]); DEBUG(i);
ROUND(H, A, B, C, D, E, F, G, k[1], d[1]); DEBUG(i+1);
ROUND(G, H, A, B, C, D, E, F, k[2], d[2]);
ROUND(F, G, H, A, B, C, D, E, k[3], d[3]);
ROUND(E, F, G, H, A, B, C, D, k[4], d[4]);
ROUND(D, E, F, G, H, A, B, C, k[5], d[5]);
ROUND(C, D, E, F, G, H, A, B, k[6], d[6]);
ROUND(B, C, D, E, F, G, H, A, k[7], d[7]);
ROUND(C, D, E, F, G, H, A, B, k[6], d[6]); DEBUG(i+6);
ROUND(B, C, D, E, F, G, H, A, k[7], d[7]); DEBUG(i+7);
}
for (; i<80; i += 16, k+= 16)
{
ROUND(A, B, C, D, E, F, G, H, k[ 0], EXPAND(data, 0));
ROUND(H, A, B, C, D, E, F, G, k[ 1], EXPAND(data, 1));
ROUND(G, H, A, B, C, D, E, F, k[ 2], EXPAND(data, 2));
ROUND(A, B, C, D, E, F, G, H, k[ 0], EXPAND(data, 0)); DEBUG(i);
ROUND(H, A, B, C, D, E, F, G, k[ 1], EXPAND(data, 1)); DEBUG(i+1);
ROUND(G, H, A, B, C, D, E, F, k[ 2], EXPAND(data, 2)); DEBUG(i+2);
ROUND(F, G, H, A, B, C, D, E, k[ 3], EXPAND(data, 3));
ROUND(E, F, G, H, A, B, C, D, k[ 4], EXPAND(data, 4));
ROUND(D, E, F, G, H, A, B, C, k[ 5], EXPAND(data, 5));
......@@ -145,8 +159,8 @@ _nettle_sha512_compress(uint64_t *state, const uint8_t *input, const uint64_t *k
ROUND(F, G, H, A, B, C, D, E, k[11], EXPAND(data, 11));
ROUND(E, F, G, H, A, B, C, D, k[12], EXPAND(data, 12));
ROUND(D, E, F, G, H, A, B, C, k[13], EXPAND(data, 13));
ROUND(C, D, E, F, G, H, A, B, k[14], EXPAND(data, 14));
ROUND(B, C, D, E, F, G, H, A, k[15], EXPAND(data, 15));
ROUND(C, D, E, F, G, H, A, B, k[14], EXPAND(data, 14)); DEBUG(i+14);
ROUND(B, C, D, E, F, G, H, A, k[15], EXPAND(data, 15)); DEBUG(i+15);
}
/* Update state */
......@@ -158,4 +172,9 @@ _nettle_sha512_compress(uint64_t *state, const uint8_t *input, const uint64_t *k
state[5] += F;
state[6] += G;
state[7] += H;
#if SHA512_DEBUG
fprintf(stderr, "99: %8lx %8lx %8lx %8lx\n %8lx %8lx %8lx %8lx\n",
state[0], state[1], state[2], state[3],
state[4], state[5], state[6], state[7]);
#endif
}
......@@ -61,3 +61,66 @@ test_main(void)
"2354e093d76f3048 b456764346900cb1"
"30d2a4fd5dd16abb 5e30bcb850dee843"));
}
/* For first test case.
-1: 6a09e667f3bcc908 bb67ae8584caa73b 3c6ef372fe94f82b a54ff53a5f1d36f1
510e527fade682d1 9b05688c2b3e6c1f 1f83d9abfb41bd6b 5be0cd19137e2179
0: 6a09e667f3bcc908 bb67ae8584caa73b 3c6ef372fe94f82b 58cb02347ab51f91
510e527fade682d1 9b05688c2b3e6c1f 1f83d9abfb41bd6b f6afceb8bcfcddf5
1: 6a09e667f3bcc908 bb67ae8584caa73b c3d4ebfd48650ffa 58cb02347ab51f91
510e527fade682d1 9b05688c2b3e6c1f 1320f8c9fb872cc0 f6afceb8bcfcddf5
6: b47b4bb1928990e c4875b0c7abc076b af573b02403e89cd b680953951604860
5a83cb3e80050e82 5a6c781f54dcc00c 96f60209b6dc35ba 745aca4a342ed2e2
7: 8093d195e0054fa3 c4875b0c7abc076b af573b02403e89cd b680953951604860
86f67263a0f0ec0a 5a6c781f54dcc00c 96f60209b6dc35ba 745aca4a342ed2e2
8: 8093d195e0054fa3 c4875b0c7abc076b af573b02403e89cd d0403c398fc40002
86f67263a0f0ec0a 5a6c781f54dcc00c 96f60209b6dc35ba f1eca5544cb89225
9: 8093d195e0054fa3 c4875b0c7abc076b 91f460be46c52 d0403c398fc40002
86f67263a0f0ec0a 5a6c781f54dcc00c 81782d4a5db48f03 f1eca5544cb89225
14: 475975b91a7a462c fa967eed85a08028 44249631255d2ca0 5e41214388186c14
db0a9963f80c2eaa 874bfe5f6aae9f2f 860acf9effba6f61 cdf3bff2883fc9d9
15: ae07c86b1181c75 fa967eed85a08028 44249631255d2ca0 5e41214388186c14
a77b7c035dd4c161 874bfe5f6aae9f2f 860acf9effba6f61 cdf3bff2883fc9d9
16: ae07c86b1181c75 fa967eed85a08028 44249631255d2ca0 2deecc6b39d64d78
a77b7c035dd4c161 874bfe5f6aae9f2f 860acf9effba6f61 caf81a425d800537
17: ae07c86b1181c75 fa967eed85a08028 f47e8353f8047455 2deecc6b39d64d78
a77b7c035dd4c161 874bfe5f6aae9f2f 4725be249ad19e6b caf81a425d800537
18: ae07c86b1181c75 29695fd88d81dbd0 f47e8353f8047455 2deecc6b39d64d78
a77b7c035dd4c161 3c4b4104168e3edb 4725be249ad19e6b caf81a425d800537
30: 9068a4e255a0dac 4c4fbbb75f1873a6 74bf40f869094c63 e62349090f47d30a
eab4a9e5771b8d09 73e025d91b9efea3 f0aec2fe1437f085 fcdf99710f21584
31: ff4d3f1f0d46a736 4c4fbbb75f1873a6 74bf40f869094c63 e62349090f47d30a
3cd388e119e8162e 73e025d91b9efea3 f0aec2fe1437f085 fcdf99710f21584
32: ff4d3f1f0d46a736 4c4fbbb75f1873a6 74bf40f869094c63 e1034573654a106f
3cd388e119e8162e 73e025d91b9efea3 f0aec2fe1437f085 a0509015ca08c8d4
33: ff4d3f1f0d46a736 4c4fbbb75f1873a6 efabbd8bf47c041a e1034573654a106f
3cd388e119e8162e 73e025d91b9efea3 60d4e6995ed91fe6 a0509015ca08c8d4
34: ff4d3f1f0d46a736 fbae670fa780fd3 efabbd8bf47c041a e1034573654a106f
3cd388e119e8162e 2c59ec7743632621 60d4e6995ed91fe6 a0509015ca08c8d4
46: cc5100997f5710f2 f61e672694de2d67 21fbadbabab5ac6 c47c9d5c7ea8a234
35d7e7f41defcbd5 c6bc35740d8daa9a e95c2a57572d64d9 858d832ae0e8911c
47: 6b69fc1bb482feac f61e672694de2d67 21fbadbabab5ac6 c47c9d5c7ea8a234
35264334c03ac8ad c6bc35740d8daa9a e95c2a57572d64d9 858d832ae0e8911c
48: 6b69fc1bb482feac f61e672694de2d67 21fbadbabab5ac6 271580ed6c3e5650
35264334c03ac8ad c6bc35740d8daa9a e95c2a57572d64d9 571f323d96b3a047
49: 6b69fc1bb482feac f61e672694de2d67 dfe091dab182e645 271580ed6c3e5650
35264334c03ac8ad c6bc35740d8daa9a ca9bd862c5050918 571f323d96b3a047
50: 6b69fc1bb482feac 7a0d8ef821c5e1a dfe091dab182e645 271580ed6c3e5650
35264334c03ac8ad 813a43dd2c502043 ca9bd862c5050918 571f323d96b3a047
62: 4797cde4ed370692 a81dedbb9f19e643 cfcd928c5424e2b6 3857dfd2fc37d3ba
2c074484ef1eac8c 84058865d60a05fa 9aee5bda1644de5 a6af4e9c9f807e51
63: ab44e86276478d85 a81dedbb9f19e643 cfcd928c5424e2b6 3857dfd2fc37d3ba
cd881ee59ca6bc53 84058865d60a05fa 9aee5bda1644de5 a6af4e9c9f807e51
64: ab44e86276478d85 a81dedbb9f19e643 cfcd928c5424e2b6 aa84b086688a5c45
cd881ee59ca6bc53 84058865d60a05fa 9aee5bda1644de5 5a806d7e9821a501
65: ab44e86276478d85 a81dedbb9f19e643 3b5fed0d6a1f96e1 aa84b086688a5c45
cd881ee59ca6bc53 84058865d60a05fa eeb9c21bb0102598 5a806d7e9821a501
66: ab44e86276478d85 29fab5a7bff53366 3b5fed0d6a1f96e1 aa84b086688a5c45
cd881ee59ca6bc53 46c4210ab2cc155d eeb9c21bb0102598 5a806d7e9821a501
78: 995019a6ff3ba3de 10d9c4c4295599f6 d67806db8b148677 654ef9abec389ca9
c8960e6be864b916 9bb4d39778c07f9e 25c96a7768fb2aa3 ceb9fc3691ce8326
79: 73a54f399fa4b1b2 10d9c4c4295599f6 d67806db8b148677 654ef9abec389ca9
d08446aa79693ed7 9bb4d39778c07f9e 25c96a7768fb2aa3 ceb9fc3691ce8326
99: ddaf35a193617aba cc417349ae204131 12e6fa4e89a97ea2 a9eeee64b55d39a
2192992a274fc1a8 36ba3c23a3feebbd 454d4423643ce80e 2a9ac94fa54ca49f
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment