Skip to content

Commit ed09873

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 9914bc7 + d2357cf commit ed09873

22 files changed

+4165
-212
lines changed

crypto/BouncyCastle.Android.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@
325325
<Compile Include="src\asn1\misc\NetscapeRevocationURL.cs" />
326326
<Compile Include="src\asn1\misc\VerisignCzagExtension.cs" />
327327
<Compile Include="src\asn1\mozilla\PublicKeyAndChallenge.cs" />
328+
<Compile Include="src\asn1\nist\KMACwithSHAKE128_params.cs" />
329+
<Compile Include="src\asn1\nist\KMACwithSHAKE256_params.cs" />
328330
<Compile Include="src\asn1\nist\NISTNamedCurves.cs" />
329331
<Compile Include="src\asn1\nist\NISTObjectIdentifiers.cs" />
330332
<Compile Include="src\asn1\ntt\NTTObjectIdentifiers.cs" />
@@ -748,6 +750,7 @@
748750
<Compile Include="src\crypto\agreement\srp\SRP6VerifierGenerator.cs" />
749751
<Compile Include="src\crypto\digests\Blake2bDigest.cs" />
750752
<Compile Include="src\crypto\digests\Blake2sDigest.cs" />
753+
<Compile Include="src\crypto\digests\CSHAKEDigest.cs" />
751754
<Compile Include="src\crypto\digests\DSTU7564Digest.cs" />
752755
<Compile Include="src\crypto\digests\GeneralDigest.cs" />
753756
<Compile Include="src\crypto\digests\GOST3411Digest.cs" />
@@ -778,6 +781,7 @@
778781
<Compile Include="src\crypto\digests\SkeinEngine.cs" />
779782
<Compile Include="src\crypto\digests\TigerDigest.cs" />
780783
<Compile Include="src\crypto\digests\WhirlpoolDigest.cs" />
784+
<Compile Include="src\crypto\digests\XofUtils.cs" />
781785
<Compile Include="src\crypto\ec\CustomNamedCurves.cs" />
782786
<Compile Include="src\crypto\encodings\ISO9796d1Encoding.cs" />
783787
<Compile Include="src\crypto\encodings\OaepEncoding.cs" />
@@ -886,6 +890,7 @@
886890
<Compile Include="src\crypto\macs\GOST28147Mac.cs" />
887891
<Compile Include="src\crypto\macs\HMac.cs" />
888892
<Compile Include="src\crypto\macs\ISO9797Alg3Mac.cs" />
893+
<Compile Include="src\crypto\macs\KMac.cs" />
889894
<Compile Include="src\crypto\macs\Poly1305.cs" />
890895
<Compile Include="src\crypto\macs\SipHash.cs" />
891896
<Compile Include="src\crypto\macs\SkeinMac.cs" />

crypto/BouncyCastle.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@
319319
<Compile Include="src\asn1\misc\NetscapeRevocationURL.cs" />
320320
<Compile Include="src\asn1\misc\VerisignCzagExtension.cs" />
321321
<Compile Include="src\asn1\mozilla\PublicKeyAndChallenge.cs" />
322+
<Compile Include="src\asn1\nist\KMACwithSHAKE128_params.cs" />
323+
<Compile Include="src\asn1\nist\KMACwithSHAKE256_params.cs" />
322324
<Compile Include="src\asn1\nist\NISTNamedCurves.cs" />
323325
<Compile Include="src\asn1\nist\NISTObjectIdentifiers.cs" />
324326
<Compile Include="src\asn1\ntt\NTTObjectIdentifiers.cs" />
@@ -742,6 +744,7 @@
742744
<Compile Include="src\crypto\agreement\srp\SRP6VerifierGenerator.cs" />
743745
<Compile Include="src\crypto\digests\Blake2bDigest.cs" />
744746
<Compile Include="src\crypto\digests\Blake2sDigest.cs" />
747+
<Compile Include="src\crypto\digests\CSHAKEDigest.cs" />
745748
<Compile Include="src\crypto\digests\DSTU7564Digest.cs" />
746749
<Compile Include="src\crypto\digests\GeneralDigest.cs" />
747750
<Compile Include="src\crypto\digests\GOST3411Digest.cs" />
@@ -772,6 +775,7 @@
772775
<Compile Include="src\crypto\digests\SkeinEngine.cs" />
773776
<Compile Include="src\crypto\digests\TigerDigest.cs" />
774777
<Compile Include="src\crypto\digests\WhirlpoolDigest.cs" />
778+
<Compile Include="src\crypto\digests\XofUtils.cs" />
775779
<Compile Include="src\crypto\ec\CustomNamedCurves.cs" />
776780
<Compile Include="src\crypto\encodings\ISO9796d1Encoding.cs" />
777781
<Compile Include="src\crypto\encodings\OaepEncoding.cs" />
@@ -880,6 +884,7 @@
880884
<Compile Include="src\crypto\macs\GOST28147Mac.cs" />
881885
<Compile Include="src\crypto\macs\HMac.cs" />
882886
<Compile Include="src\crypto\macs\ISO9797Alg3Mac.cs" />
887+
<Compile Include="src\crypto\macs\KMac.cs" />
883888
<Compile Include="src\crypto\macs\Poly1305.cs" />
884889
<Compile Include="src\crypto\macs\SipHash.cs" />
885890
<Compile Include="src\crypto\macs\SkeinMac.cs" />

