Skip to content

Commit

Permalink
Update to BouncyCastle 1.64
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten Ohme committed May 30, 2020
1 parent 4909906 commit 2b69895
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,20 @@
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
<version>1.46</version>
<artifactId>bcprov-debug-jdk15on</artifactId>
<version>1.64</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.bouncycastle</groupId>-->
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
<!-- <version>1.64</version>-->
<!-- </dependency>-->
<dependency>
<groupId>oracle.javacard</groupId>
<artifactId>api_classic</artifactId>
<version>${jcApiVersion}</version>
<systemPath>${env.JC_CLASSIC_HOME}/lib/api_classic-${jcApiVersion}.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
Expand Down Expand Up @@ -180,7 +192,7 @@
<artifactId>api_classic</artifactId>
<version>${jcApiVersion}</version>
<packaging>jar</packaging>
<file>${env.JC_CLASSIC_HOME}/lib/api_classic.jar</file>
<file>${env.JC_CLASSIC_HOME}/lib/api_classic-${jcApiVersion}.jar</file>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public AsymmetricSignatureImpl(byte algorithm) {
engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest());
break;
case ALG_RSA_SHA_ISO9796_MR:
engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest());
engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest(), true);
isRecovery = true;
break;
case ALG_RSA_SHA_PKCS1:
Expand Down Expand Up @@ -254,18 +254,7 @@ public short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff,
try {
sig = engine.generateSignature();
Util.arrayCopyNonAtomic(sig, (short) 0, sigBuff, sigOffset, (short) sig.length);
// there is no direct way to obtain encoded message length
int keyBits = key.getSize();
Field messageLengthField = engine.getClass().getDeclaredField("messageLength");
messageLengthField.setAccessible(true);
int messageLength = messageLengthField.getInt(engine);
int digSize = 20;
int x = (digSize + messageLength) * 8 + 16 + 4 - keyBits;
int mR = messageLength;
if (x > 0) {
mR = messageLength - ((x + 7) / 8);
}
recMsgLen[recMsgLenOffset] = (short) mR;
recMsgLen[recMsgLenOffset] = (short) ((SignerWithRecovery)engine).getRecoveredMessage().length;
return (short) sig.length;
} catch (org.bouncycastle.crypto.CryptoException ex) {
CryptoException.throwIt(CryptoException.ILLEGAL_USE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ final void setDomainParameters(ECDomainParameters parameters) {
a.setBigInteger(parameters.getCurve().getA().toBigInteger());
b.setBigInteger(parameters.getCurve().getB().toBigInteger());
// generator
g.setBytes(parameters.getG().getEncoded());
g.setBytes(parameters.getG().getEncoded(false));
// order
r.setBigInteger(parameters.getN());
// cofactor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ECPublicKeyImpl(ECPublicKeyParameters params) {
}

public void setParameters(CipherParameters params){
w.setBytes(((ECPublicKeyParameters)params).getQ().getEncoded());
w.setBytes(((ECPublicKeyParameters)params).getQ().getEncoded(false));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,15 @@ public void init(CipherParameters privateKey) {
this.key = (ECPrivateKeyParameters)privateKey;
}

@Override
public int getFieldSize() {
return (key.getParameters().getCurve().getFieldSize() + 7) / 8;
}

public BigInteger calculateAgreement(CipherParameters publicKey) {
ECPublicKeyParameters pub = (ECPublicKeyParameters)publicKey;
ECPoint result = pub.getQ().multiply(this.key.getD());
return new BigInteger(1, result.getEncoded());
return new BigInteger(1, result.getEncoded(false));
}
}
}

0 comments on commit 2b69895

Please sign in to comment.