This document outlines all the enum-based API overloads added to support type-safe security level specifications in GreenfieldPQC.
public enum KyberSecurityLevel
{
ML_KEM_512 = 1, // NIST Level 1
ML_KEM_768 = 3, // NIST Level 3
ML_KEM_1024 = 5 // NIST Level 5
}public enum DilithiumSecurityLevel
{
ML_DSA_44 = 2, // NIST Level 2
ML_DSA_65 = 3, // NIST Level 3
ML_DSA_87 = 5 // NIST Level 5
}- Int overload (existing):
CreateKyber(int parameter)- Accepts 512, 768, or 1024 - Enum overload (v1.1.0+):
CreateKyber(KyberSecurityLevel level)- Accepts enum values - Usage examples:
var kyber1 = CryptoFactory.CreateKyber(768); // Old API var kyber2 = CryptoFactory.CreateKyber(KyberSecurityLevel.ML_KEM_768); // New API
- Int overload (existing):
CreateDilithium(int level)- Accepts 2, 3, or 5 - Enum overload (v1.1.0+):
CreateDilithium(DilithiumSecurityLevel level)- Accepts enum values - Usage examples:
var dilithium1 = CryptoFactory.CreateDilithium(3); // Old API var dilithium2 = CryptoFactory.CreateDilithium(DilithiumSecurityLevel.ML_DSA_65); // New API
- Int overload (existing):
CreateJweProvider(int kyberLevel = 3, CipherAlgorithm kusumiAlgorithm = CipherAlgorithm.Kusumi512) - Enum overload (v1.1.1+):
CreateJweProvider(KyberSecurityLevel kyberLevel = KyberSecurityLevel.ML_KEM_768, CipherAlgorithm kusumiAlgorithm = CipherAlgorithm.Kusumi512) - Usage examples:
var jwe1 = CryptoFactory.CreateJweProvider(3, CipherAlgorithm.Kusumi512Poly1305); // Old API var jwe2 = CryptoFactory.CreateJweProvider(KyberSecurityLevel.ML_KEM_768, CipherAlgorithm.Kusumi512Poly1305); // New API
- Int overload (existing):
CreateJwsProvider(int dilithiumLevel = 3) - Enum overload (v1.1.1+):
CreateJwsProvider(DilithiumSecurityLevel dilithiumLevel = DilithiumSecurityLevel.ML_DSA_65) - Usage examples:
var jws1 = CryptoFactory.CreateJwsProvider(3); // Old API var jws2 = CryptoFactory.CreateJwsProvider(DilithiumSecurityLevel.ML_DSA_65); // New API
- Int constructor (existing):
KyberParameters(int securityLevel)- Accepts 512, 768, or 1024 - Enum constructor (v1.1.1+):
KyberParameters(KyberSecurityLevel securityLevel)- Accepts enum values - Usage examples:
var params1 = new KyberParameters(768); // Old API var params2 = new KyberParameters(KyberSecurityLevel.ML_KEM_768); // New API
- Int constructor (existing):
DilithiumParameters(int securityLevel)- Accepts 2, 3, or 5 - Enum constructor (v1.1.1+):
DilithiumParameters(DilithiumSecurityLevel securityLevel)- Accepts enum values - Usage examples:
var params1 = new DilithiumParameters(3); // Old API var params2 = new DilithiumParameters(DilithiumSecurityLevel.ML_DSA_65); // New API
All enum-based APIs are fully tested with the following test cases:
CreateKyber_WithEnum_ReturnsCorrectAlgorithm- Tests all 3 Kyber levelsCreateDilithium_WithEnum_ReturnsCorrectAlgorithm- Tests all 3 Dilithium levelsCreateJwsProvider_WithEnum_CreatesValidProvider- Tests JWS creation and verification with enum APICreateJweProvider_WithEnum_CreatesValidProvider- Tests JWE creation and decryption with enum API
JwsJweNesting_WithEnums_RoundTrip- Tests nested JWT scenario using only enum APIEnumAndIntAPI_ProduceSameResults- Tests backward compatibility between int and enum APIs
KyberParameters_WithEnum_MapsToCorrectIntValue- Verifies enum-to-int mapping for KyberDilithiumParameters_WithEnum_MapsToCorrectIntValue- Verifies enum-to-int mapping for Dilithium
? All existing int-based APIs remain functional and unchanged.
The enum overloads call the int-based implementations internally, ensuring:
- No breaking changes for existing code
- Both APIs can be used interchangeably
- Cross-compatibility (e.g., create with int API, use with enum API)
var jweProvider = CryptoFactory.CreateJweProvider(3, CryptoFactory.CipherAlgorithm.Kusumi512Poly1305);
var jwsProvider = CryptoFactory.CreateJwsProvider(3);
var kyber = CryptoFactory.CreateKyber(768);
var dilithium = CryptoFactory.CreateDilithium(3);var jweProvider = CryptoFactory.CreateJweProvider(
KyberSecurityLevel.ML_KEM_768,
CryptoFactory.CipherAlgorithm.Kusumi512Poly1305
);
var jwsProvider = CryptoFactory.CreateJwsProvider(DilithiumSecurityLevel.ML_DSA_65);
var kyber = CryptoFactory.CreateKyber(KyberSecurityLevel.ML_KEM_768);
var dilithium = CryptoFactory.CreateDilithium(DilithiumSecurityLevel.ML_DSA_65);- Type Safety: Compiler catches invalid security levels at compile time
- IntelliSense: IDE autocomplete shows available security levels
- Self-Documenting: Code clearly shows which NIST standard is being used (ML-KEM-768, ML-DSA-65)
- Future-Proof: Easier to add new security levels without breaking changes
- Backward Compatible: Existing code continues to work without modifications
- v1.1.0: Added
KyberSecurityLevelandDilithiumSecurityLevelenums; Added enum overloads toCreateKyberandCreateDilithium - v1.1.1: Added enum overloads to
CreateJweProvider,CreateJwsProvider,KyberParameters, andDilithiumParameters; Added comprehensive test coverage
| Component | Int API | Enum API | Tests |
|---|---|---|---|
| CreateKyber | ? | ? | ? |
| CreateDilithium | ? | ? | ? |
| CreateJweProvider | ? | ? | ? |
| CreateJwsProvider | ? | ? | ? |
| KyberParameters | ? | ? | ? |
| DilithiumParameters | ? | ? | ? |
| Kyber constructor | ? (via params) | ? (via params) | ? |
| Dilithium constructor | ? (via params) | ? (via params) | ? |
Status: ? All enum APIs implemented and tested