-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviathinksoft-std-0006-mha2.html
More file actions
757 lines (493 loc) · 27.1 KB
/
viathinksoft-std-0006-mha2.html
File metadata and controls
757 lines (493 loc) · 27.1 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
<!DOCTYPE html>
<html lang="en">
<!-- DO NOT EDIT THIS FILE. IT IS GENERATED BY GENERATE.PHPS -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Marschall Hash 2 (MHA2)</title>
<style>
/** === DESKTOP === */
@media (min-width: 601px) {
a, a:visited, a:link, a:active, a:hover {
color: #046D95 !important;
}
body {
color: black !important;
background-color: #f5f5f5 !important;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
}
.page {
width: 100%;
max-width: 700px; /* 72 Zeichen Breite in Pixel (bei Desktop-Ansicht) */
margin-bottom: 20px;
padding: 20px;
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
font-family: monospace;
white-space: pre-wrap;
overflow: hidden;
border: 1px solid #ccc;
box-sizing: border-box;
}
}
/** === MOBILE === */
@media (max-width: 600px) {
a, a:visited, a:link, a:active, a:hover {
color: #046D95 !important;
}
body {
color: black !important;
background-color: #f5f5f5 !important;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
width: 100%;
padding: 10px;
box-sizing: border-box;
}
.page {
width: 100%;
max-width: 100%; /* Ensures the page takes up full width on mobile */
margin-bottom: 20px;
padding: 10px;
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
font-family: monospace;
white-space: pre-wrap;
overflow: auto; /* Ensures overflow is handled */
border: 1px solid #ccc;
box-sizing: border-box;
font-size: 8.7px; /* Smaller font size for mobile */
}
}
</style>
</head>
<body>
<span style="font-family:Verdana">← <a href="index.html">Back to Standards index</a></span><br><br>
<div id="content">
<div class="container"><div class="page"><pre>VIATHINKSOFT/WEBFAN D. Marschall
SPECIFICATION No. 6 ViaThinkSoft
First Draft: 2014 4 September 2024
=== Marschall Hash 2 (MHA2) ===
Abstract
This document describes the hash algorithm MHA2.
Identification of this Document
Revision: 2024-09-04
State: Deprecated
Filename: viathinksoft-std-0006-mha2.txt
URN: urn:x-viathinksoft:std:0006:2024-09-04
OID: 1.3.6.1.4.1.37476.3.2.1.2
{ iso(1) identified-organization(3) dod(6) internet(1)
private(4) enterprise(1) 37476 specifications(3)
algorithm(2) hash(1) mha2(2) }
WEID: P-SX0-3-2-1-2-9
IETF/RFC: (None)
Attachments
Reference implementation in PHP:
<a href="https://github.com/danielmarschall/php_utils/blob/master/vts_crypt.inc.php">https://github.com/danielmarschall/php_utils/blob/master/</a>
<a href="https://github.com/danielmarschall/php_utils/blob/master/vts_crypt.inc.php">vts_crypt.inc.php</a>
Copyright Notice
Copyright (c) 2014-2024 ViaThinkSoft and the persons identified as
the document authors. All rights reserved.
Licensed under the terms of the Apache 2.0 License.
<span class="grey">Marschall [Page 1]</span></pre>
</div><div class="page"><span class="noprint" id="page-2"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
Table of Contents
<a href="#section-1">1</a> Introduction . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-3">3</a>
<a href="#section-1.1">1.1</a> Terminology . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-3">3</a>
<a href="#section-2">2</a> Definition . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-3">3</a>
<a href="#section-2.1">2.1</a> Example . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-4">4</a>
<a href="#section-3">3</a> Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-4">4</a>
<a href="#section-3.1">3.1</a> Modular Crypt Format Notation . . . . . . . . . . . . . . . <a href="#page-4">4</a>
<a href="#section-3.2">3.2</a> Heterogenous Systems Notation . . . . . . . . . . . . . . . <a href="#page-5">5</a>
<a href="#section-4">4</a> Test Vectors . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-6">6</a>
<a href="#section-5">5</a> Reference implementation . . . . . . . . . . . . . . . . . . . <a href="#page-8">8</a>
<a href="#section-6">6</a> Security Considerations . . . . . . . . . . . . . . . . . . . . <a href="#page-8">8</a>
<a href="#section-6.1">6.1</a> Runtime complexity . . . . . . . . . . . . . . . . . . . . <a href="#page-10">10</a>
<a href="#section-7">7</a> RA Considerations . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-11">11</a>
<a href="#section-8">8</a> References . . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-11">11</a>
<a href="#section-6.1">6.1</a> Normative References . . . . . . . . . . . . . . . . . . . <a href="#page-11">11</a>
<a href="#section-6.2">6.2</a> Informative References . . . . . . . . . . . . . . . . . . <a href="#page-12">12</a>
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-12">12</a>
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . <a href="#page-12">12</a>
<span class="grey">Marschall [Page 2]</span></pre>
</div><div class="page"><span class="noprint" id="page-3"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
<h2><a class="selflink" id="section-1" href="#section-1">1</a> Introduction</h2>
MHA2 is a method to strengten a weak hash function, e.g. in case that
the development environment or hardware does not allow using a new
implementation of a modern hash variant like SHA256 or SHA3.
<h3><a class="selflink" id="section-1.1" href="#section-1.1">1.1</a> Terminology</h3>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
<a href="https://datatracker.ietf.org/doc/html/bcp14">BCP 14</a> [<a href="https://datatracker.ietf.org/doc/html/rfc2119">RFC2119</a>] [<a href="https://datatracker.ietf.org/doc/html/rfc8174">RFC8174</a>] when, and only when, they appear in all
capitals, as shown here.
<h2><a class="selflink" id="section-2" href="#section-2">2</a> Definition</h2>
MHA2(i,s,x) := A(i,s,x) xor B(i,s,x) xor C(i,s,x)
with:
A(j,s,x) := j>=0: H(P & A(j-1, s, x) & x & s & Q)
j=-1: ''
B(j,s,x) := j<=0: H(Q & s & x & B(j-1, s, x) & P)
j=-1: ''
C(j,s,x) := H( (K&x&s)*(j+1) )
K := 0x24 & 0x12 & 0x19 & 0x87
P := 0x12 & 0x24 & 0x19 & 0x87
Q := 0x19 & 0x87 & 0x12 & 0x24
where:
i is the number of iterations, i <= 0.
j is a number <= -1 .
s is the salt.
x is the input data.
0xd is a single byte with the hexadecimal value d.
H(z) is an existing hash function.
All hash operations have a binary output;
no string conversation is done.
x*z are z repetitions (concatenations) of x.
<span class="grey">Marschall [Page 3]</span></pre>
</div><div class="page"><span class="noprint" id="page-4"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
& is concatenation.
<h3><a class="selflink" id="section-2.1" href="#section-2.1">2.1</a> Example</h3>
- MHA2(1, '', x) = H(P & H(P&x&Q) & x & Q) xor
H(Q & x & H(Q&x&P) & P) xor H(K&x&s & K&x&s)
- MHA2(1, s, x) = H(P & H(P&x&s&Q) & x & s & Q)
xor H(Q & s & x & H(Q&s&x&P) & P) xor H(K&x&s & K&x&s)
<h2><a class="selflink" id="section-3" href="#section-3">3</a> Notation</h2>
<h3><a class="selflink" id="section-3.1" href="#section-3.1">3.1</a> Modular Crypt Format Notation</h3>
Format of the MCF:
$<id>$<params>$<salt>$<hash>
<id> is 1.3.6.1.4.1.37476.3.2.1.1
<params> is a=<algo>,i=<iterations>
where <algo> is any valid hash algorithm (name scheme of PHP
hash_algos() preferred), e.g.
- sha3-512
- sha3-384
- sha3-256
- sha3-224
- sha512
- sha512/256
- sha512/224
- sha384
- sha256
- sha224
- sha1
- md5
Not possible with MHA2 are these hashes (because they have a special
salt-handling and output their own crypt format):
- bcrypt [Standardized crypt identifier 2, 2a, 2b, 2x, 2y]
- argon2i [Crypt identifier argon2i, not standardized]
- argon2id [Crypt identifier argon2id, not standardized]
<iterations> are the iterations.
Like most Crypt-hashes, <salt> and <hash> are Radix64 coded without
padding and with alphabet
'./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
<span class="grey">Marschall [Page 4]</span></pre>
</div><div class="page"><span class="noprint" id="page-5"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
<h3><a class="selflink" id="section-3.2" href="#section-3.2">3.2</a> Heterogenous Systems Notation</h3>
The "heterogenous systems notation" (HSN) is DEPRECATED in favor of
the modular crypt format notation!
<mha2-oid>$<base-hash>$<iterations>$<salt-base64>$<hash-base64>
- <mha2-oid> is the OID for a MHA2 algorithm in its dot-notation
without leading dot, which is 1.3.6.1.4.1.37476.3.2.1.2
This OID has ASN.1 Notation: { iso(1) identified-organization(3)
dod(6) internet(1) private(4) enterprise(1) 37476
specification(3) algorithm(2) hash(1) mha2(2) }
- <base-hash> should be an OID which represents the base hash ("H")
algorithm used, in dot-notation.
The following table shows the OIDs which have been assigned for
exchange between heterogenous systems. If you want to use a different
hash algorithm or a derivate of it, please define your own OID
(you can use an UUID OID, get a free IANA PEN OID, or a free
ViaThinkSoft OID), but please do not use this arc, since only
ViaThinkSoft may maintain it.
--------------------------------------------------------------
Base algorithm OID proposal
--------------------------------------------------------------
Message Digest 4 (MD4) 1.3.6.1.4.1.37476.3.2.1.99.1
Message Digest 5 (MD5) 1.3.6.1.4.1.37476.3.2.1.99.2
RIPEMD-160 1.3.6.1.4.1.37476.3.2.1.99.3
Secure Hash Algorithm 1.3.6.1.4.1.37476.3.2.1.99.4
Secure Hash Algorithm 1 1.3.6.1.4.1.37476.3.2.1.99.5
Secure Hash Algorithm 2/224 1.3.6.1.4.1.37476.3.2.1.99.6.224
Secure Hash Algorithm 2/256 1.3.6.1.4.1.37476.3.2.1.99.6.256
Secure Hash Algorithm 2/384 1.3.6.1.4.1.37476.3.2.1.99.6.384
Secure Hash Algorithm 2/512 1.3.6.1.4.1.37476.3.2.1.99.6.512
Secure Hash Algorithm 3/224 1.3.6.1.4.1.37476.3.2.1.99.7.224
Secure Hash Algorithm 3/256 1.3.6.1.4.1.37476.3.2.1.99.7.256
Secure Hash Algorithm 3/384 1.3.6.1.4.1.37476.3.2.1.99.7.384
Secure Hash Algorithm 3/512 1.3.6.1.4.1.37476.3.2.1.99.7.512
--------------------------------------------------------------
- <iterations> is the number of iterations, e.g. 1987.
- <salt-base64> is the iterated salt used for MHA2, encoded in
Base64.
- <hash-base64> is the resulting hash, encoded in Base64.
<span class="grey">Marschall [Page 5]</span></pre>
</div><div class="page"><span class="noprint" id="page-6"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
<h2><a class="selflink" id="section-4" href="#section-4">4</a> Test Vectors</h2>
MHA2 - Base algo 'sha1', Input '', Salt '', Iterations 0
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=0$$NKCUx/Vbzl1cuIdoIA
WNBJapRpG
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$0$
$PMEWz1Xd/n3ewKfqKCYPDLcrTrI=
Hex: 3cc116cf55ddfe7ddec0a7ea28260f0cb72b4eb2
MHA2 - Base algo 'sha1', Input '', Salt '', Iterations 1
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=1$$PoioZBIxVWuqt0nym5
qyhAszLwC
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$1$
$RqkqbDKzXYwsv2p+o7s+jCu/NyE=
Hex: 46a92a6c32b35d8c2cbf6a7ea3bb3e8c2bbf3721
MHA2 - Base algo 'sha1', Input '', Salt '', Iterations 2
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=2$$1zU5hmBQ9/ZewYq43q
rXd2D8QRK
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$2$
$3/W7joDSB1bgyas65stZf4FASTM=
Hex: dff5bb8e80d20756e0c9ab3ae6cb597f81404933
MHA2 - Base algo 'sha1', Input '', Salt 'salt', Iterations 0
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=0$a0Dqb8$zZjdOSIocsFG
Qp/.hpoYQLOfiN6
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$0$
c2FsdA==$/blfQUKqeuHISr10jrqaSNQhkP8=
Hex: fdb95f4142aa7ae1c84abd748eba9a48d42190ff
MHA2 - Base algo 'sha1', Input '', Salt 'salt', Iterations 1
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=1$a0Dqb8$BkKmNoOvKEss
6ek6EyXArDX1Z.8
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$1$
c2FsdA==$DmMoPqQxMGuu8gm8G+ZCtFZ3b0A=
Hex: 0e63283ea431306baef209bc1be642b456776f40
MHA2 - Base algo 'sha1', Input '', Salt 'salt', Iterations 2
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=2$a0Dqb8$8HauBcPn31A4
EuUKUf.vcbg1K/O
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$2$
c2FsdA==$AJcwDeRp53C6GwWMWh0xedi3M1Q=
Hex: 0097300de469e770ba1b058c5a1d3179d8b73354
MHA2 - Base algo 'sha1',
Input 'The quick brown fox jumps over the lazy dog',
Salt '', Iterations 0
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=0$$/oEBf.u/XEwY8r12lI
<span class="grey">Marschall [Page 6]</span></pre>
</div><div class="page"><span class="noprint" id="page-7"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
lk.4wWH6m
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$0$
$1qGDh0w1ZGyaAt34nKnm06yYJ8o=
Hex: d6a183874c35646c9a02ddf89ca9e6d3ac9827ca
MHA2 - Base algo 'sha1',
Input 'The quick brown fox jumps over the lazy dog',
Salt '', Iterations 1
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=1$$9zbRpQFxyeyoJj0keA
dMpjXdvuK
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$1$
$B/dTrSHz+g+qLl2mgCfOrlZfxwM=
Hex: 07f753ad21f3fa0faa2e5da68027ceae565fc703
MHA2 - Base algo 'sha1',
Input 'The quick brown fox jumps over the lazy dog',
Salt '', Iterations 2
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=2$$gGCiACHhKqZgNFztpF
zsncKMCTS
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$2$
$iIEkCEJjMsbiPH/vrH/upeMOEVU=
Hex: 88812408426332c6e23c7fefac7feea5e30e1155
MHA2 - Base algo 'sha1',
Input 'The quick brown fox jumps over the lazy dog',
Salt 'salt', Iterations 0
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=0$a0Dqb8$EFuadpjXUzjJ
BNVfZHS.iQ/.dM2
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$0$
c2FsdA==$GHwcfrlZW/lLDPXhbJU0kS10fO4=
Hex: 187c1c7eb9595bf94b0cf5e16c9534912d747cee
MHA2 - Base algo 'sha1',
Input 'The quick brown fox jumps over the lazy dog',
Salt 'salt', Iterations 1
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=1$a0Dqb8$fMnarhbJV/XF
qzP38t7RJEdHKJ2
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$1$
c2FsdA==$hOpctjdLX1ZHs/R5Av9TLGfJML4=
Hex: 84ea5cb6374b5f5647b3f47902ff532c67c930be
MHA2 - Base algo 'sha1',
Input 'The quick brown fox jumps over the lazy dog',
Salt 'salt', Iterations 2
MCF: $1.3.6.1.4.1.37476.3.2.1.2$a=sha1,i=2$a0Dqb8$dECLjkOyRDCv
5W9QS4Qm3ZgXRh2
HSN: 1.3.6.1.4.1.37476.3.2.1.2$1.3.6.1.4.1.37476.3.2.1.99.5$2$
c2FsdA==$fGENlmQ+TFEx7YBSU6So5biZTj4=
<span class="grey">Marschall [Page 7]</span></pre>
</div><div class="page"><span class="noprint" id="page-8"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
Hex: 7c610d96643e4c5131ed805253a4a8e5b8994e3e
<h2><a class="selflink" id="section-5" href="#section-5">5</a> Reference implementation</h2>
// Implementation in PHP, with hex output
define('MHA2_K', chr(0x24).chr(0x12).chr(0x19).chr(0x87));
define('MHA2_P', chr(0x12).chr(0x24).chr(0x19).chr(0x87));
define('MHA2_Q', chr(0x19).chr(0x87).chr(0x12).chr(0x24));
function mha2($message, $salt, $iterations, $base_algo) {
assert($iterations>=0);
$a = '';
$b = '';
$c = '';
for ($i=0; $i<=$iterations; $i++) { // run $iterations+1 times
$a = hash($base_algo,
MHA2_P.$a.$message.$salt.MHA2_Q, true/*binary*/);
$b = hash($base_algo,
MHA2_Q.$salt.$message.$b.MHA2_P, true/*binary*/);
$c .= MHA2_K.$message.$salt;
}
$c = hash($base_algo, $c, true/*binary*/);
return bin2hex($a ^ $b ^ $c);
}
// Framework for PHP, with MCF output and auto-generated salt:
// <a href="https://github.com/danielmarschall/php_utils/blob/master///">https://github.com/danielmarschall/php_utils/blob/master/</a>
<a href="https://github.com/danielmarschall/php_utils/blob/master///">//</a> vts_crypt.inc.php
include 'vts_crypt.inc.php';
$hash = vts_password_hash($data, PASSWORD_VTS_MHA2,
['algo'=>'sha1', 'salt_length'=>16, 'iterations'=>1987]);
assert(vts_password_verify($data, $hash));
<h2><a class="selflink" id="section-6" href="#section-6">6</a> Security Considerations</h2>
Hash values play a crucial role in various security contexts, such as
password verification. For detailed guidance on securely managing
hashes, please consult the relevant literature or documentation.
- The output length of MHA2(i, s, x) is equal to the output length of
H(z).
- MHA2(i, '', s & x) != MHA2(i, s, x) != MHA2(i, '', x & s).
- It is recommended not to use i=0.
- P, Q and K are chosen to arbitrary data . It can be chosen to a
different value, but should not be empty.
<span class="grey">Marschall [Page 8]</span></pre>
</div><div class="page"><span class="noprint" id="page-9"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
- P should never be equal to Q, otherwise, A(i,s,x) could become
equal to B(i,s,x).
Possible "optimizations" (vulnerabilities) can be done if P&Q = Q&P:
a) If i = 0 and s&x = x&s:
=> A(0, s, x) = B(0, s, x)
=> MHA2(0, s, x) = H(K&x&s)
b) If s&x='' (s='' and x=''):
=> A(i, '', '') = B(i, '', '')
=> MHA2(i, '', '') = H('')
c) If z := s&x = x&s:
=> H(s&x) = H(x&s) = H(z)
=> H(s&x) = A(0,s,x) = H(z) = B(0,s,x) = H(P&x&s&Q)
= H(Q&s&x&P)
=> in A(i,s,x) and B(i,s,x),
this embedded value H(z) has to be calculated only once.
Note: s&x = x&s is true if one of the following conditions is true:
x = '' or
s = '' or
x = s
- If H(x) is compromised, MHA2 (even unsalted) would be still safe.
Examples:
i = 0, unsalted (s=''):
H(P&x&Q) = H(P&y&Q) = c
=> MHA2(0, '', x) = c xor c xor H(K&x)
= c xor c xor H(K&y)
= MHA2(0, '', y)
=> H(K&x) ?= H(K&y)
i = 1, unsalted (s=''):
H(P&x&Q) = H(P&y&Q) = c
=> MHA2(1, '', x) = H(P&c&x&Q) xor H(Q&x&c&P) xor H(K&x&K&x)
= H(P&c&y&Q) xor H(Q&y&c&P) xor H(K&y&K&y)
= MHA2(1, '', y)
=> H(P&c&x&Q) xor H(Q&x&c&P) xor H(K&x&K&x)
?= H(P&c&y&Q) xor H(Q&y&c&P) xor H(K&y&K&y)
i = 2, unsalted (s=''):
H(P&x&Q) = H(P&y&Q) = c
=> MHA2(2, '', x) = H(P&H(P&c&x&Q)&x&Q) xor
H(Q&x&H(Q&x&c&P)&P) xor H(K&x&K&x&K&x) =
H(P&H(P&c&y&Q)&y&Q) xor H(&Qx&H(&Qy&c&P)&P)
xor H(K&y&K&y&K&y) = MHA2(2, '', y)
<span class="grey">Marschall [Page 9]</span></pre>
</div><div class="page"><span class="noprint" id="page-10"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
=> H(P&H(P&c&x&Q)&x&Q) xor H(Q&x&H(Q&x&c&P)&P)
xor H(K&x&K&x&K&x) ?= H(P&H(P&c&y&Q)&y&Q)
xor H(Q&x&H(Q&y&c&P)&P) xor H(K&y&K&y&K&y)
- If a high value for i is chosen, the hash will be slow. Therefore,
the creation of a rainbow table or brute force attacks will be slow
(see runtime section). On the other hand, a brute force attack could
result in a DoS if the CPU of the server is too weak.
- The salt should always be set. The salt should be a merge of an
individual (random unique) user-specific salt, a service-specific
salt and server-specific salt. s = userSalt & serviceSalt &
serverSalt
- For the third xor argument "xor C(i,s,x)" is not required, but does
probably strengten the algorithm in case that an attack can be found
where A(i,s,x) = B(i,s,x) can be enforced.
<h3><a class="selflink" id="section-6.1" href="#section-6.1">6.1</a> Runtime complexity</h3>
The following table will show the required executions of the hash
function H(z) on given number of different values of i:
------------------
i H(z)-calls
------------------
0 3
1 5
2 7
3 9
n 2n+3
------------------
<span class="grey">Marschall [Page 10]</span></pre>
</div><div class="page"><span class="noprint" id="page-11"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
<h2><a class="selflink" id="section-7" href="#section-7">7</a> RA Considerations</h2>
OID: 1.3.6.1.4.1.37476.3.2.1.2
WEID: P-SX0-3-2-1-2-9
ASN1: { iso(1) identified-organization(3) dod(6) internet(1)
private(4) enterprise(1) 37476 specifications(3)
algorithm(2) hash(1) mha2(2) }
IRI: /.../Specifications/Algorithm/Hash/MHA2
OID: 1.3.6.1.4.1.37476.3.2.1.99
ASN1: { iso(1) identified-organization(3) dod(6) internet(1)
private(4) enterprise(1) 37476 specifications(3) algorithm(2)
hash(1) foreign(99) }
IRI: /.../Specifications/Algorithm/Hash/Foreign
WEID: P-SX0-3-2-1-2R-2
Children:
+ md4(1), IRI MD4
+ md5(3), IRI MD5
+ ripemd160(3), IRI RIPEMD-160
+ sha0(4), IRI SHA0
+ sha1(5), IRI SHA1
+ sha2(6), IRI SHA2
+ ... <a href="#page-224">224</a>
+ ... <a href="#page-256">256</a>
+ ... <a href="#page-384">384</a>
+ ... <a href="#page-512">512</a>
+ ... ... <a href="#page-224">224</a>
+ ... ... <a href="#page-256">256</a>
+ sha3(7), IRI SHA3
+ ... <a href="#page-224">224</a>
+ ... <a href="#page-256">256</a>
+ ... <a href="#page-384">384</a>
+ ... <a href="#page-512">512</a>
+ shake(8), IRI SHAKE
+ ... <a href="#page-128">128</a>
+ ... <a href="#page-256">256</a>
<h2><a class="selflink" id="section-8" href="#section-8">8</a> References</h2>
<h3><a class="selflink" id="section-6.1" href="#section-6.1">6.1</a> Normative References</h3>
[<a id="ref-RFC2119">RFC2119</a>] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", <a href="https://datatracker.ietf.org/doc/html/bcp14">BCP 14</a>, <a href="https://datatracker.ietf.org/doc/html/rfc2119">RFC 2119</a>,
DOI 10.17487/RFC2119, March 1997,
<<a href="https://www.rfc-editor.org/info/rfc2119">https://www.rfc-editor.org/info/rfc2119</a>>.
<span class="grey">Marschall [Page 11]</span></pre>
</div><div class="page"><span class="noprint" id="page-12"><span class="grey">VTS/WF STD. 6 ViaThinkSoft MHA2 4 September 2024</span>
<h3><a class="selflink" id="section-6.2" href="#section-6.2">6.2</a> Informative References</h3>
None
Acknowledgements
I would like to thank Melanie Wehowski for her long time support in
OIDplus and WEID projects.
This document was written in Nroff Internet Draft Editor by 3xA
Security.
<a href="https://aaa-sec.com/nroffedit/">https://aaa-sec.com/nroffedit/</a>
<a href="https://misc.daniel-marschall.de/patches/nroffedit/">https://misc.daniel-marschall.de/patches/nroffedit/</a> ("year 2020"
patch)
Authors' Addresses
Daniel Marschall
Postfach 11 53
69243 Bammental
Germany
Email: daniel-marschall@viathinksoft.de
URI: <a href="https://www.viathinksoft.com/">https://www.viathinksoft.com/</a>
Marschall [Page 12]
</pre></div></div></div>
</body>
</html>