Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b91c18

Browse filesBrowse files
committed
add SHA-512 capabilities to program
1 parent c5fc102 commit 1b91c18
Copy full SHA for 1b91c18

File tree

Expand file treeCollapse file tree

7 files changed

+76
-18
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+76
-18
lines changed

‎ChangeLog.md

Copy file name to clipboard
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# ChangeLog for sha256
22

3+
## Version 1.3 (2015-08-03)
4+
- add option to hash with SHA-512 instead of SHA-256
5+
36
## Version 1.2 (2015-08-01)
47
- add option to hash with SHA-224 instead of SHA-256
58

69
## Version 1.1 (2012-09-18)
710
- add option to hash with SHA-1 instead of SHA-256
811

9-
1012
## Version 1.0 (2012-08-30)
1113
- initial version

‎ReadMe.de.txt

Copy file name to clipboardExpand all lines: ReadMe.de.txt
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ folgt.
2525
Übersicht:
2626
----------
2727

28-
sha256 [--sha1 | --sha224 | --sha256] DATEINAME ...
28+
sha256 [--sha1 | --sha224 | --sha256 | --sha512] DATEINAME ...
2929

3030

3131
Optionen + Parameter:
@@ -41,6 +41,9 @@ Optionen + Parameter:
4141
Berechnet SHA-256-Prüfsummen (256bit). Dies ist die Standard-
4242
vorgabe.
4343

44+
--sha512
45+
Berechnet SHA-512-Prüfsummen (512bit) anstelle von SHA-256.
46+
4447
--help
4548
Zeigt einen (englischen) Hilfetext und listet gültige Programm-
4649
optionen auf.

‎ReadMe.en.txt

Copy file name to clipboardExpand all lines: ReadMe.en.txt
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Purpose of the program:
1010
The sha256 program calculates and prints SHA-256 (256bit) checksums of
1111
all files that are passed to it as command line parameters.
1212
As of version 1.1 it can also be used to calculate SHA-1 (160bit)
13-
checksums, if desired. Version 1.2 also offers SHA-224 (224bit checksum).
13+
checksums, if desired. Version 1.2 also offers SHA-224 (224bit checksum),
14+
Version 1.3 added SHA-512 (512bit checksum).
1415

1516

1617
Program call:
@@ -23,7 +24,7 @@ command line/ shell. A list of valid options follows below.
2324
Synopsis:
2425
---------
2526

26-
sha256 [--sha1 | --sha224 | --sha256] FILENAME ...
27+
sha256 [--sha1 | --sha224 | --sha256 | --sha512] FILENAME ...
2728

2829

2930
Options + parameters:
@@ -38,6 +39,9 @@ Options + parameters:
3839
--sha256
3940
Calculate SHA-256 (256bit) checksums. This is the default.
4041

42+
--sha512
43+
Calculate SHA-512 (512bit) checksums instead of SHA-256.
44+
4145
--help
4246
Show a help message and list valid program options.
4347

‎readme.md

Copy file name to clipboardExpand all lines: readme.md
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
The sha256 program calculates and prints SHA-256 (256bit) checksums
88
of all files that are passed to it as command line parameters.
99
As of version 1.1 it can also be used to calculate SHA-1 (160bit)
10-
checksums, if desired. Version 1.2 also offers SHA-224 (224bit checksum).
10+
checksums, if desired. Version 1.2 also offers SHA-224 (224bit checksum),
11+
SHA-512 is available since version 1.3.
1112

1213
## Program call
1314

@@ -17,7 +18,7 @@ via command line/ shell. A list of valid options follows below.
1718

1819
### Synopsis
1920

20-
sha256 [--sha1 | --sha224 | --sha256] FILENAME ...
21+
sha256 [--sha1 | --sha224 | --sha256 | --sha512] FILENAME ...
2122

2223

2324
### Options + parameters
@@ -31,6 +32,9 @@ via command line/ shell. A list of valid options follows below.
3132
--sha256
3233
Calculate SHA-256 (256bit) checksums. This is the default.
3334

35+
--sha512
36+
Calculate SHA-512 (512bit) checksums instead of SHA-256.
37+
3438
--help
3539
Show a help message and list valid program options.
3640

