55* https://opensource.org/licenses/MIT
66***/
77
8+ #ifndef SHA1DC_SHA1_H
9+ #define SHA1DC_SHA1_H
10+
811#if defined(__cplusplus )
912extern "C" {
1013#endif
1114
15+ #ifndef SHA1DC_NO_STANDARD_INCLUDES
1216#include <stdint.h>
17+ #endif
1318
14- /* uses SHA-1 message expansion to expand the first 16 words of W[] to 80 words */
15- /* void sha1_message_expansion(uint32_t W[80]); */
16-
17- /* sha-1 compression function; first version takes a message block pre-parsed as 16 32-bit integers, second version takes an already expanded message) */
18- /* void sha1_compression(uint32_t ihv[5], const uint32_t m[16]);
19- void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]); */
20-
21- /* same as sha1_compression_W, but additionally store intermediate states */
19+ /* sha-1 compression function that takes an already expanded message, and additionally store intermediate states */
2220/* only stores states ii (the state between step ii-1 and step ii) when DOSTORESTATEii is defined in ubc_check.h */
2321void sha1_compression_states (uint32_t [5 ], const uint32_t [16 ], uint32_t [80 ], uint32_t [80 ][5 ]);
2422
2523/*
26- // function type for sha1_recompression_step_T (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5])
27- // where 0 <= T < 80
28- // me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference)
29- // state is the internal state (a,b,c,d,e) before step T of the SHA-1 compression function while processing the original message block
30- // the function will return:
31- // ihvin: the reconstructed input chaining value
32- // ihvout: the reconstructed output chaining value
24+ // Function type for sha1_recompression_step_T (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]).
25+ // Where 0 <= T < 80
26+ // me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference. )
27+ // state is the internal state (a,b,c,d,e) before step T of the SHA-1 compression function while processing the original message block.
28+ // The function will return:
29+ // ihvin: The reconstructed input chaining value.
30+ // ihvout: The reconstructed output chaining value.
3331*/
3432typedef void (* sha1_recompression_type )(uint32_t * , uint32_t * , const uint32_t * , const uint32_t * );
3533
36- /* table of sha1_recompression_step_0, ... , sha1_recompression_step_79 */
37- /* extern sha1_recompression_type sha1_recompression_step[80];*/
38-
39- /* a callback function type that can be set to be called when a collision block has been found: */
34+ /* A callback function type that can be set to be called when a collision block has been found: */
4035/* void collision_block_callback(uint64_t byteoffset, const uint32_t ihvin1[5], const uint32_t ihvin2[5], const uint32_t m1[80], const uint32_t m2[80]) */
4136typedef void (* collision_block_callback )(uint64_t , const uint32_t * , const uint32_t * , const uint32_t * , const uint32_t * );
4237
43- /* the SHA-1 context */
38+ /* The SHA-1 context. */
4439typedef struct {
4540 uint64_t total ;
4641 uint32_t ihv [5 ];
@@ -59,30 +54,34 @@ typedef struct {
5954 uint32_t states [80 ][5 ];
6055} SHA1_CTX ;
6156
62- /* initialize SHA-1 context */
57+ /* Initialize SHA-1 context. */
6358void SHA1DCInit (SHA1_CTX * );
6459
6560/*
66- // function to enable safe SHA-1 hashing:
67- // collision attacks are thwarted by hashing a detected near-collision block 3 times
68- // think of it as extending SHA-1 from 80-steps to 240-steps for such blocks:
69- // the best collision attacks against SHA-1 have complexity about 2^60,
70- // thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would 2^180
71- // an attacker would be better off using a generic birthday search of complexity 2^80
72- //
73- // enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected
74- // but it will result in a different SHA-1 hash for messages where a collision attack was detected
75- // this will automatically invalidate SHA-1 based digital signature forgeries
76- // enabled by default
61+ Function to enable safe SHA-1 hashing:
62+ Collision attacks are thwarted by hashing a detected near-collision block 3 times.
63+ Think of it as extending SHA-1 from 80-steps to 240-steps for such blocks:
64+ The best collision attacks against SHA-1 have complexity about 2^60,
65+ thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would be 2^180.
66+ An attacker would be better off using a generic birthday search of complexity 2^80.
67+
68+ Enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected,
69+ but it will result in a different SHA-1 hash for messages where a collision attack was detected.
70+ This will automatically invalidate SHA-1 based digital signature forgeries.
71+ Enabled by default.
7772*/
7873void SHA1DCSetSafeHash (SHA1_CTX * , int );
7974
80- /* function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up) */
81- /* enabled by default */
75+ /*
76+ Function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up).
77+ Enabled by default
78+ */
8279void SHA1DCSetUseUBC (SHA1_CTX * , int );
8380
84- /* function to disable or enable the use of Collision Detection */
85- /* enabled by default */
81+ /*
82+ Function to disable or enable the use of Collision Detection.
83+ Enabled by default.
84+ */
8685void SHA1DCSetUseDetectColl (SHA1_CTX * , int );
8786
8887/* function to disable or enable the detection of reduced-round SHA-1 collisions */
@@ -98,8 +97,14 @@ void SHA1DCUpdate(SHA1_CTX*, const char*, size_t);
9897
9998/* obtain SHA-1 hash from SHA-1 context */
10099/* returns: 0 = no collision detected, otherwise = collision found => warn user for active attack */
101- int SHA1DCFinal (unsigned char [20 ], SHA1_CTX * );
100+ int SHA1DCFinal (unsigned char [20 ], SHA1_CTX * );
102101
103102#if defined(__cplusplus )
104103 }
105104#endif
105+
106+ #ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H
107+ #include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_H
108+ #endif
109+
110+ #endif
0 commit comments