Source File
ciphersuite.go
Belonging Package
github.com/pion/dtls/v2/pkg/crypto/ciphersuite
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MIT// Package ciphersuite provides the crypto operations needed for a DTLS CipherSuitepackage ciphersuiteimport ()var (errNotEnoughRoomForNonce = &protocol.InternalError{Err: errors.New("buffer not long enough to contain nonce")} //nolint:goerr113errDecryptPacket = &protocol.TemporaryError{Err: errors.New("failed to decrypt packet")} //nolint:goerr113errInvalidMAC = &protocol.TemporaryError{Err: errors.New("invalid mac")} //nolint:goerr113errFailedToCast = &protocol.FatalError{Err: errors.New("failed to cast")} //nolint:goerr113)func generateAEADAdditionalData( *recordlayer.Header, int) []byte {var [13]byte// SequenceNumber MUST be set first// we only want uint48, clobbering an extra 2 (using uint64, Golang doesn't have uint48)binary.BigEndian.PutUint64([:], .SequenceNumber)binary.BigEndian.PutUint16([:], .Epoch)[8] = byte(.ContentType)[9] = .Version.Major[10] = .Version.Minorbinary.BigEndian.PutUint16([len()-2:], uint16())return [:]}// examinePadding returns, in constant time, the length of the padding to remove// from the end of payload. It also returns a byte which is equal to 255 if the// padding was valid and 0 otherwise. See RFC 2246, Section 6.2.3.2.//// https://github.com/golang/go/blob/039c2081d1178f90a8fa2f4e6958693129f8de33/src/crypto/tls/conn.go#L245func examinePadding( []byte) ( int, byte) {if len() < 1 {return 0, 0}:= [len()-1]:= uint(len()-1) - uint()// if len(payload) >= (paddingLen - 1) then the MSB of t is zero= byte(int32(^) >> 31)// The maximum possible padding length plus the actual length field:= 256// The length of the padded data is public, so we can use an if hereif > len() {= len()}for := 0; < ; ++ {:= uint() - uint()// if i <= paddingLen then the MSB of t is zero:= byte(int32(^) >> 31):= [len()-1-]&^= & ^ &}// We AND together the bits of good and replicate the result across// all the bits.&= << 4&= << 2&= << 1= uint8(int8() >> 7)= int() + 1return ,}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |