Skip to content

Commit a947912

Browse files
rscgopherbot
authored andcommitted
internal/byteorder: use canonical Go casing in names
If Be and Le stand for big-endian and little-endian, then they should be BE and LE. Change-Id: I723e3962b8918da84791783d3c547638f1c9e8a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/627376 Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Russ Cox <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 2e07ff3 commit a947912

38 files changed

+260
-260
lines changed

src/cmd/compile/internal/inline/inl.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,12 @@ opSwitch:
537537
// budgeting system does not see that. See issue 42958.
538538
if base.Ctxt.Arch.CanMergeLoads && name.Sym().Pkg.Path == "internal/byteorder" {
539539
switch name.Sym().Name {
540-
case "LeUint64", "LeUint32", "LeUint16",
541-
"BeUint64", "BeUint32", "BeUint16",
542-
"LePutUint64", "LePutUint32", "LePutUint16",
543-
"BePutUint64", "BePutUint32", "BePutUint16",
544-
"LeAppendUint64", "LeAppendUint32", "LeAppendUint16",
545-
"BeAppendUint64", "BeAppendUint32", "BeAppendUint16":
540+
case "LEUint64", "LEUint32", "LEUint16",
541+
"BEUint64", "BEUint32", "BEUint16",
542+
"LEPutUint64", "LEPutUint32", "LEPutUint16",
543+
"BEPutUint64", "BEPutUint32", "BEPutUint16",
544+
"LEAppendUint64", "LEAppendUint32", "LEAppendUint16",
545+
"BEAppendUint64", "BEAppendUint32", "BEAppendUint16":
546546
cheap = true
547547
}
548548
}

