Skip to content

Commit 7b8d0fd

Browse files
alts: Reduce ALTS counter overflow length from 5 to 4. (#6699)
1 parent e88e849 commit 7b8d0fd

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

credentials/alts/internal/conn/aes128gcm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
const (
2929
// Overflow length n in bytes, never encrypt more than 2^(n*8) frames (in
3030
// each direction).
31-
overflowLenAES128GCM = 5
31+
overflowLenAES128GCM = 4
3232
)
3333

3434
// aes128gcm is the struct that holds necessary information for ALTS record.

credentials/alts/internal/conn/aes128gcmrekey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
const (
2828
// Overflow length n in bytes, never encrypt more than 2^(n*8) frames (in
2929
// each direction).
30-
overflowLenAES128GCMRekey = 8
30+
overflowLenAES128GCMRekey = 4
3131
nonceLen = 12
3232
aeadKeyLen = 16
3333
kdfKeyLen = 32

credentials/alts/internal/conn/counter_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ func (s) TestCounterSides(t *testing.T) {
5252

5353
func (s) TestCounterInc(t *testing.T) {
5454
for _, test := range []struct {
55-
counter []byte
56-
want []byte
55+
counter []byte
56+
want []byte
57+
expectInvalid bool
5758
}{
5859
{
5960
counter: []byte{0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
@@ -72,19 +73,32 @@ func (s) TestCounterInc(t *testing.T) {
7273
want: []byte{0x43, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
7374
},
7475
{
75-
counter: []byte{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
76-
want: []byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
76+
counter: []byte{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
77+
want: []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
7778
},
7879
{
79-
counter: []byte{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80},
80-
want: []byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80},
80+
counter: []byte{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80},
81+
want: []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80},
82+
},
83+
{
84+
counter: []byte{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
85+
want: []byte{},
86+
expectInvalid: true,
87+
},
88+
{
89+
counter: []byte{0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80},
90+
want: []byte{},
91+
expectInvalid: true,
8192
},
8293
} {
8394
c := CounterFromValue(test.counter, overflowLenAES128GCM)
8495
c.Inc()
8596
value, _ := c.Value()
86-
if g, w := value, test.want; !bytes.Equal(g, w) || c.invalid {
87-
t.Errorf("counter(%v).Inc() =\n%v, want\n%v", test.counter, g, w)
97+
if got, want := c.invalid, test.expectInvalid; got != want {
98+
t.Errorf("counter.invalid=%t, want=%t", got, want)
99+
}
100+
if got, want := value, test.want; !bytes.Equal(got, want) {
101+
t.Errorf("counter(%v).Inc() =\n%v, want\n%v", test.counter, got, want)
88102
}
89103
}
90104
}

0 commit comments

Comments
 (0)