crypto/BouncyCastle.iOS.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@
320320
<Compile Include="src\asn1\misc\NetscapeRevocationURL.cs" />
321321
<Compile Include="src\asn1\misc\VerisignCzagExtension.cs" />
322322
<Compile Include="src\asn1\mozilla\PublicKeyAndChallenge.cs" />
323+
<Compile Include="src\asn1\nist\KMACwithSHAKE128_params.cs" />
324+
<Compile Include="src\asn1\nist\KMACwithSHAKE256_params.cs" />
323325
<Compile Include="src\asn1\nist\NISTNamedCurves.cs" />
324326
<Compile Include="src\asn1\nist\NISTObjectIdentifiers.cs" />
325327
<Compile Include="src\asn1\ntt\NTTObjectIdentifiers.cs" />
@@ -743,6 +745,7 @@
743745
<Compile Include="src\crypto\agreement\srp\SRP6VerifierGenerator.cs" />
744746
<Compile Include="src\crypto\digests\Blake2bDigest.cs" />
745747
<Compile Include="src\crypto\digests\Blake2sDigest.cs" />
748+
<Compile Include="src\crypto\digests\CSHAKEDigest.cs" />
746749
<Compile Include="src\crypto\digests\DSTU7564Digest.cs" />
747750
<Compile Include="src\crypto\digests\GeneralDigest.cs" />
748751
<Compile Include="src\crypto\digests\GOST3411Digest.cs" />
@@ -773,6 +776,7 @@
773776
<Compile Include="src\crypto\digests\SkeinEngine.cs" />
774777
<Compile Include="src\crypto\digests\TigerDigest.cs" />
775778
<Compile Include="src\crypto\digests\WhirlpoolDigest.cs" />
779+
<Compile Include="src\crypto\digests\XofUtils.cs" />
776780
<Compile Include="src\crypto\ec\CustomNamedCurves.cs" />
777781
<Compile Include="src\crypto\encodings\ISO9796d1Encoding.cs" />
778782
<Compile Include="src\crypto\encodings\OaepEncoding.cs" />
@@ -881,6 +885,7 @@
881885
<Compile Include="src\crypto\macs\GOST28147Mac.cs" />
882886
<Compile Include="src\crypto\macs\HMac.cs" />
883887
<Compile Include="src\crypto\macs\ISO9797Alg3Mac.cs" />
888+
<Compile Include="src\crypto\macs\KMac.cs" />
884889
<Compile Include="src\crypto\macs\Poly1305.cs" />
885890
<Compile Include="src\crypto\macs\SipHash.cs" />
886891
<Compile Include="src\crypto\macs\SkeinMac.cs" />