src/crypto/cipher/gcm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func deriveCounter(H, counter *[gcmBlockSize]byte, nonce []byte) {
312312
counter[gcmBlockSize-1] = 1
313313
} else {
314314
lenBlock := make([]byte, 16)
315-
byteorder.BePutUint64(lenBlock[8:], uint64(len(nonce))*8)
315+
byteorder.BEPutUint64(lenBlock[8:], uint64(len(nonce))*8)
316316
J := gcm.GHASH(H, nonce, lenBlock)
317317
copy(counter[:], J)
318318
}
@@ -337,13 +337,13 @@ func gcmCounterCryptGeneric(b Block, out, src []byte, counter *[gcmBlockSize]byt
337337

338338
func gcmInc32(counterBlock *[gcmBlockSize]byte) {
339339
ctr := counterBlock[len(counterBlock)-4:]
340-
byteorder.BePutUint32(ctr, byteorder.BeUint32(ctr)+1)
340+
byteorder.BEPutUint32(ctr, byteorder.BEUint32(ctr)+1)
341341
}
342342

343343
func gcmAuth(out []byte, H, tagMask *[gcmBlockSize]byte, ciphertext, additionalData []byte) {
344344
lenBlock := make([]byte, 16)
345-
byteorder.BePutUint64(lenBlock[:8], uint64(len(additionalData))*8)
346-
byteorder.BePutUint64(lenBlock[8:], uint64(len(ciphertext))*8)
345+
byteorder.BEPutUint64(lenBlock[:8], uint64(len(additionalData))*8)
346+
byteorder.BEPutUint64(lenBlock[8:], uint64(len(ciphertext))*8)
347347
S := gcm.GHASH(H, additionalData, ciphertext, lenBlock)
348348
subtle.XORBytes(out, S, tagMask[:])
349349
}

src/crypto/des/block.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func cryptBlock(subkeys []uint64, dst, src []byte, decrypt bool) {
13-
b := byteorder.BeUint64(src)
13+
b := byteorder.BEUint64(src)
1414
b = permuteInitialBlock(b)
1515
left, right := uint32(b>>32), uint32(b)
1616

@@ -32,7 +32,7 @@ func cryptBlock(subkeys []uint64, dst, src []byte, decrypt bool) {
3232

3333
// switch left & right and perform final permutation
3434
preOutput := (uint64(right) << 32) | uint64(left)
35-
byteorder.BePutUint64(dst, permuteFinalBlock(preOutput))
35+
byteorder.BEPutUint64(dst, permuteFinalBlock(preOutput))
3636
}
3737

3838
// DES Feistel function. feistelBox must be initialized via
@@ -218,7 +218,7 @@ func (c *desCipher) generateSubkeys(keyBytes []byte) {
218218
feistelBoxOnce.Do(initFeistelBox)
219219

220220
// apply PC1 permutation to key
221-
key := byteorder.BeUint64(keyBytes)
221+
key := byteorder.BEUint64(keyBytes)
222222
permutedKey := permuteBlock(key, permutedChoice1[:])
223223

224224
// rotate halves of permuted key according to the rotation schedule

src/crypto/des/cipher.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (c *tripleDESCipher) Encrypt(dst, src []byte) {
9595
panic("crypto/des: invalid buffer overlap")
9696
}
9797

98-
b := byteorder.BeUint64(src)
98+
b := byteorder.BEUint64(src)
9999
b = permuteInitialBlock(b)
100100
left, right := uint32(b>>32), uint32(b)
101101

@@ -116,7 +116,7 @@ func (c *tripleDESCipher) Encrypt(dst, src []byte) {
116116
right = (right << 31) | (right >> 1)
117117

118118
preOutput := (uint64(right) << 32) | uint64(left)
119-
byteorder.BePutUint64(dst, permuteFinalBlock(preOutput))
119+
byteorder.BEPutUint64(dst, permuteFinalBlock(preOutput))
120120
}
121121

122122
func (c *tripleDESCipher) Decrypt(dst, src []byte) {
@@ -130,7 +130,7 @@ func (c *tripleDESCipher) Decrypt(dst, src []byte) {
130130
panic("crypto/des: invalid buffer overlap")
131131
}
132132

133-
b := byteorder.BeUint64(src)
133+
b := byteorder.BEUint64(src)
134134
b = permuteInitialBlock(b)
135135
left, right := uint32(b>>32), uint32(b)
136136

@@ -151,5 +151,5 @@ func (c *tripleDESCipher) Decrypt(dst, src []byte) {
151151
right = (right << 31) | (right >> 1)
152152

153153
preOutput := (uint64(right) << 32) | uint64(left)
154-
byteorder.BePutUint64(dst, permuteFinalBlock(preOutput))
154+
byteorder.BEPutUint64(dst, permuteFinalBlock(preOutput))
155155
}

src/crypto/internal/boring/sha.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ func (h *sha1Hash) MarshalBinary() ([]byte, error) {
166166
func (h *sha1Hash) AppendBinary(b []byte) ([]byte, error) {
167167
d := (*sha1Ctx)(unsafe.Pointer(&h.ctx))
168168
b = append(b, sha1Magic...)
169-
b = byteorder.BeAppendUint32(b, d.h[0])
170-
b = byteorder.BeAppendUint32(b, d.h[1])
171-
b = byteorder.BeAppendUint32(b, d.h[2])
172-
b = byteorder.BeAppendUint32(b, d.h[3])
173-
b = byteorder.BeAppendUint32(b, d.h[4])
169+
b = byteorder.BEAppendUint32(b, d.h[0])
170+
b = byteorder.BEAppendUint32(b, d.h[1])
171+
b = byteorder.BEAppendUint32(b, d.h[2])
172+
b = byteorder.BEAppendUint32(b, d.h[3])
173+
b = byteorder.BEAppendUint32(b, d.h[4])
174174
b = append(b, d.x[:d.nx]...)
175175
b = append(b, make([]byte, len(d.x)-int(d.nx))...)
176-
b = byteorder.BeAppendUint64(b, uint64(d.nl)>>3|uint64(d.nh)<<29)
176+
b = byteorder.BEAppendUint64(b, uint64(d.nl)>>3|uint64(d.nh)<<29)
177177
return b, nil
178178
}
179179

@@ -295,17 +295,17 @@ func (h *sha224Hash) MarshalBinary() ([]byte, error) {
295295
func (h *sha224Hash) AppendBinary(b []byte) ([]byte, error) {
296296
d := (*sha256Ctx)(unsafe.Pointer(&h.ctx))
297297
b = append(b, magic224...)
298-
b = byteorder.BeAppendUint32(b, d.h[0])
299-
b = byteorder.BeAppendUint32(b, d.h[1])
300-
b = byteorder.BeAppendUint32(b, d.h[2])
301-
b = byteorder.BeAppendUint32(b, d.h[3])
302-
b = byteorder.BeAppendUint32(b, d.h[4])
303-
b = byteorder.BeAppendUint32(b, d.h[5])
304-
b = byteorder.BeAppendUint32(b, d.h[6])
305-
b = byteorder.BeAppendUint32(b, d.h[7])
298+
b = byteorder.BEAppendUint32(b, d.h[0])
299+
b = byteorder.BEAppendUint32(b, d.h[1])
300+
b = byteorder.BEAppendUint32(b, d.h[2])
301+
b = byteorder.BEAppendUint32(b, d.h[3])
302+
b = byteorder.BEAppendUint32(b, d.h[4])
303+
b = byteorder.BEAppendUint32(b, d.h[5])
304+
b = byteorder.BEAppendUint32(b, d.h[6])
305+
b = byteorder.BEAppendUint32(b, d.h[7])
306306
b = append(b, d.x[:d.nx]...)
307307
b = append(b, make([]byte, len(d.x)-int(d.nx))...)
308-
b = byteorder.BeAppendUint64(b, uint64(d.nl)>>3|uint64(d.nh)<<29)
308+
b = byteorder.BEAppendUint64(b, uint64(d.nl)>>3|uint64(d.nh)<<29)
309309
return b, nil
310310
}
311311

@@ -316,17 +316,17 @@ func (h *sha256Hash) MarshalBinary() ([]byte, error) {
316316
func (h *sha256Hash) AppendBinary(b []byte) ([]byte, error) {
317317
d := (*sha256Ctx)(unsafe.Pointer(&h.ctx))
318318
b = append(b, magic256...)
319-
b = byteorder.BeAppendUint32(b, d.h[0])
320-
b = byteorder.BeAppendUint32(b, d.h[1])
321-
b = byteorder.BeAppendUint32(b, d.h[2])
322-
b = byteorder.BeAppendUint32(b, d.h[3])
323-
b = byteorder.BeAppendUint32(b, d.h[4])
324-
b = byteorder.BeAppendUint32(b, d.h[5])
325-
b = byteorder.BeAppendUint32(b, d.h[6])
326-
b = byteorder.BeAppendUint32(b, d.h[7])
319+
b = byteorder.BEAppendUint32(b, d.h[0])
320+
b = byteorder.BEAppendUint32(b, d.h[1])
321+
b = byteorder.BEAppendUint32(b, d.h[2])
322+
b = byteorder.BEAppendUint32(b, d.h[3])
323+
b = byteorder.BEAppendUint32(b, d.h[4])
324+
b = byteorder.BEAppendUint32(b, d.h[5])
325+
b = byteorder.BEAppendUint32(b, d.h[6])
326+
b = byteorder.BEAppendUint32(b, d.h[7])
327327
b = append(b, d.x[:d.nx]...)
328328
b = append(b, make([]byte, len(d.x)-int(d.nx))...)
329-
b = byteorder.BeAppendUint64(b, uint64(d.nl)>>3|uint64(d.nh)<<29)
329+
b = byteorder.BEAppendUint64(b, uint64(d.nl)>>3|uint64(d.nh)<<29)
330330
return b, nil
331331
}
332332

@@ -478,17 +478,17 @@ func (h *sha384Hash) MarshalBinary() ([]byte, error) {
478478
func (h *sha384Hash) AppendBinary(b []byte) ([]byte, error) {
479479
d := (*sha512Ctx)(unsafe.Pointer(&h.ctx))
480480
b = append(b, magic384...)
481-
b = byteorder.BeAppendUint64(b, d.h[0])
482-
b = byteorder.BeAppendUint64(b, d.h[1])
483-
b = byteorder.BeAppendUint64(b, d.h[2])
484-
b = byteorder.BeAppendUint64(b, d.h[3])
485-
b = byteorder.BeAppendUint64(b, d.h[4])
486-
b = byteorder.BeAppendUint64(b, d.h[5])
487-
b = byteorder.BeAppendUint64(b, d.h[6])
488-
b = byteorder.BeAppendUint64(b, d.h[7])
481+
b = byteorder.BEAppendUint64(b, d.h[0])
482+
b = byteorder.BEAppendUint64(b, d.h[1])
483+
b = byteorder.BEAppendUint64(b, d.h[2])
484+
b = byteorder.BEAppendUint64(b, d.h[3])
485+
b = byteorder.BEAppendUint64(b, d.h[4])
486+
b = byteorder.BEAppendUint64(b, d.h[5])
487+
b = byteorder.BEAppendUint64(b, d.h[6])
488+
b = byteorder.BEAppendUint64(b, d.h[7])
489489
b = append(b, d.x[:d.nx]...)
490490
b = append(b, make([]byte, len(d.x)-int(d.nx))...)
491-
b = byteorder.BeAppendUint64(b, d.nl>>3|d.nh<<61)
491+
b = byteorder.BEAppendUint64(b, d.nl>>3|d.nh<<61)
492492
return b, nil
493493
}
494494

@@ -499,17 +499,17 @@ func (h *sha512Hash) MarshalBinary() ([]byte, error) {
499499
func (h *sha512Hash) AppendBinary(b []byte) ([]byte, error) {
500500
d := (*sha512Ctx)(unsafe.Pointer(&h.ctx))
501501
b = append(b, magic512...)
502-
b = byteorder.BeAppendUint64(b, d.h[0])
503-
b = byteorder.BeAppendUint64(b, d.h[1])
504-
b = byteorder.BeAppendUint64(b, d.h[2])
505-
b = byteorder.BeAppendUint64(b, d.h[3])
506-
b = byteorder.BeAppendUint64(b, d.h[4])
507-
b = byteorder.BeAppendUint64(b, d.h[5])
508-
b = byteorder.BeAppendUint64(b, d.h[6])
509-
b = byteorder.BeAppendUint64(b, d.h[7])
502+
b = byteorder.BEAppendUint64(b, d.h[0])
503+
b = byteorder.BEAppendUint64(b, d.h[1])
504+
b = byteorder.BEAppendUint64(b, d.h[2])
505+
b = byteorder.BEAppendUint64(b, d.h[3])
506+
b = byteorder.BEAppendUint64(b, d.h[4])
507+
b = byteorder.BEAppendUint64(b, d.h[5])
508+
b = byteorder.BEAppendUint64(b, d.h[6])
509+
b = byteorder.BEAppendUint64(b, d.h[7])
510510
b = append(b, d.x[:d.nx]...)
511511
b = append(b, make([]byte, len(d.x)-int(d.nx))...)
512-
b = byteorder.BeAppendUint64(b, d.nl>>3|d.nh<<61)
512+
b = byteorder.BEAppendUint64(b, d.nl>>3|d.nh<<61)
513513
return b, nil
514514
}
515515

@@ -570,9 +570,9 @@ func (h *sha512Hash) UnmarshalBinary(b []byte) error {
570570
}
571571

572572
func consumeUint64(b []byte) ([]byte, uint64) {
573-
return b[8:], byteorder.BeUint64(b)
573+
return b[8:], byteorder.BEUint64(b)
574574
}
575575

576576
func consumeUint32(b []byte) ([]byte, uint32) {
577-
return b[4:], byteorder.BeUint32(b)
577+
return b[4:], byteorder.BEUint32(b)
578578
}

src/crypto/internal/fips140deps/byteorder/byteorder.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,45 @@ import (
99
)
1010

1111
func LEUint16(b []byte) uint16 {
12-
return byteorder.LeUint16(b)
12+
return byteorder.LEUint16(b)
1313
}
1414

1515
func BEUint32(b []byte) uint32 {
16-
return byteorder.BeUint32(b)
16+
return byteorder.BEUint32(b)
1717
}
1818

1919
func BEUint64(b []byte) uint64 {
20-
return byteorder.BeUint64(b)
20+
return byteorder.BEUint64(b)
2121
}
2222

2323
func LEUint64(b []byte) uint64 {
24-
return byteorder.LeUint64(b)
24+
return byteorder.LEUint64(b)
2525
}
2626

2727
func BEPutUint16(b []byte, v uint16) {
28-
byteorder.BePutUint16(b, v)
28+
byteorder.BEPutUint16(b, v)
2929
}
3030

3131
func BEPutUint32(b []byte, v uint32) {
32-
byteorder.BePutUint32(b, v)
32+
byteorder.BEPutUint32(b, v)
3333
}
3434

3535
func BEPutUint64(b []byte, v uint64) {
36-
byteorder.BePutUint64(b, v)
36+
byteorder.BEPutUint64(b, v)
3737
}
3838

3939
func LEPutUint64(b []byte, v uint64) {
40-
byteorder.LePutUint64(b, v)
40+
byteorder.LEPutUint64(b, v)
4141
}
4242

4343
func BEAppendUint16(b []byte, v uint16) []byte {
44-
return byteorder.BeAppendUint16(b, v)
44+
return byteorder.BEAppendUint16(b, v)
4545
}
4646

4747
func BEAppendUint32(b []byte, v uint32) []byte {
48-
return byteorder.BeAppendUint32(b, v)
48+
return byteorder.BEAppendUint32(b, v)
4949
}
5050

5151
func BEAppendUint64(b []byte, v uint64) []byte {
52-
return byteorder.BeAppendUint64(b, v)
52+
return byteorder.BEAppendUint64(b, v)
5353
}

src/crypto/internal/hpke/hpke.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (kdf *hkdfKDF) LabeledExtract(sid []byte, salt []byte, label string, inputK
3737

3838
func (kdf *hkdfKDF) LabeledExpand(suiteID []byte, randomKey []byte, label string, info []byte, length uint16) []byte {
3939
labeledInfo := make([]byte, 0, 2+7+len(suiteID)+len(label)+len(info))
40-
labeledInfo = byteorder.BeAppendUint16(labeledInfo, length)
40+
labeledInfo = byteorder.BEAppendUint16(labeledInfo, length)
4141
labeledInfo = append(labeledInfo, []byte("HPKE-v1")...)
4242
labeledInfo = append(labeledInfo, suiteID...)
4343
labeledInfo = append(labeledInfo, label...)
@@ -75,7 +75,7 @@ func newDHKem(kemID uint16) (*dhKEM, error) {
7575
return &dhKEM{
7676
dh: suite.curve,
7777
kdf: hkdfKDF{suite.hash},
78-
suiteID: byteorder.BeAppendUint16([]byte("KEM"), kemID),
78+
suiteID: byteorder.BEAppendUint16([]byte("KEM"), kemID),
7979
nSecret: suite.nSecret,
8080
}, nil
8181
}
@@ -290,9 +290,9 @@ func (r *Receipient) Open(aad, ciphertext []byte) ([]byte, error) {
290290
func suiteID(kemID, kdfID, aeadID uint16) []byte {
291291
suiteID := make([]byte, 0, 4+2+2+2)
292292
suiteID = append(suiteID, []byte("HPKE")...)
293-
suiteID = byteorder.BeAppendUint16(suiteID, kemID)
294-
suiteID = byteorder.BeAppendUint16(suiteID, kdfID)
295-
suiteID = byteorder.BeAppendUint16(suiteID, aeadID)
293+
suiteID = byteorder.BEAppendUint16(suiteID, kemID)
294+
suiteID = byteorder.BEAppendUint16(suiteID, kdfID)
295+
suiteID = byteorder.BEAppendUint16(suiteID, aeadID)
296296
return suiteID
297297
}
298298

@@ -327,7 +327,7 @@ func (u uint128) bitLen() int {
327327

328328
func (u uint128) bytes() []byte {
329329
b := make([]byte, 16)
330-
byteorder.BePutUint64(b[0:], u.hi)
331-
byteorder.BePutUint64(b[8:], u.lo)
330+
byteorder.BEPutUint64(b[0:], u.hi)
331+
byteorder.BEPutUint64(b[8:], u.lo)
332332
return b
333333
}

src/crypto/internal/sysrand/rand_plan9.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func read(b []byte) error {
5050

5151
for len(b) >= 8 {
5252
if x, ok := state.Next(); ok {
53-
byteorder.BePutUint64(b, x)
53+
byteorder.BEPutUint64(b, x)
5454
b = b[8:]
5555
} else {
5656
state.Refill()
@@ -59,7 +59,7 @@ func read(b []byte) error {
5959
for len(b) > 0 {
6060
if x, ok := state.Next(); ok {
6161
var buf [8]byte
62-
byteorder.BePutUint64(buf[:], x)
62+
byteorder.BEPutUint64(buf[:], x)
6363
n := copy(b, buf[:])
6464
b = b[n:]
6565
} else {

src/crypto/md5/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func blockGeneric(dig *digest, p []byte) {
219219
220220
// load input block
221221
{{range $i := seq 16 -}}
222-
{{printf "x%x := byteorder.LeUint32(q[4*%#x:])" $i $i}}
222+
{{printf "x%x := byteorder.LEUint32(q[4*%#x:])" $i $i}}
223223
{{end}}
224224
225225
// round 1

0 commit comments

Comments
 (0)