-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hash.Sha.pp
232 lines (201 loc) · 7.9 KB
/
Hash.Sha.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{ }
{ This unit contains code from the HashLib Library }
{ by Ugochukwu Mmaduekwe licensed under the MIT }
{ license. (https://github.com/Xor-el/HashLib4Pascal) }
{ }
{*******************************************************}
{ }
{ HashLib Library }
{ Copyright (c) Ugochukwu Mmaduekwe 2016 - 2017 }
{ }
{*******************************************************}
{ }
{ The MIT License (MIT) }
{ }
{ Copyright (c) 2016 Ugochukwu Mmaduekwe }
{ }
{ Permission is hereby granted, free of charge, to any }
{ person obtaining a copy of this software and }
{ associated documentation files (the "Software"), to }
{ deal in the Software without restriction, including }
{ without limitation the rights to use, copy, modify, }
{ merge, publish, distribute, sublicense, and/or sell }
{ copies of the Software, and to permit persons to whom }
{ the Software is furnished to do so, subject to the }
{ following conditions: }
{ }
{ The above copyright notice and this permission notice }
{ shall be included in all copies or substantial }
{ portions of the Software. }
{ }
{ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF }
{ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT }
{ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS }
{ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO }
{ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE }
{ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, }
{ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, }
{ ARISING FROM, OUT OF OR IN CONNECTION WITH THE }
{ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE }
{ SOFTWARE. }
{ }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
unit Hash.Sha;
interface
uses
SysUtils,
Classes,
HlpSHA0,
HlpSHA1,
HlpSHA2_224,
HlpSHA2_256,
HlpSHA2_384,
HlpSHA2_512,
HlpSHA2_512_224,
HlpSHA2_512_256,
HlpSHA3;
type
RTSupportedShaHashTypes = (
rtSha0,
rtSha1,
rtSha224,
rtSha256,
rtSha384,
rtSha512_224,
rtSha512_256,
rtSha512,
rtSha3_224,
rtSha3_256,
rtSha3_384,
rtSha3_512
);
RTSupportedShaHashTypesSet = set of RTSupportedShaHashTypes;
RTSha = object
public
function CreateSha(S : UTF8String; ShaType : RTSupportedShaHashTypes): ansistring; static;
function Sha(S: UTF8String): ansistring; static;
function Sha0(S: UTF8String): ansistring; static;
function Sha1(S: UTF8String): ansistring; static;
function Sha224(S: UTF8String): ansistring; static;
function Sha256(S: UTF8String): ansistring; static;
function Sha384(S: UTF8String): ansistring; static;
function Sha512(S: UTF8String): ansistring; static;
function Sha512_224(S: UTF8String): ansistring; static;
function Sha512_256(S: UTF8String): ansistring; static;
function Sha3_224(S: UTF8String): ansistring; static;
function Sha3_256(S: UTF8String): ansistring; static;
function Sha3_384(S: UTF8String): ansistring; static;
function Sha3_512(S: UTF8String): ansistring; static;
end;
implementation
function RTSha.CreateSha(S : UTF8String; ShaType : RTSupportedShaHashTypes) : ansistring;
begin
case ShaType of
rtSha0 : Result := Sha(S);
rtSha1 : Result := Sha1(S);
rtSha224 : Result := Sha224(S);
rtSha256 : Result := Sha256(S);
rtSha384 : Result := Sha384(S);
rtSha512_224 : Result := Sha512_224(S);
rtSha512_256 : Result := Sha512_256(S);
rtSha512 : Result := Sha512(S);
rtSha3_224 : Result := Sha3_224(S);
rtSha3_256 : Result := Sha3_256(S);
rtSha3_384 : Result := Sha3_384(S);
rtSha3_512 : Result := Sha3_512(S);
end;
end;
function RTSha.Sha(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA0.Create().ComputeString(PChar(S), TEncoding.UTF8).ToString());
end;
function RTSha.Sha0(S: UTF8String): ansistring;
begin
Result := Sha(S);
end;
function RTSha.Sha1(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA1.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha224(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA2_224.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha256(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA2_256.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha384(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA2_384.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha512(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA2_512.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha512_224(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA2_512_224.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha512_256(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA2_512_256.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha3_224(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA3_224.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha3_256(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA3_256.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha3_384(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA3_384.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
function RTSha.Sha3_512(S: UTF8String): ansistring;
begin
Result := System.LowerCase(TSHA3_512.Create().ComputeString(PChar(S),
TEncoding.UTF8).ToString());
end;
end.