Skip to content

Commit ab88132

Browse files
Add python script to generate algorithm families (#645)
This PR will add a python script that can be used to generate an enum-object for the cyclonedx json schema that reflects algorithm families defined in `cryptography-defs.json`.
2 parents 4e9ef89 + 2481f1a commit ab88132

4 files changed

Lines changed: 123 additions & 6 deletions

File tree

schema/bom-1.7.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5114,6 +5114,12 @@
51145114
"unknown": "The primitive is not known."
51155115
}
51165116
},
5117+
"algorithmFamily": {
5118+
"$ref": "cryptography-defs.schema.json#/properties/algorithmFamilies",
5119+
"title": "Algorithm Family",
5120+
"description": "A valid algorithm family identifier. If specified, this value must be one of the enumeration of valid algorithm Family identifiers defined in the cryptography-defs.schema.json subschema.",
5121+
"examples": ["3DES", "Blowfish", "ECDH"]
5122+
},
51175123
"parameterSetIdentifier": {
51185124
"type": "string",
51195125
"title": "Parameter Set Identifier",
@@ -5526,6 +5532,8 @@
55265532
"ike",
55275533
"sstp",
55285534
"wpa",
5535+
"dtls",
5536+
"quic",
55295537
"other",
55305538
"unknown"
55315539
],

schema/cryptography-defs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
{
144144
"family": "SHA-3",
145145
"standard": [
146-
{"name": "FIPS202", "url": "https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf"}
146+
{"name": "FIPS202", "url": "https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf"},
147147
{"name": "SP800-185", "url": "https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf"}
148148
],
149149
"variant": [

schema/cryptography-defs.schema.json

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"$id": "http://cyclonedx.org/schema/cryptography-defs.schema.json",
4+
"$comment": "2025-06-12T08:47:23.114985",
45
"title": "Cryptographic Algorithm Family Definitions",
56
"description": "Enumerates cryptographic algorithm families and their specific metadata.",
67
"type": "object",
@@ -54,7 +55,10 @@
5455
"description": "A URL pointing to the standard's official documentation."
5556
}
5657
},
57-
"required": ["name", "url"]
58+
"required": [
59+
"name",
60+
"url"
61+
]
5862
}
5963
},
6064
"variant": {
@@ -101,17 +105,83 @@
101105
"description": "A URL pointing to the standard's official documentation."
102106
}
103107
},
104-
"required": ["name", "url"]
108+
"required": [
109+
"name",
110+
"url"
111+
]
105112
}
106113
}
107114
},
108-
"required": ["pattern", "primitive"]
115+
"required": [
116+
"pattern",
117+
"primitive"
118+
]
109119
}
110120
}
111121
},
112-
"required": ["family", "variant"]
122+
"required": [
123+
"family",
124+
"variant"
125+
]
113126
}
127+
},
128+
"algorithmFamilies": {
129+
"type": "string",
130+
"title": "Algorithm Families",
131+
"description": "An enum for the algorithm families.",
132+
"enum": [
133+
"3DES",
134+
"AES",
135+
"ARIA",
136+
"BLAKE2b",
137+
"Blowfish",
138+
"CAMELLIA",
139+
"CMAC",
140+
"ChaCha",
141+
"ChaCha20",
142+
"DES",
143+
"DSA",
144+
"ECDH",
145+
"ECDSA",
146+
"EdDSA",
147+
"FFDH",
148+
"GOST",
149+
"HKDF",
150+
"HMAC",
151+
"HashML-DSA",
152+
"HashSLH-DSA",
153+
"IDEA",
154+
"IKE-PRF",
155+
"KMAC",
156+
"LMS",
157+
"MD4",
158+
"MD5",
159+
"ML-DSA",
160+
"ML-KEM",
161+
"PKCS12-PBEA",
162+
"PKCS5-PBE",
163+
"Poly1305",
164+
"RC2",
165+
"RC4",
166+
"RSAES-OAEP",
167+
"RSAES-PKCS1",
168+
"RSASSA-PKCS1",
169+
"RSASSA-PSS",
170+
"SEED",
171+
"SHA-1",
172+
"SHA-2",
173+
"SHA-3",
174+
"SP800-108",
175+
"Salsa20",
176+
"Twofish",
177+
"X3DH",
178+
"XMSS"
179+
]
114180
}
115181
},
116-
"required": ["lastUpdated", "algorithms"]
182+
"required": [
183+
"lastUpdated",
184+
"algorithms",
185+
"algorithmFamilies"
186+
]
117187
}

tools/algorithmFamilyGeneration.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
from datetime import datetime
3+
from pathlib import Path
4+
from typing import Dict, List, Any
5+
6+
# Step 1: Load JSON data safely using context managers
7+
SCHEMA_DIR = Path(__file__).parent.parent / "schema"
8+
DEFS_FILE = SCHEMA_DIR / "cryptography-defs.json"
9+
SCHEMA_FILE = SCHEMA_DIR / "cryptography-defs.schema.json"
10+
11+
with DEFS_FILE.open("r", encoding="utf-8") as defs_file:
12+
defs_data: Dict[str, List[Dict[str, Any]]] = json.load(defs_file)
13+
14+
with SCHEMA_FILE.open("r", encoding="utf-8") as schema_file:
15+
schema_data: Dict[str, Any] = json.load(schema_file)
16+
17+
# Step 2: Extract unique algorithm families and sort them
18+
families: List[str] = sorted({algo['family'] for algo in defs_data.get('algorithms', [])})
19+
20+
# Step 3: Update the schema with the extracted families
21+
try:
22+
schema_properties = schema_data['properties']
23+
except KeyError as e:
24+
raise KeyError(f"Required schema property 'properties' missing: {e}")
25+
26+
schema_data['$comment'] = datetime.now().isoformat()
27+
28+
schema_data['properties']['algorithmFamilies'] = {
29+
"type": "string",
30+
"title": "Algorithm Families",
31+
"description": "An enum for the algorithm families.",
32+
"enum": families,
33+
}
34+
35+
# Step 4: Write the updated schema back to the file
36+
with SCHEMA_FILE.open("w", encoding="utf-8") as update_file:
37+
json.dump(schema_data, update_file, indent=2, ensure_ascii=False)
38+
39+
print("Schema updated successfully.")

0 commit comments

Comments
 (0)