Skip to content

Commit a365ff4

Browse files
committed
Added support for HSS
1 parent 85d498a commit a365ff4

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

java/ql/lib/experimental/quantum/BouncyCastle/AlgorithmInstances.qll

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,25 @@ class ECDSASignatureAlgorithmInstance extends SignatureAlgorithmInstance instanc
176176
}
177177

178178
/**
179-
* LMS signers.
179+
* An LMS or HSS stateful hash-based signer.
180180
*/
181-
class LMSSignatureAlgorithmInstance extends SignatureAlgorithmInstance instanceof ClassInstanceExpr {
182-
LMSSignatureAlgorithmInstance() {
181+
class StatefulSignatureAlgorithmInstance extends SignatureAlgorithmInstance instanceof ClassInstanceExpr
182+
{
183+
StatefulSignatureAlgorithmInstance() {
183184
super.getConstructedType() instanceof Signers::Signer and
184-
super.getConstructedType().getName().matches("LMS%")
185+
super.getConstructedType().getName().matches(["LMS%", "HSS%"])
185186
}
186187

187188
override string getRawAlgorithmName() {
188189
typeNameToRawAlgorithmName(super.getConstructedType().getName(), result)
189190
}
190191

191192
override Crypto::KeyOpAlg::Algorithm getAlgorithmType() {
193+
super.getConstructedType().getName().matches("LMS%") and
192194
result = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::LMS())
195+
or
196+
super.getConstructedType().getName().matches("HSS%") and
197+
result = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::HSS())
193198
}
194199
}
195200

@@ -307,25 +312,26 @@ class GenericEllipticCurveKeyGenerationAlgorithmInstance extends KeyGenerationAl
307312
}
308313

309314
/**
310-
* Represents LMS key generation instances. The algorithm is implicitly defined
311-
* by the type.
312-
*
313-
* TODO: Determine how to represent LMS parameters, such as the hash function
314-
* and the tree height.
315+
* Represents LMS or HSS key generation instances. The algorithm is implicitly
316+
* defined by the type.
315317
*/
316-
class LMSKeyGenerationAlgorithmInstance extends KeyGenerationAlgorithmInstance instanceof ClassInstanceExpr
318+
class StatefulSignatureKeyGenerationAlgorithmInstance extends KeyGenerationAlgorithmInstance instanceof ClassInstanceExpr
317319
{
318-
LMSKeyGenerationAlgorithmInstance() {
320+
StatefulSignatureKeyGenerationAlgorithmInstance() {
319321
super.getConstructedType() instanceof Generators::KeyGenerator and
320-
super.getConstructedType().getName().matches("LMS%")
322+
super.getConstructedType().getName().matches(["LMS%", "HSS%"])
321323
}
322324

323325
override string getRawAlgorithmName() {
324326
typeNameToRawAlgorithmName(super.getConstructedType().getName(), result)
325327
}
326328

327329
override Crypto::KeyOpAlg::Algorithm getAlgorithmType() {
330+
super.getConstructedType().getName().matches("LMS%") and
328331
result = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::LMS())
332+
or
333+
super.getConstructedType().getName().matches("HSS%") and
334+
result = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::HSS())
329335
}
330336
}
331337

@@ -336,11 +342,11 @@ bindingset[typeName]
336342
private predicate typeNameToRawAlgorithmName(string typeName, string algorithmName) {
337343
// Ed25519, Ed25519ph, and Ed25519ctx key generators and signers
338344
typeName.matches("Ed25519%") and
339-
algorithmName = "ED25519"
345+
algorithmName = "Ed25519"
340346
or
341347
// Ed448 and Ed448ph key generators and signers
342348
typeName.matches("Ed448%") and
343-
algorithmName = "ED448"
349+
algorithmName = "Ed448"
344350
or
345351
// ECDSA
346352
typeName.matches("ECDSA%") and
@@ -349,28 +355,32 @@ private predicate typeNameToRawAlgorithmName(string typeName, string algorithmNa
349355
// LMS
350356
typeName.matches("LMS%") and
351357
algorithmName = "LMS"
358+
or
359+
// HSS
360+
typeName.matches("HSS%") and
361+
algorithmName = "HSS"
352362
}
353363

354364
private predicate signatureNameToKeySizeAndAlgorithmMapping(
355365
string name, int keySize, Crypto::KeyOpAlg::Algorithm algorithm
356366
) {
357-
name = "ED25519" and
367+
name = "Ed25519" and
358368
keySize = 256 and
359369
algorithm = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::Ed25519())
360370
or
361-
name = "ED448" and
371+
name = "Ed448" and
362372
keySize = 448 and
363373
algorithm = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::Ed448())
364374
}
365375

366376
private predicate generatorNameToKeySizeAndAlgorithmMapping(
367377
string name, int keySize, Crypto::KeyOpAlg::Algorithm algorithm
368378
) {
369-
name = "ED25519" and
379+
name = "Ed25519" and
370380
keySize = 256 and
371381
algorithm = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::Ed25519())
372382
or
373-
name = "ED448" and
383+
name = "Ed448" and
374384
keySize = 448 and
375385
algorithm = Crypto::KeyOpAlg::TSignature(Crypto::KeyOpAlg::Ed448())
376386
}

java/ql/lib/experimental/quantum/BouncyCastle/OperationInstances.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@ module Signers {
162162
}
163163
}
164164

165+
/**
166+
* This class represents signers with a one shot API (where the entire message
167+
* is passed to either `generateSignature()` or `verifySignature`.).
168+
*/
165169
class OneShotSigner extends Signer {
166-
OneShotSigner() { this.getName().matches(["ECDSA%", "LMS%"]) }
170+
OneShotSigner() { this.getName().matches(["ECDSA%", "LMS%", "HSS%"]) }
167171

168172
override Expr getMessageArg(MethodCall call) {
169173
// For ECDSA and LMS, the message is passed directly to `generateSignature()`.

shared/quantum/codeql/quantum/experimental/Model.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
607607
Ed25519() or
608608
Ed448() or
609609
LMS() or
610+
HSS() or
610611
MLDSA() or
611612
OtherSignatureAlgorithmType()
612613

0 commit comments

Comments
 (0)