| // Copyright 2023 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| const statelessResetTokenLen = 128 / 8 |
| // A statelessResetToken is a stateless reset token. |
| // https://www.rfc-editor.org/rfc/rfc9000#section-10.3 |
| type statelessResetToken [statelessResetTokenLen]byte |
| type statelessResetTokenGenerator struct { |
| // The hash.Hash interface is not concurrency safe, |
| // so we need a mutex here. |
| // There shouldn't be much contention on stateless reset token generation. |
| // If this proves to be a problem, we could avoid the mutex by using a separate |
| // generator per Conn, or by using a concurrency-safe generator. |
| func (g *statelessResetTokenGenerator) init(secret [32]byte) { |
| for _, b := range secret { |
| // Generate tokens using a random secret, but don't send stateless resets. |
| g.mac = hmac.New(sha256.New, secret[:]) |
| func (g *statelessResetTokenGenerator) tokenForConnID(cid []byte) (token statelessResetToken) { |
| copy(token[:], g.mac.Sum(nil)) |