Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Jan 20, 2019
2 parents a6cb039 + aa29930 commit 9480083
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 93 deletions.
14 changes: 10 additions & 4 deletions crypto/src/cms/KeyTransRecipientInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@ internal KeyTransRecipientInformation(
}

private string GetExchangeEncryptionAlgorithmName(
DerObjectIdentifier oid)
AlgorithmIdentifier algo)
{
if (Asn1Pkcs.PkcsObjectIdentifiers.RsaEncryption.Equals(oid))
DerObjectIdentifier oid = algo.Algorithm;

if (Asn1Pkcs.PkcsObjectIdentifiers.RsaEncryption.Equals(oid))
{
return "RSA//PKCS1Padding";
}
} else if (Asn1Pkcs.PkcsObjectIdentifiers.IdRsaesOaep.Equals(oid))
{
Asn1Pkcs.RsaesOaepParameters rsaParams = Asn1Pkcs.RsaesOaepParameters.GetInstance(algo.Parameters);
return "RSA//OAEPWITH"+DigestUtilities.GetAlgorithmName(rsaParams.HashAlgorithm.Algorithm)+"ANDMGF1Padding";
}

return oid.Id;
}

internal KeyParameter UnwrapKey(ICipherParameters key)
{
byte[] encryptedKey = info.EncryptedKey.GetOctets();
string keyExchangeAlgorithm = GetExchangeEncryptionAlgorithmName(keyEncAlg.Algorithm);
string keyExchangeAlgorithm = GetExchangeEncryptionAlgorithmName(keyEncAlg);

try
{
Expand Down
6 changes: 3 additions & 3 deletions crypto/src/crypto/digests/GOST3411_2012Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Org.BouncyCastle.Crypto.Digests
{
public abstract class GOST3411_2012Digest:IDigest,IMemoable
public abstract class Gost3411_2012Digest:IDigest,IMemoable
{
private readonly byte[] IV = new byte[64];
private readonly byte[] N = new byte[64];
Expand All @@ -19,7 +19,7 @@ public abstract class GOST3411_2012Digest:IDigest,IMemoable

private int bOff = 64;

protected GOST3411_2012Digest(byte[] IV)
protected Gost3411_2012Digest(byte[] IV)
{
System.Array.Copy(IV,this.IV,64);
System.Array.Copy(IV, h, 64);
Expand Down Expand Up @@ -79,7 +79,7 @@ public void Reset()

public void Reset(IMemoable other)
{
GOST3411_2012Digest o = (GOST3411_2012Digest)other;
Gost3411_2012Digest o = (Gost3411_2012Digest)other;

System.Array.Copy(o.IV, 0, this.IV, 0, 64);
System.Array.Copy(o.N, 0, this.N, 0, 64);
Expand Down
8 changes: 4 additions & 4 deletions crypto/src/crypto/digests/GOST3411_2012_256Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Org.BouncyCastle.Crypto.Digests
{
public class GOST3411_2012_256Digest : GOST3411_2012Digest
public class Gost3411_2012_256Digest : Gost3411_2012Digest
{
private readonly static byte[] IV = {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
Expand All @@ -21,12 +21,12 @@ public override string AlgorithmName
get { return "GOST3411-2012-256"; }
}

public GOST3411_2012_256Digest() : base(IV)
public Gost3411_2012_256Digest() : base(IV)
{

}

public GOST3411_2012_256Digest(GOST3411_2012_256Digest other) : base(IV)
public Gost3411_2012_256Digest(Gost3411_2012_256Digest other) : base(IV)
{
Reset(other);
}
Expand All @@ -48,7 +48,7 @@ public override int DoFinal(byte[] output, int outOff)

public override IMemoable Copy()
{
return new GOST3411_2012_256Digest(this);
return new Gost3411_2012_256Digest(this);
}
}
}
8 changes: 4 additions & 4 deletions crypto/src/crypto/digests/GOST3411_2012_512Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Org.BouncyCastle.Crypto.Digests
{
public class GOST3411_2012_512Digest:GOST3411_2012Digest
public class Gost3411_2012_512Digest:Gost3411_2012Digest
{
private readonly static byte[] IV = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -21,11 +21,11 @@ public override string AlgorithmName
get { return "GOST3411-2012-512"; }
}

public GOST3411_2012_512Digest():base(IV)
public Gost3411_2012_512Digest():base(IV)
{
}

public GOST3411_2012_512Digest(GOST3411_2012_512Digest other) : base(IV)
public Gost3411_2012_512Digest(Gost3411_2012_512Digest other) : base(IV)
{
Reset(other);
}
Expand All @@ -37,7 +37,7 @@ public override int GetDigestSize()

public override IMemoable Copy()
{
return new GOST3411_2012_512Digest(this);
return new Gost3411_2012_512Digest(this);
}
}
}
15 changes: 8 additions & 7 deletions crypto/src/crypto/operators/Asn1KeyWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Asn1.Oiw;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Security;

namespace Org.BouncyCastle.Crypto.Operators
{
Expand Down Expand Up @@ -106,33 +107,33 @@ internal class RsaOaepWrapper : IKeyWrapper, IKeyUnwrapper
{
internal static object Rsa_Sha1_Oaep(bool forWrapping, ICipherParameters parameters)
{
return new RsaOaepWrapper(forWrapping, parameters, OiwObjectIdentifiers.IdSha1, new Sha1Digest());
return new RsaOaepWrapper(forWrapping, parameters, OiwObjectIdentifiers.IdSha1);
}

internal static object Rsa_Sha224_Oaep(bool forWrapping, ICipherParameters parameters)
{
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha224, new Sha224Digest());
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha224);
}

internal static object Rsa_Sha256_Oaep(bool forWrapping, ICipherParameters parameters)
{
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha256, new Sha256Digest());
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha256);
}

internal static object Rsa_Sha384_Oaep(bool forWrapping, ICipherParameters parameters)
{
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha384, new Sha384Digest());
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha384);
}

internal static object Rsa_Sha512_Oaep(bool forWrapping, ICipherParameters parameters)
{
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha512, new Sha512Digest());
return new RsaOaepWrapper(forWrapping, parameters, NistObjectIdentifiers.IdSha512);
}