‎sha256/CMakeLists.txt

Copy file name to clipboardExpand all lines: sha256/CMakeLists.txt
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ set(sha256_sources
1616
../libthoro/hash/sha256/FileSource.cpp
1717
../libthoro/hash/sha256/FileSourceUtility.cpp
1818
../libthoro/hash/sha256/MessageSource.cpp
19+
../libthoro/hash/sha512/FileSource.cpp
20+
../libthoro/hash/sha512/FileSourceUtility.cpp
21+
../libthoro/hash/sha512/MessageSource.cpp
22+
../libthoro/hash/sha512/sha512.cpp
1923
main.cpp)
2024

2125
if (CMAKE_COMPILER_IS_GNUCC)

‎sha256/main.cpp

Copy file name to clipboardExpand all lines: sha256/main.cpp
+44-12Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
-------------------------------------------------------------------------------
33
This file is part of the SHA-256 hash calculator.
4-
Copyright (C) 2012 Thoronador
4+
Copyright (C) 2012, 2015 Thoronador
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -22,6 +22,9 @@
2222
#include <set>
2323
#include <string>
2424
#include "../libthoro/filesystem/FileFunctions.hpp"
25+
#include "../libthoro/hash/sha512/sha512.hpp"
26+
#include "../libthoro/hash/sha512/FileSource.hpp"
27+
#include "../libthoro/hash/sha512/FileSourceUtility.hpp"
2528
#include "../libthoro/hash/sha256/sha256.hpp"
2629
#include "../libthoro/hash/sha256/FileSource.hpp"
2730
#include "../libthoro/hash/sha256/FileSourceUtility.hpp"
@@ -40,49 +43,50 @@ void showGPLNotice()
4043
std::cout << "SHA-256 file hash calculator\n"
4144
<< " Copyright (C) 2012, 2015 Thoronador\n"
4245
<< "\n"
43-
<< " This programme is free software: you can redistribute it and/or\n"
46+
<< " This program is free software: you can redistribute it and/or\n"
4447
<< " modify it under the terms of the GNU General Public License as published\n"
4548
<< " by the Free Software Foundation, either version 3 of the License, or\n"
4649
<< " (at your option) any later version.\n"
4750
<< "\n"
48-
<< " This programme is distributed in the hope that they will be useful,\n"
51+
<< " This program is distributed in the hope that they will be useful,\n"
4952
<< " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
5053
<< " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
5154
<< " GNU General Public License for more details.\n"
5255
<< "\n"
5356
<< " You should have received a copy of the GNU General Public License\n"
54-
<< " along with this programme. If not, see <http://www.gnu.org/licenses/>.\n"
57+
<< " along with this program. If not, see <http://www.gnu.org/licenses/>.\n"
5558
<< "\n";
5659
}
5760

5861
void showVersion()
5962
{
6063
showGPLNotice();
61-
std::cout << "SHA-256 file hash calculator, version 1.2, 2015-08-01\n";
64+
std::cout << "SHA-256 file hash calculator, version 1.3, 2015-08-03\n";
6265
}
6366

6467
void showHelp()
6568
{
66-
std::cout << "\nsha256 [--sha1 | --sha224 | --sha256] FILENAME\n"
69+
std::cout << "\nsha256 [--sha1 | --sha224 | --sha256 | --sha512] FILENAME\n"
6770
<< "\n"
6871
<< "options:\n"
6972
<< " --help - displays this help message and quits\n"
7073
<< " -? - same as --help\n"
71-
<< " --version - displays the version of the programme and quits\n"
74+
<< " --version - displays the version of the program and quits\n"
7275
<< " -v - same as --version\n"
7376
<< " FILENAME - set path to file that should be hashed. Can be repeated\n"
74-
<< " multiple times.\n"
77+
<< " multiple times. Has to appear at least once.\n"
7578
<< " --sha1 - use SHA-1 instead of SHA-256 to hash files.\n"
7679
<< " --sha224 - use SHA-224 instead of SHA-256 to hash files.\n"
7780
<< " --sha256 - use SHA-256 to hash files. This option is active by\n"
78-
<< " default.\n";
81+
<< " default.\n"
82+
<< " --sha512 - use SHA-512 instead of SHA-256 to hash files.\n";
7983
}
8084

