FuzzECDHFromKey tests ECDH key creation with random inputs. This is important for security as malformed keys should be handled gracefully.
(f *testing.F)
| 9 | // FuzzECDHFromKey tests ECDH key creation with random inputs. |
| 10 | // This is important for security as malformed keys should be handled gracefully. |
| 11 | func FuzzECDHFromKey(f *testing.F) { |
| 12 | // Seed corpus with valid key sizes |
| 13 | f.Add([]byte{}, int(core.ECC_CURVE25519)) |
| 14 | f.Add(make([]byte, 32), int(core.ECC_CURVE25519)) |
| 15 | f.Add(make([]byte, 64), int(core.ECC_SM2)) |
| 16 | f.Add(make([]byte, 16), int(core.ECC_CURVE25519)) |
| 17 | f.Add(make([]byte, 48), int(core.ECC_SM2)) |
| 18 | |
| 19 | f.Fuzz(func(t *testing.T, data []byte, eccType int) { |
| 20 | // Normalize eccType to valid range |
| 21 | var eType core.EccTypeEnum |
| 22 | switch eccType % 2 { |
| 23 | case 0: |
| 24 | eType = core.ECC_CURVE25519 |
| 25 | case 1: |
| 26 | eType = core.ECC_SM2 |
| 27 | } |
| 28 | |
| 29 | // ECDHFromKey should not panic on any input |
| 30 | // It should return nil for invalid keys |
| 31 | e := core.ECDHFromKey(eType, data) |
| 32 | if e != nil { |
| 33 | // If key was accepted, verify basic operations don't panic |
| 34 | _ = e.PublicKey() |
| 35 | _ = e.PublicKeyBase64() |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | |
| 40 | // FuzzAESDecrypt tests AES decryption with random inputs. |
| 41 | // Ensures malformed ciphertext is handled without panics. |
nothing calls this directly
no test coverage detected