private readonly AlgorithmIdentifier algId;
private readonly IAsymmetricBlockCipher engine;

public RsaOaepWrapper(bool forWrapping, ICipherParameters parameters, DerObjectIdentifier digestOid, IDigest digest)
public RsaOaepWrapper(bool forWrapping, ICipherParameters parameters, DerObjectIdentifier digestOid)
{
AlgorithmIdentifier digestAlgId = new AlgorithmIdentifier(digestOid, DerNull.Instance);

Expand All @@ -142,7 +143,7 @@ public RsaOaepWrapper(bool forWrapping, ICipherParameters parameters, DerObjectI
digestAlgId,
new AlgorithmIdentifier(PkcsObjectIdentifiers.IdMgf1, digestAlgId),
RsaesOaepParameters.DefaultPSourceAlgorithm));
this.engine = new OaepEncoding(new RsaBlindedEngine());
this.engine = new OaepEncoding(new RsaBlindedEngine(), DigestUtilities.GetDigest(digestOid) );
this.engine.Init(forWrapping, parameters);
}

Expand Down
6 changes: 3 additions & 3 deletions crypto/src/crypto/parameters/ECGOST3410Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
public class ECGOST3410Parameters : ECNamedDomainParameters
public class ECGost3410Parameters : ECNamedDomainParameters
{

private readonly DerObjectIdentifier _publicKeyParamSet;
Expand All @@ -26,7 +26,7 @@ public DerObjectIdentifier EncryptionParamSet
get { return _encryptionParamSet; }
}

