Skip to content

Commit 94173c7

Browse files
committed
Port of CVC-ECDSA and PLAIN-ECDSA from Java
1 parent fe659c4 commit 94173c7

23 files changed

+559
-211
lines changed

crypto/BouncyCastle.Android.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<Compile Include="src\asn1\anssi\ANSSINamedCurves.cs" />
143143
<Compile Include="src\asn1\anssi\ANSSIObjectIdentifiers.cs" />
144144
<Compile Include="src\asn1\bc\BCObjectIdentifiers.cs" />
145+
<Compile Include="src\asn1\bsi\BsiObjectIdentifiers.cs" />
145146
<Compile Include="src\asn1\cmp\CAKeyUpdAnnContent.cs" />
146147
<Compile Include="src\asn1\cmp\CertConfirmContent.cs" />
147148
<Compile Include="src\asn1\cmp\CertOrEncCert.cs" />
@@ -651,6 +652,7 @@
651652
<Compile Include="src\crypto\IBufferedCipher.cs" />
652653
<Compile Include="src\crypto\ICipherParameters.cs" />
653654
<Compile Include="src\crypto\IDSA.cs" />
655+
<Compile Include="src\crypto\IDsaExt.cs" />
654656
<Compile Include="src\crypto\IDerivationFunction.cs" />
655657
<Compile Include="src\crypto\IDerivationParameters.cs" />
656658
<Compile Include="src\crypto\IDigest.cs" />
@@ -985,14 +987,17 @@
985987
<Compile Include="src\crypto\signers\GOST3410Signer.cs" />
986988
<Compile Include="src\crypto\signers\GenericSigner.cs" />
987989
<Compile Include="src\crypto\signers\HMacDsaKCalculator.cs" />
990+
<Compile Include="src\crypto\signers\IDsaEncoding.cs" />
988991
<Compile Include="src\crypto\signers\IDsaKCalculator.cs" />
989992
<Compile Include="src\crypto\signers\Iso9796d2PssSigner.cs" />
990993
<Compile Include="src\crypto\signers\Iso9796d2Signer.cs" />
991994
<Compile Include="src\crypto\signers\IsoTrailers.cs" />
995+
<Compile Include="src\crypto\signers\PlainDsaEncoding.cs" />
992996
<Compile Include="src\crypto\signers\PssSigner.cs" />
993997
<Compile Include="src\crypto\signers\RandomDsaKCalculator.cs" />
994998
<Compile Include="src\crypto\signers\RsaDigestSigner.cs" />
995999
<Compile Include="src\crypto\signers\SM2Signer.cs" />
1000+
<Compile Include="src\crypto\signers\StandardDsaEncoding.cs" />
9961001
<Compile Include="src\crypto\signers\X931Signer.cs" />
9971002
<Compile Include="src\crypto\tls\AbstractTlsAgreementCredentials.cs" />
9981003
<Compile Include="src\crypto\tls\AbstractTlsCipherFactory.cs" />

crypto/BouncyCastle.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<Compile Include="src\asn1\anssi\ANSSINamedCurves.cs" />
137137
<Compile Include="src\asn1\anssi\ANSSIObjectIdentifiers.cs" />
138138
<Compile Include="src\asn1\bc\BCObjectIdentifiers.cs" />
139+
<Compile Include="src\asn1\bsi\BsiObjectIdentifiers.cs" />
139140
<Compile Include="src\asn1\cmp\CAKeyUpdAnnContent.cs" />
140141
<Compile Include="src\asn1\cmp\CertConfirmContent.cs" />
141142
<Compile Include="src\asn1\cmp\CertOrEncCert.cs" />
@@ -645,6 +646,7 @@
645646
<Compile Include="src\crypto\IBufferedCipher.cs" />
646647
<Compile Include="src\crypto\ICipherParameters.cs" />
647648
<Compile Include="src\crypto\IDSA.cs" />
649+
<Compile Include="src\crypto\IDsaExt.cs" />
648650
<Compile Include="src\crypto\IDerivationFunction.cs" />
649651
<Compile Include="src\crypto\IDerivationParameters.cs" />
650652
<Compile Include="src\crypto\IDigest.cs" />
@@ -979,14 +981,17 @@
979981
<Compile Include="src\crypto\signers\GOST3410Signer.cs" />
980982
<Compile Include="src\crypto\signers\GenericSigner.cs" />
981983
<Compile Include="src\crypto\signers\HMacDsaKCalculator.cs" />
984+
<Compile Include="src\crypto\signers\IDsaEncoding.cs" />
982985
<Compile Include="src\crypto\signers\IDsaKCalculator.cs" />
983986
<Compile Include="src\crypto\signers\Iso9796d2PssSigner.cs" />
984987
<Compile Include="src\crypto\signers\Iso9796d2Signer.cs" />
985988
<Compile Include="src\crypto\signers\IsoTrailers.cs" />
989+
<Compile Include="src\crypto\signers\PlainDsaEncoding.cs" />
986990
<Compile Include="src\crypto\signers\PssSigner.cs" />
987991
<Compile Include="src\crypto\signers\RandomDsaKCalculator.cs" />
988992
<Compile Include="src\crypto\signers\RsaDigestSigner.cs" />
989993
<Compile Include="src\crypto\signers\SM2Signer.cs" />
994+
<Compile Include="src\crypto\signers\StandardDsaEncoding.cs" />
990995
<Compile Include="src\crypto\signers\X931Signer.cs" />
991996
<Compile Include="src\crypto\tls\AbstractTlsAgreementCredentials.cs" />
992997
<Compile Include="src\crypto\tls\AbstractTlsCipherFactory.cs" />

