Skip to content

Commit 508dbf9

Browse files
gefeilidghgit
authored andcommitted
Add BcHssLmsContentSignerBuilder
1 parent c30fd65 commit 508dbf9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

core/src/main/java/org/bouncycastle/asn1/pkcs/PKCSObjectIdentifiers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public interface PKCSObjectIdentifiers
278278
* id-alg-hss-lms-hashsig OBJECT IDENTIFIER ::= { iso(1)
279279
* member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9)
280280
* smime(16) alg(3) 17 }
281+
* 1.2.840.113549.1.9.16.3.17
281282
*/
282283
public static final ASN1ObjectIdentifier id_alg_hss_lms_hashsig = smime_alg.branch("17");
283284

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.bouncycastle.operator.bc;
2+
3+
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
4+
import org.bouncycastle.crypto.CipherParameters;
5+
import org.bouncycastle.crypto.CryptoException;
6+
import org.bouncycastle.crypto.DataLengthException;
7+
import org.bouncycastle.crypto.Digest;
8+
import org.bouncycastle.crypto.Signer;
9+
import org.bouncycastle.operator.OperatorCreationException;
10+
import org.bouncycastle.pqc.crypto.MessageSigner;
11+
import org.bouncycastle.pqc.crypto.lms.HSSSigner;
12+
13+
public class BcHssLmsContentSignerBuilder
14+
extends BcContentSignerBuilder
15+
{
16+
public BcHssLmsContentSignerBuilder(AlgorithmIdentifier sigAlgId, AlgorithmIdentifier digAlgId)
17+
{
18+
super(sigAlgId, digAlgId);
19+
}
20+
21+
protected Signer createSigner(AlgorithmIdentifier sigAlgId, AlgorithmIdentifier digAlgId)
22+
throws OperatorCreationException
23+
{
24+
Digest dig = digestProvider.get(digAlgId);
25+
26+
return new HssSigner(dig);
27+
}
28+
29+
private static class HssSigner
30+
implements Signer
31+
{
32+
private final MessageSigner hss = new HSSSigner();
33+
private final Digest digest;
34+
35+
public HssSigner(Digest digest)
36+
{
37+
this.digest = digest;
38+
}
39+
40+
@Override
41+
public void init(boolean forSigning, CipherParameters param)
42+
{
43+
hss.init(forSigning, param);
44+
}
45+
46+
@Override
47+
public void update(byte b)
48+
{
49+
digest.update(b);
50+
}
51+
52+
@Override
53+
public void update(byte[] in, int off, int len)
54+
{
55+
digest.update(in, off, len);
56+
}
57+
58+
@Override
59+
public byte[] generateSignature()
60+
throws CryptoException, DataLengthException
61+
{
62+
byte[] hash = new byte[digest.getDigestSize()];
63+
digest.doFinal(hash, 0);
64+
return hss.generateSignature(hash);
65+
}
66+
67+
@Override
68+
public boolean verifySignature(byte[] signature)
69+
{
70+
byte[] hash = new byte[digest.getDigestSize()];
71+
digest.doFinal(hash, 0);
72+
return hss.verifySignature(hash, signature);
73+
}
74+
75+
@Override
76+
public void reset()
77+
{
78+
digest.reset();
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)