public ECGOST3410Parameters(
public ECGost3410Parameters(
ECNamedDomainParameters dp,
DerObjectIdentifier publicKeyParamSet,
DerObjectIdentifier digestParamSet,
Expand All @@ -38,7 +38,7 @@ public ECGOST3410Parameters(
}


public ECGOST3410Parameters(ECDomainParameters dp, DerObjectIdentifier publicKeyParamSet,
public ECGost3410Parameters(ECDomainParameters dp, DerObjectIdentifier publicKeyParamSet,
DerObjectIdentifier digestParamSet,
DerObjectIdentifier encryptionParamSet) : base(publicKeyParamSet, dp.Curve, dp.G, dp.N, dp.H, dp.GetSeed())
{
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/crypto/signers/EcGost3410_2012Signer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Org.BouncyCastle.Crypto.Signers
{
public class ECGOST3410_2012Signer : IDsaExt
public class ECGost3410_2012Signer : IDsaExt
{
private ECKeyParameters key;
private SecureRandom secureRandom;
Expand Down Expand Up @@ -150,4 +150,4 @@ protected virtual ECMultiplier CreateBasePointMultiplier()
return new FixedPointCombMultiplier();
}
}
}
}
4 changes: 2 additions & 2 deletions crypto/src/pkcs/PrivateKeyInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public static PrivateKeyInfo CreatePrivateKeyInfo(AsymmetricKeyParameter private
ECDomainParameters dp = priv.Parameters;

// ECGOST3410
if (dp is ECGOST3410Parameters)
if (dp is ECGost3410Parameters)
{
ECGOST3410Parameters domainParameters = (ECGOST3410Parameters) dp;
ECGost3410Parameters domainParameters = (ECGost3410Parameters) dp;

Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters(
(domainParameters).PublicKeyParamSet,
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/security/DigestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ public static IDigest GetDigest(
case DigestAlgorithm.DSTU7564_384: return new Dstu7564Digest(384);
case DigestAlgorithm.DSTU7564_512: return new Dstu7564Digest(512);
case DigestAlgorithm.GOST3411: return new Gost3411Digest();
case DigestAlgorithm.GOST3411_2012_256: return new GOST3411_2012_256Digest();
case DigestAlgorithm.GOST3411_2012_512: return new GOST3411_2012_512Digest();
case DigestAlgorithm.GOST3411_2012_256: return new Gost3411_2012_256Digest();
case DigestAlgorithm.GOST3411_2012_512: return new Gost3411_2012_512Digest();
case DigestAlgorithm.KECCAK_224: return new KeccakDigest(224);
case DigestAlgorithm.KECCAK_256: return new KeccakDigest(256);
case DigestAlgorithm.KECCAK_288: return new KeccakDigest(288);
Expand Down
12 changes: 6 additions & 6 deletions crypto/src/security/PrivateKeyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ public static AsymmetricKeyParameter CreateKey(
|| algOid.Equals(RosstandartObjectIdentifiers.id_tc26_gost_3410_12_256))
{
Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(keyInfo.PrivateKeyAlgorithm.Parameters);
ECGOST3410Parameters ecSpec = null;
ECGost3410Parameters ecSpec = null;
BigInteger d = null;
Asn1Object p = keyInfo.PrivateKeyAlgorithm.Parameters.ToAsn1Object();
if (p is Asn1Sequence && (Asn1Sequence.GetInstance(p).Count == 2 || Asn1Sequence.GetInstance(p).Count == 3))
{

ECDomainParameters ecP = ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet);

ecSpec = new ECGOST3410Parameters(
ecSpec = new ECGost3410Parameters(
new ECNamedDomainParameters(
gostParams.PublicKeyParamSet, ecP),
gostParams.PublicKeyParamSet,
Expand Down Expand Up @@ -237,7 +237,7 @@ public static AsymmetricKeyParameter CreateKey(
if (ecP == null)
{
ECDomainParameters gParam = ECGost3410NamedCurves.GetByOid(oid);
ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters(
ecSpec = new ECGost3410Parameters(new ECNamedDomainParameters(
oid,
gParam.Curve,
gParam.G,
Expand All @@ -248,7 +248,7 @@ public static AsymmetricKeyParameter CreateKey(
}
else
{
ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters(
ecSpec = new ECGost3410Parameters(new ECNamedDomainParameters(
oid,
ecP.Curve,
ecP.G,
Expand All @@ -265,7 +265,7 @@ public static AsymmetricKeyParameter CreateKey(
else
{
X9ECParameters ecP = X9ECParameters.GetInstance(parameters.Parameters);
ecSpec = new ECGOST3410Parameters(new ECNamedDomainParameters(
ecSpec = new ECGost3410Parameters(new ECNamedDomainParameters(
algOid,
ecP.Curve,
ecP.G,
Expand All @@ -292,7 +292,7 @@ public static AsymmetricKeyParameter CreateKey(

return new ECPrivateKeyParameters(
d,
new ECGOST3410Parameters(
new ECGost3410Parameters(
ecSpec,
gostParams.PublicKeyParamSet,
gostParams.DigestParamSet,
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/security/PublicKeyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ public static AsymmetricKeyParameter CreateKey(

Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(keyInfo.AlgorithmID.Parameters);

ECGOST3410Parameters ecDomainParameters =
new ECGOST3410Parameters(
ECGost3410Parameters ecDomainParameters =
new ECGost3410Parameters(
new ECNamedDomainParameters(gostParams.PublicKeyParamSet, ECGost3410NamedCurves.GetByOid(gostParams.PublicKeyParamSet)),
gostParams.PublicKeyParamSet,
gostParams.DigestParamSet,
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/x509/SubjectPublicKeyInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public static SubjectPublicKeyInfo CreateSubjectPublicKeyInfo(
ECPublicKeyParameters _key = (ECPublicKeyParameters) publicKey;


if (_key.Parameters is ECGOST3410Parameters)
if (_key.Parameters is ECGost3410Parameters)
{
ECGOST3410Parameters gostParams = (ECGOST3410Parameters)_key.Parameters;
ECGost3410Parameters gostParams = (ECGost3410Parameters)_key.Parameters;

BigInteger bX = _key.Q.AffineXCoord.ToBigInteger();
BigInteger bY = _key.Q.AffineYCoord.ToBigInteger();
Expand Down
7 changes: 7 additions & 0 deletions crypto/test/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="src\cms\test\Rfc4134Test.cs" />
<Compile Include="src\cms\test\SignedDataStreamTest.cs" />
<Compile Include="src\cms\test\SignedDataTest.cs" />
<Compile Include="src\crmf\test\CrmfTest.cs" />
<Compile Include="src\crypto\examples\DESExample.cs" />
<Compile Include="src\crypto\io\test\AllTests.cs" />
<Compile Include="src\crypto\io\test\CipherStreamTest.cs" />
Expand Down Expand Up @@ -185,11 +186,13 @@
<Compile Include="src\crypto\test\EAXTest.cs" />
<Compile Include="src\crypto\test\ECDHKEKGeneratorTest.cs" />
<Compile Include="src\crypto\test\ECGOST3410Test.cs" />
<Compile Include="src\crypto\test\ECGOST3410_2012Test.cs" />
<Compile Include="src\crypto\test\ECIESTest.cs" />
<Compile Include="src\crypto\test\ECNRTest.cs" />
<Compile Include="src\crypto\test\ECTest.cs" />
<Compile Include="src\crypto\test\Ed25519Test.cs" />
<Compile Include="src\crypto\test\Ed448Test.cs" />
<Compile Include="src\crypto\test\EGOST3410_2012SignatureTest.cs" />
<Compile Include="src\crypto\test\ElGamalTest.cs" />
<Compile Include="src\crypto\test\EqualsHashCodeTest.cs" />
<Compile Include="src\crypto\test\GCMTest.cs" />
Expand Down Expand Up @@ -386,6 +389,7 @@
<Compile Include="src\pkcs\test\EncryptedPrivateKeyInfoTest.cs" />
<Compile Include="src\pkcs\test\PKCS10Test.cs" />
<Compile Include="src\pkcs\test\PKCS12StoreTest.cs" />
<Compile Include="src\ProtectedMessageTest.cs" />
<Compile Include="src\security\test\SecureRandomTest.cs" />
<Compile Include="src\security\test\TestDigestUtil.cs" />
<Compile Include="src\security\test\TestDotNetUtil.cs" />
Expand Down Expand Up @@ -1317,4 +1321,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\NewFolder1\" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions crypto/test/src/crmf/test/CrmfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void TestBasicMessageWithArchiveControl()
certificateRequestMessageBuilder.SetPublicKey(publicKeyInfo);

certificateRequestMessageBuilder.AddControl(
new PKIArchiveControlBuilder(privateInfo, new GeneralName(new X509Name("CN=Test")))
new PkiArchiveControlBuilder(privateInfo, new GeneralName(new X509Name("CN=Test")))
.AddRecipientGenerator(new CmsKeyTransRecipientInfoGenerator(cert, new Asn1KeyWrapper("RSA/None/OAEPwithSHA256andMGF1Padding", cert)))
.Build(new CmsContentEncryptorBuilder(NistObjectIdentifiers.IdAes128Cbc).Build())
);
Expand All @@ -126,7 +126,7 @@ public void TestBasicMessageWithArchiveControl()

checkCertReqMsgWithArchiveControl(rsaKeyPair,msg);
checkCertReqMsgWithArchiveControl(rsaKeyPair, new CertificateRequestMessage(msg.GetEncoded()));

}

[Test]
Expand Down Expand Up @@ -172,13 +172,13 @@ private void checkCertReqMsgWithArchiveControl(AsymmetricCipherKeyPair kp, Certi
KeyTransRecipientInformation info = (KeyTransRecipientInformation)collection[0];

EncKeyWithID encKeyWithId = EncKeyWithID.GetInstance(info.GetContent(kp.Private));



IsTrue(encKeyWithId.HasIdentifier);
IsTrue(!encKeyWithId.IsIdentifierUtf8String); // GeneralName at this point.


IsTrue("Name", X509Name.GetInstance(GeneralName.GetInstance(encKeyWithId.Identifier).Name).Equivalent(new X509Name("CN=Test")));

PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(kp.Private);
IsTrue("Private Key", Arrays.AreEqual(privateKeyInfo.GetEncoded(), encKeyWithId.PrivateKey.GetEncoded()));

Expand Down
Loading

0 comments on commit 9480083

Please sign in to comment.