Skip to content

Commit 40642d2

Browse files
Turns up warning levels for visual studio build.
1 parent 2ca5907 commit 40642d2

File tree

5 files changed

+59
-44
lines changed

5 files changed

+59
-44
lines changed

Diff for: lib/sha1.c

+9
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,11 @@ static void sha1recompress_fast_ ## t (uint32_t ihvin[5], uint32_t ihvout[5], co
876876
ihvout[0] = ihvin[0] + a; ihvout[1] = ihvin[1] + b; ihvout[2] = ihvin[2] + c; ihvout[3] = ihvin[3] + d; ihvout[4] = ihvin[4] + e; \
877877
}
878878

879+
#ifdef _MSC_VER
880+
#pragma warning(push)
881+
#pragma warning(disable: 4127) /* Complier complains about the checks in the above macro being constant. */
882+
#endif
883+
879884
#ifdef DOSTORESTATE0
880885
SHA1_RECOMPRESS(0)
881886
#endif
@@ -1196,6 +1201,10 @@ SHA1_RECOMPRESS(78)
11961201
SHA1_RECOMPRESS(79)
11971202
#endif
11981203

1204+
#ifdef _MSC_VER
1205+
#pragma warning(pop)
1206+
#endif
1207+
11991208
static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5])
12001209
{
12011210
switch (step)

Diff for: lib/sha1.h

+30-36
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,26 @@ extern "C" {
1414

1515
#include <stdint.h>
1616

17-
/* uses SHA-1 message expansion to expand the first 16 words of W[] to 80 words */
18-
/* void sha1_message_expansion(uint32_t W[80]); */
19-
20-
/* sha-1 compression function; first version takes a message block pre-parsed as 16 32-bit integers, second version takes an already expanded message) */
21-
/* void sha1_compression(uint32_t ihv[5], const uint32_t m[16]);
22-
void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80]); */
23-
24-
/* same as sha1_compression_W, but additionally store intermediate states */
17+
/* sha-1 compression function that takes an already expanded message, and additionally store intermediate states */
2518
/* only stores states ii (the state between step ii-1 and step ii) when DOSTORESTATEii is defined in ubc_check.h */
2619
void sha1_compression_states(uint32_t[5], const uint32_t[16], uint32_t[80], uint32_t[80][5]);
2720

2821
/*
29-
// 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])
30-
// where 0 <= T < 80
31-
// me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference)
32-
// 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
33-
// the function will return:
34-
// ihvin: the reconstructed input chaining value
35-
// ihvout: the reconstructed output chaining value
22+
// 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]).
23+
// Where 0 <= T < 80
24+
// me2 is an expanded message (the expansion of an original message block XOR'ed with a disturbance vector's message block difference.)
25+
// 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.
26+
// The function will return:
27+
// ihvin: The reconstructed input chaining value.
28+
// ihvout: The reconstructed output chaining value.
3629
*/
3730
typedef void(*sha1_recompression_type)(uint32_t*, uint32_t*, const uint32_t*, const uint32_t*);
3831

39-
/* table of sha1_recompression_step_0, ... , sha1_recompression_step_79 */
40-
/* extern sha1_recompression_type sha1_recompression_step[80];*/
41-
42-
/* a callback function type that can be set to be called when a collision block has been found: */
32+
/* A callback function type that can be set to be called when a collision block has been found: */
4333
/* 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]) */
4434
typedef void(*collision_block_callback)(uint64_t, const uint32_t*, const uint32_t*, const uint32_t*, const uint32_t*);
4535

46-
/* the SHA-1 context */
36+
/* The SHA-1 context. */
4737
typedef struct {
4838
uint64_t total;
4939
uint32_t ihv[5];
@@ -62,30 +52,34 @@ typedef struct {
6252
uint32_t states[80][5];
6353
} SHA1_CTX;
6454

65-
/* initialize SHA-1 context */
55+
/* Initialize SHA-1 context. */
6656
void SHA1DCInit(SHA1_CTX*);
6757

6858
/*
69-
// function to enable safe SHA-1 hashing:
70-
// collision attacks are thwarted by hashing a detected near-collision block 3 times
71-
// think of it as extending SHA-1 from 80-steps to 240-steps for such blocks:
72-
// the best collision attacks against SHA-1 have complexity about 2^60,
73-
// thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would 2^180
74-
// an attacker would be better off using a generic birthday search of complexity 2^80
75-
//
76-
// enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected
77-
// but it will result in a different SHA-1 hash for messages where a collision attack was detected
78-
// this will automatically invalidate SHA-1 based digital signature forgeries
79-
// enabled by default
59+
Function to enable safe SHA-1 hashing:
60+
Collision attacks are thwarted by hashing a detected near-collision block 3 times.
61+
Think of it as extending SHA-1 from 80-steps to 240-steps for such blocks:
62+
The best collision attacks against SHA-1 have complexity about 2^60,
63+
thus for 240-steps an immediate lower-bound for the best cryptanalytic attacks would be 2^180.
64+
An attacker would be better off using a generic birthday search of complexity 2^80.
65+
66+
Enabling safe SHA-1 hashing will result in the correct SHA-1 hash for messages where no collision attack was detected,
67+
but it will result in a different SHA-1 hash for messages where a collision attack was detected.
68+
This will automatically invalidate SHA-1 based digital signature forgeries.
69+
Enabled by default.
8070
*/
8171
void SHA1DCSetSafeHash(SHA1_CTX*, int);
8272

83-
/* function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up) */
84-
/* enabled by default */
73+
/*
74+
Function to disable or enable the use of Unavoidable Bitconditions (provides a significant speed up).
75+
Enabled by default
76+
*/
8577
void SHA1DCSetUseUBC(SHA1_CTX*, int);
8678

87-
/* function to disable or enable the use of Collision Detection */
88-
/* enabled by default */
79+
/*
80+
Function to disable or enable the use of Collision Detection.
81+
Enabled by default.
82+
*/
8983
void SHA1DCSetUseDetectColl(SHA1_CTX*, int);
9084

9185
/* function to disable or enable the detection of reduced-round SHA-1 collisions */

Diff for: src/main.c

+4
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,7 @@ int main(int argc, char** argv)
104104
}
105105
return 0;
106106
}
107+
108+
#ifdef _MSC_VER
109+
#pragma warning(disable : 4710 ) /* 4710 -- compiler complains about printf,sprintf not being inlined. */
110+
#endif

Diff for: vs2015/sha1collisiondetection/sha1collisiondetection.vcxproj

+8-4
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,28 @@
9090
</PropertyGroup>
9191
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
9292
<ClCompile>
93-
<WarningLevel>Level3</WarningLevel>
93+
<WarningLevel>EnableAllWarnings</WarningLevel>
9494
<Optimization>Disabled</Optimization>
9595
<SDLCheck>true</SDLCheck>
96+
<TreatWarningAsError>true</TreatWarningAsError>
9697
</ClCompile>
9798
</ItemDefinitionGroup>
9899
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
99100
<ClCompile>
100-
<WarningLevel>Level3</WarningLevel>
101+
<WarningLevel>EnableAllWarnings</WarningLevel>
101102
<Optimization>Disabled</Optimization>
102103
<SDLCheck>true</SDLCheck>
104+
<TreatWarningAsError>true</TreatWarningAsError>
103105
</ClCompile>
104106
</ItemDefinitionGroup>
105107
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
106108
<ClCompile>
107-
<WarningLevel>Level3</WarningLevel>
109+
<WarningLevel>EnableAllWarnings</WarningLevel>
108110
<Optimization>MaxSpeed</Optimization>
109111
<FunctionLevelLinking>true</FunctionLevelLinking>
110112
<IntrinsicFunctions>true</IntrinsicFunctions>
111113
<SDLCheck>true</SDLCheck>
114+
<TreatWarningAsError>true</TreatWarningAsError>
112115
</ClCompile>
113116
<Link>
114117
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -117,11 +120,12 @@
117120
</ItemDefinitionGroup>
118121
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
119122
<ClCompile>
120-
<WarningLevel>Level3</WarningLevel>
123+
<WarningLevel>EnableAllWarnings</WarningLevel>
121124
<Optimization>MaxSpeed</Optimization>
122125
<FunctionLevelLinking>true</FunctionLevelLinking>
123126
<IntrinsicFunctions>true</IntrinsicFunctions>
124127
<SDLCheck>true</SDLCheck>
128+
<TreatWarningAsError>true</TreatWarningAsError>
125129
</ClCompile>
126130
<Link>
127131
<EnableCOMDATFolding>true</EnableCOMDATFolding>

Diff for: vs2015/sha1dcsum/sha1dcsum.vcxproj

+8-4
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@
7474
<PropertyGroup />
7575
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7676
<ClCompile>
77-
<WarningLevel>Level3</WarningLevel>
77+
<WarningLevel>EnableAllWarnings</WarningLevel>
7878
<Optimization>Disabled</Optimization>
7979
<SDLCheck>true</SDLCheck>
8080
<AdditionalIncludeDirectories>$(SolutionDir)..\lib\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
8181
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;</PreprocessorDefinitions>
82+
<TreatWarningAsError>true</TreatWarningAsError>
8283
</ClCompile>
8384
<Link>
8485
<AdditionalDependencies>sha1collisiondetection.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -94,11 +95,12 @@ copy /y $(OutDir)$(TargetName).pdb $(OutDir)$(TargetName)_partial.pdb</Command>
9495
</ItemDefinitionGroup>
9596
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
9697
<ClCompile>
97-
<WarningLevel>Level3</WarningLevel>
98+
<WarningLevel>EnableAllWarnings</WarningLevel>
9899
<Optimization>Disabled</Optimization>
99100
<SDLCheck>true</SDLCheck>
100101
<AdditionalIncludeDirectories>$(SolutionDir)..\lib\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
101102
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;</PreprocessorDefinitions>
103+
<TreatWarningAsError>true</TreatWarningAsError>
102104
</ClCompile>
103105
<Link>
104106
<AdditionalDependencies>sha1collisiondetection.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -114,13 +116,14 @@ copy /y $(OutDir)$(TargetName).pdb $(OutDir)$(TargetName)_partial.pdb</Command>
114116
</ItemDefinitionGroup>
115117
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
116118
<ClCompile>
117-
<WarningLevel>Level3</WarningLevel>
119+
<WarningLevel>EnableAllWarnings</WarningLevel>
118120
<Optimization>MaxSpeed</Optimization>
119121
<FunctionLevelLinking>true</FunctionLevelLinking>
120122
<IntrinsicFunctions>true</IntrinsicFunctions>
121123
<SDLCheck>true</SDLCheck>
122124
<AdditionalIncludeDirectories>$(SolutionDir)..\lib\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
123125
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;</PreprocessorDefinitions>
126+
<TreatWarningAsError>true</TreatWarningAsError>
124127
</ClCompile>
125128
<Link>
126129
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -138,13 +141,14 @@ copy /y $(OutDir)$(TargetName).pdb $(OutDir)$(TargetName)_partial.pdb</Command>
138141
</ItemDefinitionGroup>
139142
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
140143
<ClCompile>
141-
<WarningLevel>Level3</WarningLevel>
144+
<WarningLevel>EnableAllWarnings</WarningLevel>
142145
<Optimization>MaxSpeed</Optimization>
143146
<FunctionLevelLinking>true</FunctionLevelLinking>
144147
<IntrinsicFunctions>true</IntrinsicFunctions>
145148
<SDLCheck>true</SDLCheck>
146149
<AdditionalIncludeDirectories>$(SolutionDir)..\lib\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
147150
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;</PreprocessorDefinitions>
151+
<TreatWarningAsError>true</TreatWarningAsError>
148152
</ClCompile>
149153
<Link>
150154
<EnableCOMDATFolding>true</EnableCOMDATFolding>

0 commit comments

Comments
 (0)