MCPcopy Create free account
hub / github.com/HyBuildNet/quic-relay / decryptInitialPacket

Function decryptInitialPacket

internal/proxy/parser.go:437–459  ·  view source on GitHub ↗

decryptInitialPacket removes header protection and decrypts the payload.

(packet, encrypted, key, iv, hp []byte)

Source from the content-addressed store, hash-verified

435
436// decryptInitialPacket removes header protection and decrypts the payload.
437func decryptInitialPacket(packet, encrypted, key, iv, hp []byte) ([]byte, error) {
438 if len(encrypted) < 20 {
439 return nil, errors.New("encrypted payload too short")
440 }
441
442 // Create HP cipher
443 hpCipher, err := aes.NewCipher(hp)
444 if err != nil {
445 return nil, err
446 }
447
448 // Create AEAD cipher
449 aesCipher, err := aes.NewCipher(key)
450 if err != nil {
451 return nil, err
452 }
453 aead, err := cipher.NewGCM(aesCipher)
454 if err != nil {
455 return nil, err
456 }
457
458 return DecryptWithCachedCrypto(packet, encrypted, hpCipher, aead, iv)
459}
460
461// DecryptWithCachedCrypto decrypts an Initial packet using pre-derived keys.
462// This is faster than decryptInitialPacket as it reuses cipher objects.

Callers 1

Calls 1

DecryptWithCachedCryptoFunction · 0.85

Tested by

no test coverage detected