crypto/BouncyCastle.iOS.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<Compile Include="src\asn1\anssi\ANSSINamedCurves.cs" />
138138
<Compile Include="src\asn1\anssi\ANSSIObjectIdentifiers.cs" />
139139
<Compile Include="src\asn1\bc\BCObjectIdentifiers.cs" />
140+
<Compile Include="src\asn1\bsi\BsiObjectIdentifiers.cs" />
140141
<Compile Include="src\asn1\cmp\CAKeyUpdAnnContent.cs" />
141142
<Compile Include="src\asn1\cmp\CertConfirmContent.cs" />
142143
<Compile Include="src\asn1\cmp\CertOrEncCert.cs" />
@@ -646,6 +647,7 @@
646647
<Compile Include="src\crypto\IBufferedCipher.cs" />
647648
<Compile Include="src\crypto\ICipherParameters.cs" />
648649
<Compile Include="src\crypto\IDSA.cs" />
650+
<Compile Include="src\crypto\IDsaExt.cs" />
649651
<Compile Include="src\crypto\IDerivationFunction.cs" />
650652
<Compile Include="src\crypto\IDerivationParameters.cs" />
651653
<Compile Include="src\crypto\IDigest.cs" />
@@ -980,14 +982,17 @@
980982
<Compile Include="src\crypto\signers\GOST3410Signer.cs" />
981983
<Compile Include="src\crypto\signers\GenericSigner.cs" />
982984
<Compile Include="src\crypto\signers\HMacDsaKCalculator.cs" />
985+
<Compile Include="src\crypto\signers\IDsaEncoding.cs" />
983986
<Compile Include="src\crypto\signers\IDsaKCalculator.cs" />
984987
<Compile Include="src\crypto\signers\Iso9796d2PssSigner.cs" />
985988
<Compile Include="src\crypto\signers\Iso9796d2Signer.cs" />
986989
<Compile Include="src\crypto\signers\IsoTrailers.cs" />
990+
<Compile Include="src\crypto\signers\PlainDsaEncoding.cs" />
987991
<Compile Include="src\crypto\signers\PssSigner.cs" />
988992
<Compile Include="src\crypto\signers\RandomDsaKCalculator.cs" />
989993
<Compile Include="src\crypto\signers\RsaDigestSigner.cs" />
990994
<Compile Include="src\crypto\signers\SM2Signer.cs" />
995+
<Compile Include="src\crypto\signers\StandardDsaEncoding.cs" />
991996
<Compile Include="src\crypto\signers\X931Signer.cs" />
992997
<Compile Include="src\crypto\tls\AbstractTlsAgreementCredentials.cs" />
993998
<Compile Include="src\crypto\tls\AbstractTlsCipherFactory.cs" />