8185
int main(int argc, char **argv)
8286
{
8387
std::set<std::string> files;
8488

85-
enum SHAHashType {htUnspecified, htSHA1, htSHA224, htSHA256 };
89+
enum SHAHashType {htUnspecified, htSHA1, htSHA224, htSHA256, htSHA512 };
8690

8791
SHAHashType hashType = htUnspecified;
8892

@@ -152,6 +156,21 @@ int main(int argc, char **argv)
152156
}
153157
hashType = htSHA256;
154158
}//sha-256
159+
else if ((param=="--sha512") or (param=="--sha-512"))
160+
{
161+
if (hashType==htSHA512)
162+
{
163+
std::cout << "Error: parameter " << param << " must not occur more than once!\n";
164+
return rcInvalidParameter;
165+
}
166+
if (hashType!=htUnspecified)
167+
{
168+
std::cout << "Error: parameter " << param << " must not occur "
169+
<< "after hash type has already been set!\n";
170+
return rcInvalidParameter;
171+
}
172+
hashType = htSHA512;
173+
}//sha-512
155174
else
156175
{
157176
//should be filename
@@ -179,17 +198,26 @@ int main(int argc, char **argv)
179198
}//if arguments present
180199
else
181200
{
182-
std::cout << "You have to specify certain parameters for this programme to run properly.\n"
201+
std::cout << "You have to specify certain parameters for this program to run properly.\n"
202+
<< "Use --help to get a list of valid parameters.\n";
203+
return rcInvalidParameter;
204+
}
205+
206+
if (files.empty())
207+
{
208+
std::cout << "You have to specify certain parameters for this program to run properly.\n"
183209
<< "Use --help to get a list of valid parameters.\n";
184210
return rcInvalidParameter;
185211
}
186212

213+
// Set default hash algorithm, if no choice was made.
187214
if (hashType==htUnspecified)
188215
hashType = htSHA256;
189216

190-
std::cout << std::endl << "Hashing file(s), this may take a while..." << std::endl;
217+
std::cout << "Hashing file(s), this may take a while..." << std::endl;
191218

192219
std::set<std::string>::const_iterator iter = files.begin();
220+
SHA512::MessageDigest hash512;
193221
SHA256::MessageDigest hash256;
194222
SHA224::MessageDigest hash224;
195223
SHA1::MessageDigest hash160;
@@ -205,6 +233,10 @@ int main(int argc, char **argv)
205233
hash224 = SHA224::computeFromFile(*iter);
206234
std::cout << hash224.toHexString() << " " << *iter << std::endl;
207235
break;
236+
case htSHA512:
237+
hash512 = SHA512::computeFromFile(*iter);
238+
std::cout << hash512.toHexString() << " " << *iter << std::endl;
239+
break;
208240
default:
209241
hash256 = SHA256::computeFromFile(*iter);
210242
std::cout << hash256.toHexString() << " " << *iter << std::endl;

‎sha256/sha256.cbp

Copy file name to clipboardExpand all lines: sha256/sha256.cbp
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
<Unit filename="../libthoro/hash/sha256/functions.hpp" />
5858
<Unit filename="../libthoro/hash/sha256/sha256.cpp" />
5959
<Unit filename="../libthoro/hash/sha256/sha256.hpp" />
60+
<Unit filename="../libthoro/hash/sha512/FileSource.cpp" />
61+
<Unit filename="../libthoro/hash/sha512/FileSource.hpp" />
62+
<Unit filename="../libthoro/hash/sha512/FileSourceUtility.cpp" />
63+
<Unit filename="../libthoro/hash/sha512/FileSourceUtility.hpp" />
64+
<Unit filename="../libthoro/hash/sha512/MessageSource.cpp" />
65+
<Unit filename="../libthoro/hash/sha512/MessageSource.hpp" />
66+
<Unit filename="../libthoro/hash/sha512/functions.hpp" />
67+
<Unit filename="../libthoro/hash/sha512/sha512.cpp" />
68+
<Unit filename="../libthoro/hash/sha512/sha512.hpp" />
6069
<Unit filename="main.cpp" />
6170
<Extensions>
6271
<code_completion />

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.