Skip to content

Commit 3661f95

Browse files
committed
GCM updates from bc-java
1 parent 08b8d05 commit 3661f95

15 files changed

+515
-255
lines changed

crypto/BouncyCastle.Android.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@
912912
<Compile Include="src\crypto\modes\gcm\IGcmExponentiator.cs" />
913913
<Compile Include="src\crypto\modes\gcm\IGcmMultiplier.cs" />
914914
<Compile Include="src\crypto\modes\gcm\Tables1kGcmExponentiator.cs" />
915+
<Compile Include="src\crypto\modes\gcm\Tables4kGcmMultiplier.cs" />
915916
<Compile Include="src\crypto\modes\gcm\Tables64kGcmMultiplier.cs" />
916917
<Compile Include="src\crypto\modes\gcm\Tables8kGcmMultiplier.cs" />
917918
<Compile Include="src\crypto\operators\Asn1CipherBuilder.cs" />

crypto/BouncyCastle.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@
906906
<Compile Include="src\crypto\modes\gcm\IGcmExponentiator.cs" />
907907
<Compile Include="src\crypto\modes\gcm\IGcmMultiplier.cs" />
908908
<Compile Include="src\crypto\modes\gcm\Tables1kGcmExponentiator.cs" />
909+
<Compile Include="src\crypto\modes\gcm\Tables4kGcmMultiplier.cs" />
909910
<Compile Include="src\crypto\modes\gcm\Tables64kGcmMultiplier.cs" />
910911
<Compile Include="src\crypto\modes\gcm\Tables8kGcmMultiplier.cs" />
911912
<Compile Include="src\crypto\operators\Asn1CipherBuilder.cs" />

crypto/BouncyCastle.iOS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@
907907
<Compile Include="src\crypto\modes\gcm\IGcmExponentiator.cs" />
908908
<Compile Include="src\crypto\modes\gcm\IGcmMultiplier.cs" />
909909
<Compile Include="src\crypto\modes\gcm\Tables1kGcmExponentiator.cs" />
910+
<Compile Include="src\crypto\modes\gcm\Tables4kGcmMultiplier.cs" />
910911
<Compile Include="src\crypto\modes\gcm\Tables64kGcmMultiplier.cs" />
911912
<Compile Include="src\crypto\modes\gcm\Tables8kGcmMultiplier.cs" />
912913
<Compile Include="src\crypto\operators\Asn1CipherBuilder.cs" />

crypto/crypto.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,11 @@
44134413
SubType = "Code"
44144414
BuildAction = "Compile"
44154415
/>
4416+
<File
4417+
RelPath = "src\crypto\modes\gcm\Tables4kGcmMultiplier.cs"
4418+
SubType = "Code"
4419+
BuildAction = "Compile"
4420+
/>
44164421
<File
44174422
RelPath = "src\crypto\modes\gcm\Tables64kGcmMultiplier.cs"
44184423
SubType = "Code"

crypto/src/crypto/modes/GCMBlockCipher.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public GcmBlockCipher(
5959

6060
if (m == null)
6161
{
62-
// TODO Consider a static property specifying default multiplier
63-
m = new Tables8kGcmMultiplier();
62+
m = new Tables4kGcmMultiplier();
6463
}
6564

6665
this.cipher = c;
@@ -444,7 +443,7 @@ public int DoFinal(byte[] output, int outOff)
444443
byte[] H_c = new byte[16];
445444
if (exp == null)
446445
{
447-
exp = new Tables1kGcmExponentiator();
446+
exp = new BasicGcmExponentiator();
448447
exp.Init(H);
449448
}
450449
exp.ExponentiateX(c, H_c);

crypto/src/crypto/modes/gcm/BasicGcmExponentiator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ namespace Org.BouncyCastle.Crypto.Modes.Gcm
77
public class BasicGcmExponentiator
88
: IGcmExponentiator
99
{
10-
private uint[] x;
10+
private ulong[] x;
1111

1212
public void Init(byte[] x)
1313
{
14-
this.x = GcmUtilities.AsUints(x);
14+
this.x = GcmUtilities.AsUlongs(x);
1515
}
1616

1717
public void ExponentiateX(long pow, byte[] output)
1818
{
1919
// Initial value is little-endian 1
20-
uint[] y = GcmUtilities.OneAsUints();
20+
ulong[] y = GcmUtilities.OneAsUlongs();
2121

2222
if (pow > 0)
2323
{
24-
uint[] powX = Arrays.Clone(x);
24+
ulong[] powX = Arrays.Clone(x);
2525
do
2626
{
2727
if ((pow & 1L) != 0)
2828
{
2929
GcmUtilities.Multiply(y, powX);
3030
}
31-
GcmUtilities.Multiply(powX, powX);
31+
GcmUtilities.Square(powX, powX);
3232
pow >>= 1;
3333
}
3434
while (pow > 0);

crypto/src/crypto/modes/gcm/BasicGcmMultiplier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace Org.BouncyCastle.Crypto.Modes.Gcm
55
public class BasicGcmMultiplier
66
: IGcmMultiplier
77
{
8-
private uint[] H;
8+
private ulong[] H;
99

1010
public void Init(byte[] H)
1111
{
12-
this.H = GcmUtilities.AsUints(H);
12+
this.H = GcmUtilities.AsUlongs(H);
1313
}
1414

1515
public void MultiplyH(byte[] x)
1616
{
17-
uint[] t = GcmUtilities.AsUints(x);
17+
ulong[] t = GcmUtilities.AsUlongs(x);
1818
GcmUtilities.Multiply(t, H);
1919
GcmUtilities.AsBytes(t, x);
2020
}

0 commit comments

Comments
 (0)