Skip to content

Commit 08396bb

Browse files
thaJeztahgopherbot
authored andcommitted
internal/poly1305: drop Go 1.12 compatibility
Other packages already dropped compatibility with go1.12, so it should be safe to remove it for this package as well. Change-Id: Ieecc7cd06a0a4e69e8c1c09ef6fefe95d78ceb75 GitHub-Last-Rev: 1971e03 GitHub-Pull-Request: #239 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/448239 Reviewed-by: Joedian Reid <joedian@google.com> Auto-Submit: Filippo Valsorda <filippo@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
1 parent 9d2ee97 commit 08396bb

File tree

3 files changed

+23
-80
lines changed

3 files changed

+23
-80
lines changed

internal/poly1305/bits_compat.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

internal/poly1305/bits_go1.13.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

internal/poly1305/sum_generic.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
package poly1305
99

10-
import "encoding/binary"
10+
import (
11+
"encoding/binary"
12+
"math/bits"
13+
)
1114

1215
// Poly1305 [RFC 7539] is a relatively simple algorithm: the authentication tag
1316
// for a 64 bytes message is approximately
@@ -114,13 +117,13 @@ type uint128 struct {
114117
}
115118

116119
func mul64(a, b uint64) uint128 {
117-
hi, lo := bitsMul64(a, b)
120+
hi, lo := bits.Mul64(a, b)
118121
return uint128{lo, hi}
119122
}
120123

121124
func add128(a, b uint128) uint128 {
122-
lo, c := bitsAdd64(a.lo, b.lo, 0)
123-
hi, c := bitsAdd64(a.hi, b.hi, c)
125+
lo, c := bits.Add64(a.lo, b.lo, 0)
126+
hi, c := bits.Add64(a.hi, b.hi, c)
124127
if c != 0 {
125128
panic("poly1305: unexpected overflow")
126129
}
@@ -155,8 +158,8 @@ func updateGeneric(state *macState, msg []byte) {
155158
// hide leading zeroes. For full chunks, that's 1 << 128, so we can just
156159
// add 1 to the most significant (2¹²⁸) limb, h2.
157160
if len(msg) >= TagSize {
158-
h0, c = bitsAdd64(h0, binary.LittleEndian.Uint64(msg[0:8]), 0)
159-
h1, c = bitsAdd64(h1, binary.LittleEndian.Uint64(msg[8:16]), c)
161+
h0, c = bits.Add64(h0, binary.LittleEndian.Uint64(msg[0:8]), 0)
162+
h1, c = bits.Add64(h1, binary.LittleEndian.Uint64(msg[8:16]), c)
160163
h2 += c + 1
161164

162165
msg = msg[TagSize:]
@@ -165,8 +168,8 @@ func updateGeneric(state *macState, msg []byte) {
165168
copy(buf[:], msg)
166169
buf[len(msg)] = 1
167170

168-
h0, c = bitsAdd64(h0, binary.LittleEndian.Uint64(buf[0:8]), 0)
169-
h1, c = bitsAdd64(h1, binary.LittleEndian.Uint64(buf[8:16]), c)
171+
h0, c = bits.Add64(h0, binary.LittleEndian.Uint64(buf[0:8]), 0)
172+
h1, c = bits.Add64(h1, binary.LittleEndian.Uint64(buf[8:16]), c)
170173
h2 += c
171174

172175
msg = nil
@@ -219,9 +222,9 @@ func updateGeneric(state *macState, msg []byte) {
219222
m3 := h2r1
220223

221224
t0 := m0.lo
222-
t1, c := bitsAdd64(m1.lo, m0.hi, 0)
223-
t2, c := bitsAdd64(m2.lo, m1.hi, c)
224-
t3, _ := bitsAdd64(m3.lo, m2.hi, c)
225+
t1, c := bits.Add64(m1.lo, m0.hi, 0)
226+
t2, c := bits.Add64(m2.lo, m1.hi, c)
227+
t3, _ := bits.Add64(m3.lo, m2.hi, c)
225228

226229
// Now we have the result as 4 64-bit limbs, and we need to reduce it
227230
// modulo 2¹³⁰ - 5. The special shape of this Crandall prime lets us do
@@ -243,14 +246,14 @@ func updateGeneric(state *macState, msg []byte) {
243246

244247
// To add c * 5 to h, we first add cc = c * 4, and then add (cc >> 2) = c.
245248

246-
h0, c = bitsAdd64(h0, cc.lo, 0)
247-
h1, c = bitsAdd64(h1, cc.hi, c)
249+
h0, c = bits.Add64(h0, cc.lo, 0)
250+
h1, c = bits.Add64(h1, cc.hi, c)
248251
h2 += c
249252

250253
cc = shiftRightBy2(cc)
251254

252-
h0, c = bitsAdd64(h0, cc.lo, 0)
253-
h1, c = bitsAdd64(h1, cc.hi, c)
255+
h0, c = bits.Add64(h0, cc.lo, 0)
256+
h1, c = bits.Add64(h1, cc.hi, c)
254257
h2 += c
255258

256259
// h2 is at most 3 + 1 + 1 = 5, making the whole of h at most
@@ -287,9 +290,9 @@ func finalize(out *[TagSize]byte, h *[3]uint64, s *[2]uint64) {
287290
// in constant time, we compute t = h - (2¹³⁰ - 5), and select h as the
288291
// result if the subtraction underflows, and t otherwise.
289292

290-
hMinusP0, b := bitsSub64(h0, p0, 0)
291-
hMinusP1, b := bitsSub64(h1, p1, b)
292-
_, b = bitsSub64(h2, p2, b)
293+
hMinusP0, b := bits.Sub64(h0, p0, 0)
294+
hMinusP1, b := bits.Sub64(h1, p1, b)
295+
_, b = bits.Sub64(h2, p2, b)
293296

294297
// h = h if h < p else h - p
295298
h0 = select64(b, h0, hMinusP0)
@@ -301,8 +304,8 @@ func finalize(out *[TagSize]byte, h *[3]uint64, s *[2]uint64) {
301304
//
302305
// by just doing a wide addition with the 128 low bits of h and discarding
303306
// the overflow.
304-
h0, c := bitsAdd64(h0, s[0], 0)
305-
h1, _ = bitsAdd64(h1, s[1], c)
307+
h0, c := bits.Add64(h0, s[0], 0)
308+
h1, _ = bits.Add64(h1, s[1], c)
306309

307310
binary.LittleEndian.PutUint64(out[0:8], h0)
308311
binary.LittleEndian.PutUint64(out[8:16], h1)

0 commit comments

Comments
 (0)