|
53 | 53 | import org.bouncycastle.pqc.legacy.crypto.mceliece.McElieceCCA2PrivateKeyParameters; |
54 | 54 | import org.bouncycastle.pqc.legacy.crypto.qtesla.QTESLAPrivateKeyParameters; |
55 | 55 | import org.bouncycastle.util.Pack; |
| 56 | +import org.bouncycastle.util.Properties; |
56 | 57 |
|
57 | 58 | /** |
58 | 59 | * Factory to create ASN.1 private key info objects from lightweight private keys. |
@@ -247,18 +248,17 @@ else if (privateKey instanceof MLKEMPrivateKeyParameters) |
247 | 248 | MLKEMPrivateKeyParameters params = (MLKEMPrivateKeyParameters)privateKey; |
248 | 249 |
|
249 | 250 | AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(Utils.mlkemOidLookup(params.getParameters())); |
250 | | - |
251 | | - return new PrivateKeyInfo(algorithmIdentifier, getBasicPQCEncoding(params.getSeed(), params.getEncoded()), attributes); |
252 | | -// byte[] seed = params.getSeed(); |
253 | | -// |
254 | | -// if (seed == null) |
255 | | -// { |
256 | | -// return new PrivateKeyInfo(algorithmIdentifier, params.getEncoded(), attributes); |
257 | | -// } |
258 | | -// else |
259 | | -// { |
260 | | -// return new PrivateKeyInfo(algorithmIdentifier, seed, attributes); |
261 | | -// } |
| 251 | + |
| 252 | + byte[] seed = params.getSeed(); |
| 253 | + if (Properties.isOverrideSet("org.bouncycastle.mlkem.seedOnly")) |
| 254 | + { |
| 255 | + if (seed == null) // very difficult to imagine, but... |
| 256 | + { |
| 257 | + throw new IOException("no seed available"); |
| 258 | + } |
| 259 | + return new PrivateKeyInfo(algorithmIdentifier, seed, attributes); |
| 260 | + } |
| 261 | + return new PrivateKeyInfo(algorithmIdentifier, getBasicPQCEncoding(seed, params.getEncoded()), attributes); |
262 | 262 | } |
263 | 263 | else if (privateKey instanceof NTRULPRimePrivateKeyParameters) |
264 | 264 | { |
@@ -297,20 +297,16 @@ else if (privateKey instanceof MLDSAPrivateKeyParameters) |
297 | 297 |
|
298 | 298 | AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(Utils.mldsaOidLookup(params.getParameters())); |
299 | 299 |
|
| 300 | + byte[] seed = params.getSeed(); |
| 301 | + if (Properties.isOverrideSet("org.bouncycastle.mldsa.seedOnly")) |
| 302 | + { |
| 303 | + if (seed == null) // very difficult to imagine, but... |
| 304 | + { |
| 305 | + throw new IOException("no seed available"); |
| 306 | + } |
| 307 | + return new PrivateKeyInfo(algorithmIdentifier, seed, attributes); |
| 308 | + } |
300 | 309 | return new PrivateKeyInfo(algorithmIdentifier, getBasicPQCEncoding(params.getSeed(), params.getEncoded()), attributes); |
301 | | -// byte[] seed = params.getSeed(); |
302 | | -// if (seed == null) |
303 | | -// { |
304 | | -// MLDSAPublicKeyParameters pubParams = params.getPublicKeyParameters(); |
305 | | -// |
306 | | -// return new PrivateKeyInfo(algorithmIdentifier, params.getEncoded(), attributes, pubParams.getEncoded()); |
307 | | -// } |
308 | | -// else |
309 | | -// { |
310 | | -// MLDSAPublicKeyParameters pubParams = params.getPublicKeyParameters(); |
311 | | -// |
312 | | -// return new PrivateKeyInfo(algorithmIdentifier, seed, attributes, pubParams.getEncoded()); |
313 | | -// } |
314 | 310 | } |
315 | 311 | else if (privateKey instanceof DilithiumPrivateKeyParameters) |
316 | 312 | { |
|
0 commit comments