crypto/crypto.csproj

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,16 @@
14831483
SubType = "Code"
14841484
BuildAction = "Compile"
14851485
/>
1486+
<File
1487+
RelPath = "src\asn1\nist\KMACwithSHAKE128_params.cs"
1488+
SubType = "Code"
1489+
BuildAction = "Compile"
1490+
/>
1491+
<File
1492+
RelPath = "src\asn1\nist\KMACwithSHAKE256_params.cs"
1493+
SubType = "Code"
1494+
BuildAction = "Compile"
1495+
/>
14861496
<File
14871497
RelPath = "src\asn1\nist\NISTNamedCurves.cs"
14881498
SubType = "Code"
@@ -3563,6 +3573,11 @@
35633573
SubType = "Code"
35643574
BuildAction = "Compile"
35653575
/>
3576+
<File
3577+
RelPath = "src\crypto\digests\CSHAKEDigest.cs"
3578+
SubType = "Code"
3579+
BuildAction = "Compile"
3580+
/>
35663581
<File
35673582
RelPath = "src\crypto\digests\DSTU7564Digest.cs"
35683583
SubType = "Code"
@@ -3718,6 +3733,11 @@
37183733
SubType = "Code"
37193734
BuildAction = "Compile"
37203735
/>
3736+
<File
3737+
RelPath = "src\crypto\digests\XofUtils.cs"
3738+
SubType = "Code"
3739+
BuildAction = "Compile"
3740+
/>
37213741
<File
37223742
RelPath = "src\crypto\ec\CustomNamedCurves.cs"
37233743
SubType = "Code"
@@ -4279,22 +4299,27 @@
42794299
BuildAction = "Compile"
42804300
/>
42814301
<File
4282-
RelPath = "src\crypto\macs\Poly1305.cs"
4302+
RelPath = "src\crypto\macs\ISO9797Alg3Mac.cs"
42834303
SubType = "Code"
42844304
BuildAction = "Compile"
42854305
/>
42864306
<File
4287-
RelPath = "src\crypto\macs\SipHash.cs"
4307+
RelPath = "src\crypto\macs\KMac.cs"
42884308
SubType = "Code"
42894309
BuildAction = "Compile"
42904310
/>
42914311
<File
4292-
RelPath = "src\crypto\macs\SkeinMac.cs"
4312+
RelPath = "src\crypto\macs\Poly1305.cs"
42934313
SubType = "Code"
42944314
BuildAction = "Compile"
42954315
/>
42964316
<File
4297-
RelPath = "src\crypto\macs\ISO9797Alg3Mac.cs"
4317+
RelPath = "src\crypto\macs\SipHash.cs"
4318+
SubType = "Code"
4319+
BuildAction = "Compile"
4320+
/>
4321+
<File
4322+
RelPath = "src\crypto\macs\SkeinMac.cs"
42984323
SubType = "Code"
42994324
BuildAction = "Compile"
43004325
/>
@@ -8249,6 +8274,10 @@
82498274
RelPath = "test\data\cms\sigs\SignedMSPkcs7.sig"
82508275
BuildAction = "EmbeddedResource"
82518276
/>
8277+
<File
8278+
RelPath = "test\data\crypto\nist_ecc.txt"
8279+
BuildAction = "EmbeddedResource"
8280+
/>
82528281
<File
82538282
RelPath = "test\data\crypto\SHA3TestVectors.txt"
82548283
BuildAction = "EmbeddedResource"
@@ -11762,6 +11791,11 @@
1176211791
SubType = "Code"
1176311792
BuildAction = "Compile"
1176411793
/>
11794+
<File
11795+
RelPath = "test\src\asn1\test\KMacParamsTest.cs"
11796+
SubType = "Code"
11797+
BuildAction = "Compile"
11798+
/>
1176511799
<File
1176611800
RelPath = "test\src\asn1\test\LDSSecurityObjectUnitTest.cs"
1176711801
SubType = "Code"
@@ -12217,6 +12251,11 @@
1221712251
SubType = "Code"
1221812252
BuildAction = "Compile"
1221912253
/>
12254+
<File
12255+
RelPath = "test\src\crypto\test\CSHAKETest.cs"
12256+
SubType = "Code"
12257+
BuildAction = "Compile"
12258+
/>
1222012259
<File
1222112260
RelPath = "test\src\crypto\test\CTSTest.cs"
1222212261
SubType = "Code"
@@ -12342,6 +12381,16 @@
1234212381
SubType = "Code"
1234312382
BuildAction = "Compile"
1234412383
/>
12384+
<File
12385+
RelPath = "test\src\crypto\test\KMACTest.cs"
12386+
SubType = "Code"
12387+
BuildAction = "Compile"
12388+
/>
12389+
<File
12390+
RelPath = "test\src\crypto\test\NistEccTest.cs"
12391+
SubType = "Code"
12392+
BuildAction = "Compile"
12393+
/>
1234512394
<File
1234612395
RelPath = "test\src\crypto\test\OCBTest.cs"
1234712396
SubType = "Code"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using Org.BouncyCastle.Utilities;
2+
using System;
3+
4+
5+
namespace Org.BouncyCastle.Asn1.Nist
6+
{
7+
/// <summary>
8+
/// KMACwithSHAKE128-params ::= SEQUENCE {
9+
/// kMACOutputLength INTEGER DEFAULT 256, -- Output length in bits
10+
/// customizationString OCTET STRING DEFAULT ''H
11+
/// }
12+
/// </summary>
13+
public class KMacWithShake128Params : Asn1Encodable
14+
{
15+
private static readonly byte[] EMPTY_STRING = new byte[0];
16+
private static readonly int DEF_LENGTH = 256;
17+
18+
private readonly int outputLength;
19+
private readonly byte[] customizationString;
20+
21+
public KMacWithShake128Params(int outputLength)
22+
{
23+
this.outputLength = outputLength;
24+
this.customizationString = EMPTY_STRING;
25+
}
26+
27+
public KMacWithShake128Params(int outputLength, byte[] customizationString)
28+
{
29+
this.outputLength = outputLength;
30+
this.customizationString = Arrays.Clone(customizationString);
31+
}
32+
33+
public static KMacWithShake128Params GetInstance(object o)
34+
{
35+
if (o is KMacWithShake128Params)
36+
{
37+
return (KMacWithShake128Params)o;
38+
}
39+
else if (o != null)
40+
{
41+
return new KMacWithShake128Params(Asn1Sequence.GetInstance(o));
42+
}
43+
44+
return null;
45+
}
46+
47+
private KMacWithShake128Params(Asn1Sequence seq)
48+
{
49+
if (seq.Count > 2)
50+
throw new InvalidOperationException("sequence size greater than 2");
51+
52+
if (seq.Count == 2)
53+
{
54+
this.outputLength = DerInteger.GetInstance(seq[0]).IntValueExact;
55+
this.customizationString = Arrays.Clone(Asn1OctetString.GetInstance(seq[1]).GetOctets());
56+
}
57+
else if (seq.Count == 1)
58+
{
59+
if (seq[0] is DerInteger)
60+
{
61+
this.outputLength = DerInteger.GetInstance(seq[0]).IntValueExact;
62+
this.customizationString = EMPTY_STRING;
63+
}
64+
else
65+
{
66+
this.outputLength = DEF_LENGTH;
67+
this.customizationString = Arrays.Clone(Asn1OctetString.GetInstance(seq[0]).GetOctets());
68+
}
69+
}
70+
else
71+
{
72+
this.outputLength = DEF_LENGTH;
73+
this.customizationString = EMPTY_STRING;
74+
}
75+
}
76+
77+
public int OutputLength
78+
{
79+
get { return outputLength; }
80+
}
81+
82+
public byte[] CustomizationString
83+
{
84+
get { return Arrays.Clone(customizationString); }
85+
}
86+
87+
public override Asn1Object ToAsn1Object()
88+
{
89+
Asn1EncodableVector v = new Asn1EncodableVector();
90+
if (outputLength != DEF_LENGTH)
91+
{
92+
v.Add(new DerInteger(outputLength));
93+
}
94+
95+
if (customizationString.Length != 0)
96+
{
97+
v.Add(new DerOctetString(CustomizationString));
98+
}
99+
100+
return new DerSequence(v);
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)