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

View File

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