-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsha1_disturbance.go
154 lines (146 loc) · 4.23 KB
/
sha1_disturbance.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
package detectcoll
import "fmt"
type Sha1_dv struct {
Type int
K int
B uint
message_block sha1_mb
}
var SHA1_STANDARD_DV []Sha1_dv = []Sha1_dv{
Sha1_dv{Type: 1, K: 46, B: 0},
Sha1_dv{Type: 1, K: 47, B: 0},
Sha1_dv{Type: 1, K: 48, B: 0},
Sha1_dv{Type: 1, K: 49, B: 0},
Sha1_dv{Type: 1, K: 50, B: 0},
Sha1_dv{Type: 1, K: 51, B: 0},
Sha1_dv{Type: 1, K: 48, B: 2},
Sha1_dv{Type: 1, K: 49, B: 2},
Sha1_dv{Type: 1, K: 50, B: 2},
Sha1_dv{Type: 2, K: 45, B: 0},
Sha1_dv{Type: 2, K: 46, B: 0},
Sha1_dv{Type: 2, K: 47, B: 0},
Sha1_dv{Type: 2, K: 48, B: 0},
Sha1_dv{Type: 2, K: 49, B: 0},
Sha1_dv{Type: 2, K: 50, B: 0},
Sha1_dv{Type: 2, K: 51, B: 0},
Sha1_dv{Type: 2, K: 52, B: 0},
Sha1_dv{Type: 2, K: 53, B: 0},
Sha1_dv{Type: 2, K: 54, B: 0},
Sha1_dv{Type: 2, K: 56, B: 0},
Sha1_dv{Type: 2, K: 57, B: 0},
Sha1_dv{Type: 2, K: 58, B: 0},
}
var SHA1_COMPLETE_DV []Sha1_dv = []Sha1_dv{
Sha1_dv{Type: 1, K: 42, B: 0},
Sha1_dv{Type: 1, K: 43, B: 0},
Sha1_dv{Type: 1, K: 44, B: 0},
Sha1_dv{Type: 1, K: 45, B: 0},
Sha1_dv{Type: 1, K: 46, B: 0},
Sha1_dv{Type: 1, K: 47, B: 0},
Sha1_dv{Type: 1, K: 48, B: 0},
Sha1_dv{Type: 1, K: 49, B: 0},
Sha1_dv{Type: 1, K: 50, B: 0},
Sha1_dv{Type: 1, K: 51, B: 0},
Sha1_dv{Type: 1, K: 52, B: 0},
Sha1_dv{Type: 1, K: 53, B: 0},
Sha1_dv{Type: 1, K: 54, B: 0},
Sha1_dv{Type: 1, K: 55, B: 0},
Sha1_dv{Type: 1, K: 56, B: 0},
Sha1_dv{Type: 1, K: 42, B: 2},
Sha1_dv{Type: 1, K: 43, B: 2},
Sha1_dv{Type: 1, K: 44, B: 2},
Sha1_dv{Type: 1, K: 45, B: 2},
Sha1_dv{Type: 1, K: 46, B: 2},
Sha1_dv{Type: 1, K: 47, B: 2},
Sha1_dv{Type: 1, K: 48, B: 2},
Sha1_dv{Type: 1, K: 49, B: 2},
Sha1_dv{Type: 1, K: 50, B: 2},
Sha1_dv{Type: 1, K: 51, B: 2},
Sha1_dv{Type: 1, K: 52, B: 2},
Sha1_dv{Type: 1, K: 53, B: 2},
Sha1_dv{Type: 1, K: 54, B: 2},
Sha1_dv{Type: 1, K: 55, B: 2},
Sha1_dv{Type: 1, K: 56, B: 2},
Sha1_dv{Type: 2, K: 44, B: 0},
Sha1_dv{Type: 2, K: 45, B: 0},
Sha1_dv{Type: 2, K: 46, B: 0},
Sha1_dv{Type: 2, K: 47, B: 0},
Sha1_dv{Type: 2, K: 48, B: 0},
Sha1_dv{Type: 2, K: 49, B: 0},
Sha1_dv{Type: 2, K: 50, B: 0},
Sha1_dv{Type: 2, K: 51, B: 0},
Sha1_dv{Type: 2, K: 52, B: 0},
Sha1_dv{Type: 2, K: 53, B: 0},
Sha1_dv{Type: 2, K: 54, B: 0},
Sha1_dv{Type: 2, K: 55, B: 0},
Sha1_dv{Type: 2, K: 56, B: 0},
Sha1_dv{Type: 2, K: 45, B: 2},
Sha1_dv{Type: 2, K: 46, B: 2},
Sha1_dv{Type: 2, K: 47, B: 2},
Sha1_dv{Type: 2, K: 48, B: 2},
Sha1_dv{Type: 2, K: 49, B: 2},
Sha1_dv{Type: 2, K: 50, B: 2},
Sha1_dv{Type: 2, K: 51, B: 2},
Sha1_dv{Type: 2, K: 52, B: 2},
Sha1_dv{Type: 2, K: 53, B: 2},
Sha1_dv{Type: 2, K: 54, B: 2},
Sha1_dv{Type: 2, K: 55, B: 2},
Sha1_dv{Type: 2, K: 56, B: 2},
}
func (dv *Sha1_dv) String() string {
var t string
switch dv.Type {
case 1:
t = "I"
case 2:
t = "II"
}
return fmt.Sprintf("%s(%d, %d)", t, dv.K, dv.B)
}
func (dv *Sha1_dv) create_messageblock() {
switch dv.Type {
case 1:
dv.message_block[dv.K+0] = (1 << 4)
dv.message_block[dv.K+1] = (1 << 29) | (1 << 31)
dv.message_block[dv.K+3] = (1 << 29)
dv.message_block[dv.K+4] = (1 << 29)
dv.message_block[dv.K+15] = (1 << 0)
case 2:
dv.message_block[dv.K+0] = (1 << 29)
dv.message_block[dv.K+1] = (1 << 31)
dv.message_block[dv.K+2] = (1 << 4)
dv.message_block[dv.K+4] = (1 << 4) | (1 << 29)
dv.message_block[dv.K+5] = (1 << 29) | (1 << 31)
dv.message_block[dv.K+7] = (1 << 29)
dv.message_block[dv.K+8] = (1 << 29)
dv.message_block[dv.K+15] = (1 << 0)
default:
panic("Not a supported disturbance-vector type")
}
if dv.B != 0 {
for i := 0; i < 16; i++ {
dv.message_block[dv.K+i] = rotl32(dv.message_block[dv.K+i], dv.B)
}
}
for i := dv.K + 16; i < 80; i++ {
dv.message_block[i] = rotl32(dv.message_block[i-3]^dv.message_block[i-8]^dv.message_block[i-14]^dv.message_block[i-16], 1)
}
for i := dv.K - 1; i >= 0; i-- {
dv.message_block[i] = rotr32(dv.message_block[i+16], 1) ^ dv.message_block[i+13] ^ dv.message_block[i+8] ^ dv.message_block[i+2]
}
}
func init() {
for i, _ := range SHA1_STANDARD_DV {
SHA1_STANDARD_DV[i].create_messageblock()
}
for i, _ := range SHA1_COMPLETE_DV {
SHA1_COMPLETE_DV[i].create_messageblock()
}
}
func (dv *Sha1_dv) disturb(mb *sha1_mb) sha1_mb {
var ret sha1_mb
for i := 0; i < 80; i++ {
ret[i] = dv.message_block[i] ^ mb[i]
}
return ret
}