minor cleanup

This commit is contained in:
Shikhar Bhushan
2010-03-17 23:40:47 +01:00
parent 54ee1a6917
commit 9cbb75084a
2 changed files with 26 additions and 25 deletions

View File

@@ -54,13 +54,13 @@ public abstract class AbstractSignature
this.algorithm = algorithm; this.algorithm = algorithm;
} }
public void init(PublicKey pubkey, PrivateKey prvkey) { public void init(PublicKey publicKey, PrivateKey privateKey) {
try { try {
signature = SecurityUtils.getSignature(algorithm); signature = SecurityUtils.getSignature(algorithm);
if (pubkey != null) if (publicKey != null)
signature.initVerify(pubkey); signature.initVerify(publicKey);
if (prvkey != null) if (privateKey != null)
signature.initSign(prvkey); signature.initSign(privateKey);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
throw new SSHRuntimeException(e); throw new SSHRuntimeException(e);
} }
@@ -81,19 +81,18 @@ public abstract class AbstractSignature
protected byte[] extractSig(byte[] sig) { protected byte[] extractSig(byte[] sig) {
if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0) { if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0) {
int i = 0; int i = 0;
int j; int j = sig[i++] << 24 & 0xff000000
j = sig[i++] << 24 & 0xff000000 // | sig[i++] << 16 & 0x00ff0000
| sig[i++] << 16 & 0x00ff0000 // | sig[i++] << 8 & 0x0000ff00
| sig[i++] << 8 & 0x0000ff00 // | sig[i++] & 0x000000ff;
| sig[i++] & 0x000000ff;
i += j; i += j;
j = sig[i++] << 24 & 0xff000000 // j = sig[i++] << 24 & 0xff000000
| sig[i++] << 16 & 0x00ff0000 // | sig[i++] << 16 & 0x00ff0000
| sig[i++] << 8 & 0x0000ff00 // | sig[i++] << 8 & 0x0000ff00
| sig[i++] & 0x000000ff; | sig[i++] & 0x000000ff;
byte[] tmp = new byte[j]; byte[] newSig = new byte[j];
System.arraycopy(sig, i, tmp, 0, j); System.arraycopy(sig, i, newSig, 0, j);
sig = tmp; sig = newSig;
} }
return sig; return sig;
} }

View File

@@ -72,15 +72,16 @@ public class SignatureDSA
// sig is in ASN.1 // sig is in ASN.1
// SEQUENCE::={ r INTEGER, s INTEGER } // SEQUENCE::={ r INTEGER, s INTEGER }
int len = 0;
int index = 3; int rIndex = 3;
len = sig[index++] & 0xff; int rLen = sig[rIndex++] & 0xff;
byte[] r = new byte[len]; byte[] r = new byte[rLen];
System.arraycopy(sig, index, r, 0, r.length); System.arraycopy(sig, rIndex, r, 0, r.length);
index = index + len + 1;
len = sig[index++] & 0xff; int sIndex = rIndex + rLen + 1;
byte[] s = new byte[len]; int sLen = sig[sIndex++] & 0xff;
System.arraycopy(sig, index, s, 0, s.length); byte[] s = new byte[sLen];
System.arraycopy(sig, sIndex, s, 0, s.length);
byte[] result = new byte[40]; byte[] result = new byte[40];
@@ -91,6 +92,7 @@ public class SignatureDSA
result, result,
r.length > 20 ? 0 : 20 - r.length, r.length > 20 ? 0 : 20 - r.length,
r.length > 20 ? 20 : r.length); r.length > 20 ? 20 : r.length);
System.arraycopy(s, System.arraycopy(s,
s.length > 20 ? 1 : 0, s.length > 20 ? 1 : 0,
result, result,