FuzzCBCDecryption tests CBC decryption with random inputs. Tests both AES256 and SM4 cipher modes.
(f *testing.F)
| 81 | // FuzzCBCDecryption tests CBC decryption with random inputs. |
| 82 | // Tests both AES256 and SM4 cipher modes. |
| 83 | func FuzzCBCDecryption(f *testing.F) { |
| 84 | // Seed corpus with various sizes |
| 85 | f.Add(make([]byte, 16), 0) // one block, AES |
| 86 | f.Add(make([]byte, 32), 0) // two blocks, AES |
| 87 | f.Add(make([]byte, 17), 0) // invalid size (not multiple of block), AES |
| 88 | f.Add(make([]byte, 16), 1) // one block, SM4 |
| 89 | f.Add(make([]byte, 17), 1) // invalid size, SM4 |
| 90 | f.Add([]byte{}, 0) // empty |
| 91 | |
| 92 | f.Fuzz(func(t *testing.T, ciphertext []byte, cipherType int) { |
| 93 | // Use a fixed key for testing |
| 94 | var key [core.SymmetricKeySize]byte |
| 95 | for i := range key { |
| 96 | key[i] = byte(i) |
| 97 | } |
| 98 | |
| 99 | var gcmType core.GcmTypeEnum |
| 100 | switch cipherType % 2 { |
| 101 | case 0: |
| 102 | gcmType = core.GCM_AES256 |
| 103 | case 1: |
| 104 | gcmType = core.GCM_SM4 |
| 105 | } |
| 106 | |
| 107 | // CBCDecryption should not panic on any input |
| 108 | _, _ = core.CBCDecryption(gcmType, &key, ciphertext, false) |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | // FuzzUdpPeerName tests UdpPeer.Name() with various public key lengths. |
| 113 | // The Name() function slices PubKeyBase64 which could panic on short strings. |