crypto/crypto.csproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@
568568
SubType = "Code"
569569
BuildAction = "Compile"
570570
/>
571+
<File
572+
RelPath = "src\asn1\bsi\BsiObjectIdentifiers.cs"
573+
SubType = "Code"
574+
BuildAction = "Compile"
575+
/>
571576
<File
572577
RelPath = "src\asn1\cmp\CAKeyUpdAnnContent.cs"
573578
SubType = "Code"
@@ -3098,6 +3103,11 @@
30983103
SubType = "Code"
30993104
BuildAction = "Compile"
31003105
/>
3106+
<File
3107+
RelPath = "src\crypto\IDsaExt.cs"
3108+
SubType = "Code"
3109+
BuildAction = "Compile"
3110+
/>
31013111
<File
31023112
RelPath = "src\crypto\IEntropySource.cs"
31033113
SubType = "Code"
@@ -4783,6 +4793,11 @@
47834793
SubType = "Code"
47844794
BuildAction = "Compile"
47854795
/>
4796+
<File
4797+
RelPath = "src\crypto\signers\IDsaEncoding.cs"
4798+
SubType = "Code"
4799+
BuildAction = "Compile"
4800+
/>
47864801
<File
47874802
RelPath = "src\crypto\signers\IDsaKCalculator.cs"
47884803
SubType = "Code"
@@ -4803,6 +4818,11 @@
48034818
SubType = "Code"
48044819
BuildAction = "Compile"
48054820
/>
4821+
<File
4822+
RelPath = "src\crypto\signers\PlainDsaEncoding.cs"
4823+
SubType = "Code"
4824+
BuildAction = "Compile"
4825+
/>
48064826
<File
48074827
RelPath = "src\crypto\signers\PSSSigner.cs"
48084828
SubType = "Code"
@@ -4823,6 +4843,11 @@
48234843
SubType = "Code"
48244844
BuildAction = "Compile"
48254845
/>
4846+
<File
4847+
RelPath = "src\crypto\signers\StandardDsaEncoding.cs"
4848+
SubType = "Code"
4849+
BuildAction = "Compile"
4850+
/>
48264851
<File
48274852
RelPath = "src\crypto\signers\X931Signer.cs"
48284853
SubType = "Code"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
3+
namespace Org.BouncyCastle.Asn1.Bsi
4+
{
5+
/// <remarks>See https://www.bsi.bund.de/cae/servlet/contentblob/471398/publicationFile/30615/BSI-TR-03111_pdf.pdf</remarks>
6+
public abstract class BsiObjectIdentifiers
7+
{
8+
public static readonly DerObjectIdentifier bsi_de = new DerObjectIdentifier("0.4.0.127.0.7");
9+
10+
/* 0.4.0.127.0.7.1.1 */
11+
public static readonly DerObjectIdentifier id_ecc = bsi_de.Branch("1.1");
12+
13+
/* 0.4.0.127.0.7.1.1.4.1 */
14+
public static readonly DerObjectIdentifier ecdsa_plain_signatures = id_ecc.Branch("4.1");
15+
16+
/* 0.4.0.127.0.7.1.1.4.1.1 */
17+
public static readonly DerObjectIdentifier ecdsa_plain_SHA1 = ecdsa_plain_signatures.Branch("1");
18+
19+
/* 0.4.0.127.0.7.1.1.4.1.2 */
20+
public static readonly DerObjectIdentifier ecdsa_plain_SHA224 = ecdsa_plain_signatures.Branch("2");
21+
22+
/* 0.4.0.127.0.7.1.1.4.1.3 */
23+
public static readonly DerObjectIdentifier ecdsa_plain_SHA256 = ecdsa_plain_signatures.Branch("3");
24+
25+
/* 0.4.0.127.0.7.1.1.4.1.4 */
26+
public static readonly DerObjectIdentifier ecdsa_plain_SHA384 = ecdsa_plain_signatures.Branch("4");
27+
28+
/* 0.4.0.127.0.7.1.1.4.1.5 */
29+
public static readonly DerObjectIdentifier ecdsa_plain_SHA512 = ecdsa_plain_signatures.Branch("5");
30+
31+
/* 0.4.0.127.0.7.1.1.4.1.6 */
32+
public static readonly DerObjectIdentifier ecdsa_plain_RIPEMD160 = ecdsa_plain_signatures.Branch("6");
33+
34+
/** 0.4.0.127.0.7.1 */
35+
public static readonly DerObjectIdentifier algorithm = bsi_de.Branch("1");
36+
37+
public static readonly DerObjectIdentifier ecka_eg = id_ecc.Branch("5.1");
38+
39+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963 OID: 0.4.0.127.0.7.1.1.5.1.1 */
40+
public static readonly DerObjectIdentifier ecka_eg_X963kdf = ecka_eg.Branch("1");
41+
42+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963
43+
* with hash function SHA-1
44+
* OID: 0.4.0.127.0.7.1.1.5.1.1.1 */
45+
public static readonly DerObjectIdentifier ecka_eg_X963kdf_SHA1 = ecka_eg_X963kdf.Branch("1");
46+
47+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963
48+
* with hash function SHA224
49+
* OID: 0.4.0.127.0.7.1.1.5.1.1.2 */
50+
public static readonly DerObjectIdentifier ecka_eg_X963kdf_SHA224 = ecka_eg_X963kdf.Branch("2");
51+
52+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963
53+
* with hash function SHA256
54+
* OID: 0.4.0.127.0.7.1.1.5.1.1.3 */
55+
public static readonly DerObjectIdentifier ecka_eg_X963kdf_SHA256 = ecka_eg_X963kdf.Branch("3");
56+
57+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963
58+
* with hash function SHA384
59+
* OID: 0.4.0.127.0.7.1.1.5.1.1.4 */
60+
public static readonly DerObjectIdentifier ecka_eg_X963kdf_SHA384 = ecka_eg_X963kdf.Branch("4");
61+
62+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963
63+
* with hash function SHA512
64+
* OID: 0.4.0.127.0.7.1.1.5.1.1.5 */
65+
public static readonly DerObjectIdentifier ecka_eg_X963kdf_SHA512 = ecka_eg_X963kdf.Branch("5");
66+
67+
/** ElGamal Elliptic Curve Key Agreement and Key Derivation according to X963
68+
* with hash function RIPEMD160
69+
* OID: 0.4.0.127.0.7.1.1.5.1.1.6 */
70+
public static readonly DerObjectIdentifier ecka_eg_X963kdf_RIPEMD160 = ecka_eg_X963kdf.Branch("6");
71+
72+
/**
73+
* Key Derivation Function for Session Keys
74+
*/
75+
public static readonly DerObjectIdentifier ecka_eg_SessionKDF = ecka_eg.Branch("2");
76+
77+
public static readonly DerObjectIdentifier ecka_eg_SessionKDF_3DES = ecka_eg_SessionKDF.Branch("1");
78+
public static readonly DerObjectIdentifier ecka_eg_SessionKDF_AES128 = ecka_eg_SessionKDF.Branch("2");
79+
public static readonly DerObjectIdentifier ecka_eg_SessionKDF_AES192 = ecka_eg_SessionKDF.Branch("3");
80+
public static readonly DerObjectIdentifier ecka_eg_SessionKDF_AES256 = ecka_eg_SessionKDF.Branch("4");
81+
82+
/** AES encryption (CBC) and authentication (CMAC)
83+
* OID: 0.4.0.127.0.7.1.x */
84+
//TODO: replace "1" with correct OID
85+
//public static readonly DerObjectIdentifier aes_cbc_cmac = algorithm.Branch("1");
86+
87+
/** AES encryption (CBC) and authentication (CMAC) with 128 bit
88+
* OID: 0.4.0.127.0.7.1.x.y1 */
89+
//TODO: replace "1" with correct OID
90+
//public static readonly DerObjectIdentifier id_aes128_CBC_CMAC = aes_cbc_cmac.Branch("1");
91+
92+
93+
/** AES encryption (CBC) and authentication (CMAC) with 192 bit
94+
* OID: 0.4.0.127.0.7.1.x.y2 */
95+
//TODO: replace "1" with correct OID
96+
//public static readonly DerObjectIdentifier id_aes192_CBC_CMAC = aes_cbc_cmac.Branch("1");
97+
98+
/** AES encryption (CBC) and authentication (CMAC) with 256 bit
99+
* OID: 0.4.0.127.0.7.1.x.y3 */
100+
//TODO: replace "1" with correct OID
101+
//public static readonly DerObjectIdentifier id_aes256_CBC_CMAC = aes_cbc_cmac.Branch("1");
102+
}
103+
}

crypto/src/crypto/IDSA.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
23
using Org.BouncyCastle.Math;
34

45
namespace Org.BouncyCastle.Crypto

crypto/src/crypto/IDsaExt.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
using Org.BouncyCastle.Math;
4+
5+
namespace Org.BouncyCastle.Crypto
6+
{
7+
/// <summary>
8+
/// An "extended" interface for classes implementing DSA-style algorithms, that provides access
9+
/// to the group order.
10+
/// </summary>
11+
public interface IDsaExt
12+
: IDsa
13+
{
14+
/// <summary>The order of the group that the r, s values in signatures belong to.</summary>
15+
BigInteger Order { get; }
16+
}
17+
}

0 commit comments

Comments
 (0)