-
Notifications
You must be signed in to change notification settings - Fork 0
/
luffa512.go
1846 lines (1673 loc) · 36.9 KB
/
luffa512.go
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ISC License
//
// Copyright (c) 2017-2018 The DashX developers
// Copyright (c) 2016 The Dash developers
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package luffa512
import (
"fmt"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/utils"
)
// HashSize holds the size of a hash in bytes.
const HashSize = int(64)
// BlockSize holds the size of a block in bytes.
const BlockSize = uintptr(32)
type digest struct {
ptr uintptr
h [5][8]uint32
b [32]byte
}
// New returns a new digest compute a LUFFA512 hash.
func New() utils.Digest {
ref := &digest{}
ref.Reset()
return ref
}
// Reset resets the digest to its initial state.
func (ref *digest) Reset() {
ref.ptr = 0
for x := range kInit {
for y := range kInit[x] {
ref.h[x][y] = kInit[x][y]
}
}
}
// Sum appends the current hash to dst and returns the result
// as a slice. It does not change the underlying hash state.
func (ref *digest) Sum(dst []byte) []byte {
dgt := *ref
hsh := [64]byte{}
dgt.Close(hsh[:], 0, 0)
return append(dst, hsh[:]...)
}
// Write more data to the running hash, never returns an error.
func (ref *digest) Write(src []byte) (int, error) {
sln := uintptr(len(src))
fln := len(src)
buf := ref.b[:]
ptr := ref.ptr
if sln < (BlockSize - ptr) {
copy(ref.b[ptr:], src)
ref.ptr += sln
return int(sln), nil
}
var V00, V01, V02, V03, V04, V05, V06, V07 uint32
var V10, V11, V12, V13, V14, V15, V16, V17 uint32
var V20, V21, V22, V23, V24, V25, V26, V27 uint32
var V30, V31, V32, V33, V34, V35, V36, V37 uint32
var V40, V41, V42, V43, V44, V45, V46, V47 uint32
V00 = ref.h[0][0]
V01 = ref.h[0][1]
V02 = ref.h[0][2]
V03 = ref.h[0][3]
V04 = ref.h[0][4]
V05 = ref.h[0][5]
V06 = ref.h[0][6]
V07 = ref.h[0][7]
V10 = ref.h[1][0]
V11 = ref.h[1][1]
V12 = ref.h[1][2]
V13 = ref.h[1][3]
V14 = ref.h[1][4]
V15 = ref.h[1][5]
V16 = ref.h[1][6]
V17 = ref.h[1][7]
V20 = ref.h[2][0]
V21 = ref.h[2][1]
V22 = ref.h[2][2]
V23 = ref.h[2][3]
V24 = ref.h[2][4]
V25 = ref.h[2][5]
V26 = ref.h[2][6]
V27 = ref.h[2][7]
V30 = ref.h[3][0]
V31 = ref.h[3][1]
V32 = ref.h[3][2]
V33 = ref.h[3][3]
V34 = ref.h[3][4]
V35 = ref.h[3][5]
V36 = ref.h[3][6]
V37 = ref.h[3][7]
V40 = ref.h[4][0]
V41 = ref.h[4][1]
V42 = ref.h[4][2]
V43 = ref.h[4][3]
V44 = ref.h[4][4]
V45 = ref.h[4][5]
V46 = ref.h[4][6]
V47 = ref.h[4][7]
for sln > 0 {
cln := BlockSize - ptr
if cln > sln {
cln = sln
}
sln -= cln
copy(ref.b[ptr:], src[:cln])
src = src[cln:]
ptr += cln
if ptr == BlockSize {
{
var ts uint32
var M0, M1, M2, M3, M4, M5, M6, M7 uint32
var a0, a1, a2, a3, a4, a5, a6, a7 uint32
var b0, b1, b2, b3, b4, b5, b6, b7 uint32
M0 = decUInt32be(buf[0:])
M1 = decUInt32be(buf[4:])
M2 = decUInt32be(buf[8:])
M3 = decUInt32be(buf[12:])
M4 = decUInt32be(buf[16:])
M5 = decUInt32be(buf[20:])
M6 = decUInt32be(buf[24:])
M7 = decUInt32be(buf[28:])
a0 = V00 ^ V10
a1 = V01 ^ V11
a2 = V02 ^ V12
a3 = V03 ^ V13
a4 = V04 ^ V14
a5 = V05 ^ V15
a6 = V06 ^ V16
a7 = V07 ^ V17
b0 = V20 ^ V30
b1 = V21 ^ V31
b2 = V22 ^ V32
b3 = V23 ^ V33
b4 = V24 ^ V34
b5 = V25 ^ V35
b6 = V26 ^ V36
b7 = V27 ^ V37
a0 ^= b0
a1 ^= b1
a2 ^= b2
a3 ^= b3
a4 ^= b4
a5 ^= b5
a6 ^= b6
a7 ^= b7
a0 ^= V40
a1 ^= V41
a2 ^= V42
a3 ^= V43
a4 ^= V44
a5 ^= V45
a6 ^= V46
a7 ^= V47
ts = a7
a7 = a6
a6 = a5
a5 = a4
a4 = a3 ^ ts
a3 = a2 ^ ts
a2 = a1
a1 = a0 ^ ts
a0 = ts
V00 ^= a0
V01 ^= a1
V02 ^= a2
V03 ^= a3
V04 ^= a4
V05 ^= a5
V06 ^= a6
V07 ^= a7
V10 ^= a0
V11 ^= a1
V12 ^= a2
V13 ^= a3
V14 ^= a4
V15 ^= a5
V16 ^= a6
V17 ^= a7
V20 ^= a0
V21 ^= a1
V22 ^= a2
V23 ^= a3
V24 ^= a4
V25 ^= a5
V26 ^= a6
V27 ^= a7
V30 ^= a0
V31 ^= a1
V32 ^= a2
V33 ^= a3
V34 ^= a4
V35 ^= a5
V36 ^= a6
V37 ^= a7
V40 ^= a0
V41 ^= a1
V42 ^= a2
V43 ^= a3
V44 ^= a4
V45 ^= a5
V46 ^= a6
V47 ^= a7
ts = V07
b7 = V06
b6 = V05
b5 = V04
b4 = V03 ^ ts
b3 = V02 ^ ts
b2 = V01
b1 = V00 ^ ts
b0 = ts
b0 ^= V10
b1 ^= V11
b2 ^= V12
b3 ^= V13
b4 ^= V14
b5 ^= V15
b6 ^= V16
b7 ^= V17
ts = V17
V17 = V16
V16 = V15
V15 = V14
V14 = V13 ^ ts
V13 = V12 ^ ts
V12 = V11
V11 = V10 ^ ts
V10 = ts
V10 ^= V20
V11 ^= V21
V12 ^= V22
V13 ^= V23
V14 ^= V24
V15 ^= V25
V16 ^= V26
V17 ^= V27
ts = V27
V27 = V26
V26 = V25
V25 = V24
V24 = V23 ^ ts
V23 = V22 ^ ts
V22 = V21
V21 = V20 ^ ts
V20 = ts
V20 ^= V30
V21 ^= V31
V22 ^= V32
V23 ^= V33
V24 ^= V34
V25 ^= V35
V26 ^= V36
V27 ^= V37
ts = V37
V37 = V36
V36 = V35
V35 = V34
V34 = V33 ^ ts
V33 = V32 ^ ts
V32 = V31
V31 = V30 ^ ts
V30 = ts
V30 ^= V40
V31 ^= V41
V32 ^= V42
V33 ^= V43
V34 ^= V44
V35 ^= V45
V36 ^= V46
V37 ^= V47
ts = V47
V47 = V46
V46 = V45
V45 = V44
V44 = V43 ^ ts
V43 = V42 ^ ts
V42 = V41
V41 = V40 ^ ts
V40 = ts
V40 ^= V00
V41 ^= V01
V42 ^= V02
V43 ^= V03
V44 ^= V04
V45 ^= V05
V46 ^= V06
V47 ^= V07
ts = b7
V07 = b6
V06 = b5
V05 = b4
V04 = b3 ^ ts
V03 = b2 ^ ts
V02 = b1
V01 = b0 ^ ts
V00 = ts
V00 ^= V40
V01 ^= V41
V02 ^= V42
V03 ^= V43
V04 ^= V44
V05 ^= V45
V06 ^= V46
V07 ^= V47
ts = V47
V47 = V46
V46 = V45
V45 = V44
V44 = V43 ^ ts
V43 = V42 ^ ts
V42 = V41
V41 = V40 ^ ts
V40 = ts
V40 ^= V30
V41 ^= V31
V42 ^= V32
V43 ^= V33
V44 ^= V34
V45 ^= V35
V46 ^= V36
V47 ^= V37
ts = V37
V37 = V36
V36 = V35
V35 = V34
V34 = V33 ^ ts
V33 = V32 ^ ts
V32 = V31
V31 = V30 ^ ts
V30 = ts
V30 ^= V20
V31 ^= V21
V32 ^= V22
V33 ^= V23
V34 ^= V24
V35 ^= V25
V36 ^= V26
V37 ^= V27
ts = V27
V27 = V26
V26 = V25
V25 = V24
V24 = V23 ^ ts
V23 = V22 ^ ts
V22 = V21
V21 = V20 ^ ts
V20 = ts
V20 ^= V10
V21 ^= V11
V22 ^= V12
V23 ^= V13
V24 ^= V14
V25 ^= V15
V26 ^= V16
V27 ^= V17
ts = V17
V17 = V16
V16 = V15
V15 = V14
V14 = V13 ^ ts
V13 = V12 ^ ts
V12 = V11
V11 = V10 ^ ts
V10 = ts
V10 ^= b0
V11 ^= b1
V12 ^= b2
V13 ^= b3
V14 ^= b4
V15 ^= b5
V16 ^= b6
V17 ^= b7
V00 ^= M0
V01 ^= M1
V02 ^= M2
V03 ^= M3
V04 ^= M4
V05 ^= M5
V06 ^= M6
V07 ^= M7
ts = M7
M7 = M6
M6 = M5
M5 = M4
M4 = M3 ^ ts
M3 = M2 ^ ts
M2 = M1
M1 = M0 ^ ts
M0 = ts
V10 ^= M0
V11 ^= M1
V12 ^= M2
V13 ^= M3
V14 ^= M4
V15 ^= M5
V16 ^= M6
V17 ^= M7
ts = M7
M7 = M6
M6 = M5
M5 = M4
M4 = M3 ^ ts
M3 = M2 ^ ts
M2 = M1
M1 = M0 ^ ts
M0 = ts
V20 ^= M0
V21 ^= M1
V22 ^= M2
V23 ^= M3
V24 ^= M4
V25 ^= M5
V26 ^= M6
V27 ^= M7
ts = M7
M7 = M6
M6 = M5
M5 = M4
M4 = M3 ^ ts
M3 = M2 ^ ts
M2 = M1
M1 = M0 ^ ts
M0 = ts
V30 ^= M0
V31 ^= M1
V32 ^= M2
V33 ^= M3
V34 ^= M4
V35 ^= M5
V36 ^= M6
V37 ^= M7
ts = M7
M7 = M6
M6 = M5
M5 = M4
M4 = M3 ^ ts
M3 = M2 ^ ts
M2 = M1
M1 = M0 ^ ts
M0 = ts
V40 ^= M0
V41 ^= M1
V42 ^= M2
V43 ^= M3
V44 ^= M4
V45 ^= M5
V46 ^= M6
V47 ^= M7
}
{
var ul, uh, vl, vh, tws uint32
var W0, W1, W2, W3, W4, W5, W6, W7, tw uint64
V14 = (V14 << 1) | (V14 >> (32 - 1))
V15 = (V15 << 1) | (V15 >> (32 - 1))
V16 = (V16 << 1) | (V16 >> (32 - 1))
V17 = (V17 << 1) | (V17 >> (32 - 1))
V24 = (V24 << 2) | (V24 >> (32 - 2))
V25 = (V25 << 2) | (V25 >> (32 - 2))
V26 = (V26 << 2) | (V26 >> (32 - 2))
V27 = (V27 << 2) | (V27 >> (32 - 2))
V34 = (V34 << 3) | (V34 >> (32 - 3))
V35 = (V35 << 3) | (V35 >> (32 - 3))
V36 = (V36 << 3) | (V36 >> (32 - 3))
V37 = (V37 << 3) | (V37 >> (32 - 3))
V44 = (V44 << 4) | (V44 >> (32 - 4))
V45 = (V45 << 4) | (V45 >> (32 - 4))
V46 = (V46 << 4) | (V46 >> (32 - 4))
V47 = (V47 << 4) | (V47 >> (32 - 4))
W0 = uint64(V00) | (uint64(V10) << 32)
W1 = uint64(V01) | (uint64(V11) << 32)
W2 = uint64(V02) | (uint64(V12) << 32)
W3 = uint64(V03) | (uint64(V13) << 32)
W4 = uint64(V04) | (uint64(V14) << 32)
W5 = uint64(V05) | (uint64(V15) << 32)
W6 = uint64(V06) | (uint64(V16) << 32)
W7 = uint64(V07) | (uint64(V17) << 32)
for r := uintptr(0); r < 8; r++ {
tw = W0
W0 |= W1
W2 ^= W3
W1 = ^W1
W0 ^= W3
W3 &= tw
W1 ^= W3
W3 ^= W2
W2 &= W0
W0 = ^W0
W2 ^= W1
W1 |= W3
tw ^= W1
W3 ^= W2
W2 &= W1
W1 ^= W0
W0 = tw
tw = W5
W5 |= W6
W7 ^= W4
W6 = ^W6
W5 ^= W4
W4 &= tw
W6 ^= W4
W4 ^= W7
W7 &= W5
W5 = ^W5
W7 ^= W6
W6 |= W4
tw ^= W6
W4 ^= W7
W7 &= W6
W6 ^= W5
W5 = tw
W4 ^= W0
ul = uint32(W0)
uh = uint32(W0 >> 32)
vl = uint32(W4)
vh = uint32(W4 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W0 = uint64(ul) | (uint64(uh) << 32)
W4 = uint64(vl) | (uint64(vh) << 32)
W5 ^= W1
ul = uint32(W1)
uh = uint32(W1 >> 32)
vl = uint32(W5)
vh = uint32(W5 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W1 = uint64(ul) | (uint64(uh) << 32)
W5 = uint64(vl) | (uint64(vh) << 32)
W6 ^= W2
ul = uint32(W2)
uh = uint32(W2 >> 32)
vl = uint32(W6)
vh = uint32(W6 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W2 = uint64(ul) | (uint64(uh) << 32)
W6 = uint64(vl) | (uint64(vh) << 32)
W7 ^= W3
ul = uint32(W3)
uh = uint32(W3 >> 32)
vl = uint32(W7)
vh = uint32(W7 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W3 = uint64(ul) | (uint64(uh) << 32)
W7 = uint64(vl) | (uint64(vh) << 32)
W0 ^= kRCW010[r]
W4 ^= kRCW014[r]
}
V00 = uint32(W0)
V10 = uint32(W0 >> 32)
V01 = uint32(W1)
V11 = uint32(W1 >> 32)
V02 = uint32(W2)
V12 = uint32(W2 >> 32)
V03 = uint32(W3)
V13 = uint32(W3 >> 32)
V04 = uint32(W4)
V14 = uint32(W4 >> 32)
V05 = uint32(W5)
V15 = uint32(W5 >> 32)
V06 = uint32(W6)
V16 = uint32(W6 >> 32)
V07 = uint32(W7)
V17 = uint32(W7 >> 32)
W0 = uint64(V20) | (uint64(V30) << 32)
W1 = uint64(V21) | (uint64(V31) << 32)
W2 = uint64(V22) | (uint64(V32) << 32)
W3 = uint64(V23) | (uint64(V33) << 32)
W4 = uint64(V24) | (uint64(V34) << 32)
W5 = uint64(V25) | (uint64(V35) << 32)
W6 = uint64(V26) | (uint64(V36) << 32)
W7 = uint64(V27) | (uint64(V37) << 32)
for r := uintptr(0); r < 8; r++ {
tw = W0
W0 |= W1
W2 ^= W3
W1 = ^W1
W0 ^= W3
W3 &= tw
W1 ^= W3
W3 ^= W2
W2 &= W0
W0 = ^W0
W2 ^= W1
W1 |= W3
tw ^= W1
W3 ^= W2
W2 &= W1
W1 ^= W0
W0 = tw
tw = W5
W5 |= W6
W7 ^= W4
W6 = ^W6
W5 ^= W4
W4 &= tw
W6 ^= W4
W4 ^= W7
W7 &= W5
W5 = ^W5
W7 ^= W6
W6 |= W4
tw ^= W6
W4 ^= W7
W7 &= W6
W6 ^= W5
W5 = tw
W4 ^= W0
ul = uint32(W0)
uh = uint32(W0 >> 32)
vl = uint32(W4)
vh = uint32(W4 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W0 = uint64(ul) | (uint64(uh) << 32)
W4 = uint64(vl) | (uint64(vh) << 32)
W5 ^= W1
ul = uint32(W1)
uh = uint32(W1 >> 32)
vl = uint32(W5)
vh = uint32(W5 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W1 = uint64(ul) | (uint64(uh) << 32)
W5 = uint64(vl) | (uint64(vh) << 32)
W6 ^= W2
ul = uint32(W2)
uh = uint32(W2 >> 32)
vl = uint32(W6)
vh = uint32(W6 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W2 = uint64(ul) | (uint64(uh) << 32)
W6 = uint64(vl) | (uint64(vh) << 32)
W7 ^= W3
ul = uint32(W3)
uh = uint32(W3 >> 32)
vl = uint32(W7)
vh = uint32(W7 >> 32)
ul = ((ul << 2) | (ul >> (32 - 2))) ^ vl
vl = ((vl << 14) | (vl >> (32 - 14))) ^ ul
ul = ((ul << 10) | (ul >> (32 - 10))) ^ vl
vl = (vl << 1) | (vl >> (32 - 1))
uh = ((uh << 2) | (uh >> (32 - 2))) ^ vh
vh = ((vh << 14) | (vh >> (32 - 14))) ^ uh
uh = ((uh << 10) | (uh >> (32 - 10))) ^ vh
vh = (vh << 1) | (vh >> (32 - 1))
W3 = uint64(ul) | (uint64(uh) << 32)
W7 = uint64(vl) | (uint64(vh) << 32)
W0 ^= kRCW230[r]
W4 ^= kRCW234[r]
}
V20 = uint32(W0)
V30 = uint32(W0 >> 32)
V21 = uint32(W1)
V31 = uint32(W1 >> 32)
V22 = uint32(W2)
V32 = uint32(W2 >> 32)
V23 = uint32(W3)
V33 = uint32(W3 >> 32)
V24 = uint32(W4)
V34 = uint32(W4 >> 32)
V25 = uint32(W5)
V35 = uint32(W5 >> 32)
V26 = uint32(W6)
V36 = uint32(W6 >> 32)
V27 = uint32(W7)
V37 = uint32(W7 >> 32)
for r := uintptr(0); r < 8; r++ {
tws = V40
V40 |= V41
V42 ^= V43
V41 = ^V41
V40 ^= V43
V43 &= tws
V41 ^= V43
V43 ^= V42
V42 &= V40
V40 = ^V40
V42 ^= V41
V41 |= V43
tws ^= V41
V43 ^= V42
V42 &= V41
V41 ^= V40
V40 = tws
tws = V45
V45 |= V46
V47 ^= V44
V46 = ^V46
V45 ^= V44
V44 &= tws
V46 ^= V44
V44 ^= V47
V47 &= V45
V45 = ^V45
V47 ^= V46
V46 |= V44
tws ^= V46
V44 ^= V47
V47 &= V46
V46 ^= V45
V45 = tws
V44 ^= V40
V40 = ((V40 << 2) | (V40 >> (32 - 2))) ^ V44
V44 = ((V44 << 14) | (V44 >> (32 - 14))) ^ V40
V40 = ((V40 << 10) | (V40 >> (32 - 10))) ^ V44
V44 = (V44 << 1) | (V44 >> (32 - 1))
V45 ^= V41
V41 = ((V41 << 2) | (V41 >> (32 - 2))) ^ V45
V45 = ((V45 << 14) | (V45 >> (32 - 14))) ^ V41
V41 = ((V41 << 10) | (V41 >> (32 - 10))) ^ V45
V45 = (V45 << 1) | (V45 >> (32 - 1))
V46 ^= V42
V42 = ((V42 << 2) | (V42 >> (32 - 2))) ^ V46
V46 = ((V46 << 14) | (V46 >> (32 - 14))) ^ V42
V42 = ((V42 << 10) | (V42 >> (32 - 10))) ^ V46
V46 = (V46 << 1) | (V46 >> (32 - 1))
V47 ^= V43
V43 = ((V43 << 2) | (V43 >> (32 - 2))) ^ V47
V47 = ((V47 << 14) | (V47 >> (32 - 14))) ^ V43
V43 = ((V43 << 10) | (V43 >> (32 - 10))) ^ V47
V47 = (V47 << 1) | (V47 >> (32 - 1))
V40 ^= kRC40[r]
V44 ^= kRC44[r]
}
}
ptr = 0
}
}
ref.h[0][0] = V00
ref.h[0][1] = V01
ref.h[0][2] = V02
ref.h[0][3] = V03
ref.h[0][4] = V04
ref.h[0][5] = V05
ref.h[0][6] = V06
ref.h[0][7] = V07
ref.h[1][0] = V10
ref.h[1][1] = V11
ref.h[1][2] = V12
ref.h[1][3] = V13
ref.h[1][4] = V14
ref.h[1][5] = V15
ref.h[1][6] = V16
ref.h[1][7] = V17
ref.h[2][0] = V20
ref.h[2][1] = V21
ref.h[2][2] = V22
ref.h[2][3] = V23
ref.h[2][4] = V24
ref.h[2][5] = V25
ref.h[2][6] = V26
ref.h[2][7] = V27
ref.h[3][0] = V30
ref.h[3][1] = V31
ref.h[3][2] = V32
ref.h[3][3] = V33
ref.h[3][4] = V34
ref.h[3][5] = V35
ref.h[3][6] = V36
ref.h[3][7] = V37
ref.h[4][0] = V40
ref.h[4][1] = V41
ref.h[4][2] = V42
ref.h[4][3] = V43
ref.h[4][4] = V44
ref.h[4][5] = V45
ref.h[4][6] = V46
ref.h[4][7] = V47
ref.ptr = ptr
return fln, nil
}
// Close the digest by writing the last bits and storing the hash
// in dst. This prepares the digest for reuse by calling reset. A call
// to Close with a dst that is smaller then HashSize will return an error.
func (ref *digest) Close(dst []byte, bits uint8, bcnt uint8) error {
if ln := len(dst); HashSize > ln {
return fmt.Errorf("Luffa Close: dst min length: %d, got %d", HashSize, ln)
}
buf := ref.b[:]
ptr := ref.ptr + 1
{
off := uint8(0x80) >> bcnt
buf[ref.ptr] = uint8((bits & -off) | off)
}
memset(buf[ptr:], 0)
var V00, V01, V02, V03, V04, V05, V06, V07 uint32
var V10, V11, V12, V13, V14, V15, V16, V17 uint32
var V20, V21, V22, V23, V24, V25, V26, V27 uint32
var V30, V31, V32, V33, V34, V35, V36, V37 uint32
var V40, V41, V42, V43, V44, V45, V46, V47 uint32
V00 = ref.h[0][0]
V01 = ref.h[0][1]
V02 = ref.h[0][2]
V03 = ref.h[0][3]
V04 = ref.h[0][4]
V05 = ref.h[0][5]
V06 = ref.h[0][6]
V07 = ref.h[0][7]
V10 = ref.h[1][0]
V11 = ref.h[1][1]
V12 = ref.h[1][2]
V13 = ref.h[1][3]
V14 = ref.h[1][4]
V15 = ref.h[1][5]
V16 = ref.h[1][6]
V17 = ref.h[1][7]
V20 = ref.h[2][0]
V21 = ref.h[2][1]
V22 = ref.h[2][2]
V23 = ref.h[2][3]
V24 = ref.h[2][4]
V25 = ref.h[2][5]
V26 = ref.h[2][6]
V27 = ref.h[2][7]
V30 = ref.h[3][0]
V31 = ref.h[3][1]
V32 = ref.h[3][2]
V33 = ref.h[3][3]
V34 = ref.h[3][4]
V35 = ref.h[3][5]
V36 = ref.h[3][6]
V37 = ref.h[3][7]
V40 = ref.h[4][0]
V41 = ref.h[4][1]
V42 = ref.h[4][2]
V43 = ref.h[4][3]
V44 = ref.h[4][4]
V45 = ref.h[4][5]
V46 = ref.h[4][6]
V47 = ref.h[4][7]
for i := uintptr(0); i < 3; i++ {
{
var ts uint32
var M0, M1, M2, M3, M4, M5, M6, M7 uint32
var a0, a1, a2, a3, a4, a5, a6, a7 uint32
var b0, b1, b2, b3, b4, b5, b6, b7 uint32
M0 = decUInt32be(buf[0:])
M1 = decUInt32be(buf[4:])
M2 = decUInt32be(buf[8:])
M3 = decUInt32be(buf[12:])
M4 = decUInt32be(buf[16:])
M5 = decUInt32be(buf[20:])
M6 = decUInt32be(buf[24:])
M7 = decUInt32be(buf[28:])
a0 = V00 ^ V10