@@ -38,8 +38,9 @@ type state struct {
38
38
// [1] http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf
39
39
// "Draft FIPS 202: SHA-3 Standard: Permutation-Based Hash and
40
40
// Extendable-Output Functions (May 2014)"
41
- dsbyte byte
42
- storage [maxRate ]byte
41
+ dsbyte byte
42
+
43
+ storage storageBuf
43
44
44
45
// Specific to SHA-3 and SHAKE.
45
46
outputLen int // the default output size in bytes
@@ -60,15 +61,15 @@ func (d *state) Reset() {
60
61
d .a [i ] = 0
61
62
}
62
63
d .state = spongeAbsorbing
63
- d .buf = d .storage [:0 ]
64
+ d .buf = d .storage . asBytes () [:0 ]
64
65
}
65
66
66
67
func (d * state ) clone () * state {
67
68
ret := * d
68
69
if ret .state == spongeAbsorbing {
69
- ret .buf = ret .storage [:len (ret .buf )]
70
+ ret .buf = ret .storage . asBytes () [:len (ret .buf )]
70
71
} else {
71
- ret .buf = ret .storage [d .rate - cap (d .buf ) : d .rate ]
72
+ ret .buf = ret .storage . asBytes () [d .rate - cap (d .buf ) : d .rate ]
72
73
}
73
74
74
75
return & ret
@@ -82,13 +83,13 @@ func (d *state) permute() {
82
83
// If we're absorbing, we need to xor the input into the state
83
84
// before applying the permutation.
84
85
xorIn (d , d .buf )
85
- d .buf = d .storage [:0 ]
86
+ d .buf = d .storage . asBytes () [:0 ]
86
87
keccakF1600 (& d .a )
87
88
case spongeSqueezing :
88
89
// If we're squeezing, we need to apply the permutatin before
89
90
// copying more output.
90
91
keccakF1600 (& d .a )
91
- d .buf = d .storage [:d .rate ]
92
+ d .buf = d .storage . asBytes () [:d .rate ]
92
93
copyOut (d , d .buf )
93
94
}
94
95
}
@@ -97,15 +98,15 @@ func (d *state) permute() {
97
98
// the multi-bitrate 10..1 padding rule, and permutes the state.
98
99
func (d * state ) padAndPermute (dsbyte byte ) {
99
100
if d .buf == nil {
100
- d .buf = d .storage [:0 ]
101
+ d .buf = d .storage . asBytes () [:0 ]
101
102
}
102
103
// Pad with this instance's domain-separator bits. We know that there's
103
104
// at least one byte of space in d.buf because, if it were full,
104
105
// permute would have been called to empty it. dsbyte also contains the
105
106
// first one bit for the padding. See the comment in the state struct.
106
107
d .buf = append (d .buf , dsbyte )
107
108
zerosStart := len (d .buf )
108
- d .buf = d .storage [:d .rate ]
109
+ d .buf = d .storage . asBytes () [:d .rate ]
109
110
for i := zerosStart ; i < d .rate ; i ++ {
110
111
d .buf [i ] = 0
111
112
}
@@ -116,7 +117,7 @@ func (d *state) padAndPermute(dsbyte byte) {
116
117
// Apply the permutation
117
118
d .permute ()
118
119
d .state = spongeSqueezing
119
- d .buf = d .storage [:d .rate ]
120
+ d .buf = d .storage . asBytes () [:d .rate ]
120
121
copyOut (d , d .buf )
121
122
}
122
123
@@ -127,7 +128,7 @@ func (d *state) Write(p []byte) (written int, err error) {
127
128
panic ("sha3: write to sponge after read" )
128
129
}
129
130
if d .buf == nil {
130
- d .buf = d .storage [:0 ]
131
+ d .buf = d .storage . asBytes () [:0 ]
131
132
}
132
133
written = len (p )
133
134
0 commit comments