decryptInitialPacket removes header protection and decrypts the payload.
(packet, encrypted, key, iv, hp []byte)
| 435 | |
| 436 | // decryptInitialPacket removes header protection and decrypts the payload. |
| 437 | func 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. |
no test coverage detected