diff options
author | Kenny Root <kenny@the-b.org> | 2013-04-11 21:01:32 -0700 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2013-04-11 21:01:32 -0700 |
commit | d8e49ec3f297f9ba0991762eb2cddbc00ed634d2 (patch) | |
tree | aac59c707c980e90202241c7a9c306ab9d278a1c /src/com/trilead/ssh2/crypto/digest | |
parent | 847af5046fb7d2dbcc668cecf81f1726b7c48bd9 (diff) | |
download | connectbot-d8e49ec3f297f9ba0991762eb2cddbc00ed634d2.tar.gz connectbot-d8e49ec3f297f9ba0991762eb2cddbc00ed634d2.tar.bz2 connectbot-d8e49ec3f297f9ba0991762eb2cddbc00ed634d2.zip |
Fix line endings
Diffstat (limited to 'src/com/trilead/ssh2/crypto/digest')
-rw-r--r-- | src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java | 198 | ||||
-rw-r--r-- | src/com/trilead/ssh2/crypto/digest/MAC.java | 236 |
2 files changed, 217 insertions, 217 deletions
diff --git a/src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java b/src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java index 30ffe0d..9127d4e 100644 --- a/src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java +++ b/src/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java @@ -1,100 +1,100 @@ -
-package com.trilead.ssh2.crypto.digest;
-
-import java.math.BigInteger;
-import java.security.DigestException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-/**
- * HashForSSH2Types.
- *
- * @author Christian Plattner, plattner@trilead.com
- * @version $Id: HashForSSH2Types.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
- */
-public class HashForSSH2Types
-{
- MessageDigest md;
-
- public HashForSSH2Types(MessageDigest md)
- {
- this.md = md;
- }
-
- public HashForSSH2Types(String type)
- {
- try {
- if ("SHA1".equals(type) || "MD5".equals(type)) {
- md = MessageDigest.getInstance(type);
- } else {
- throw new IllegalArgumentException("Unknown algorithm " + type);
- }
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException("Unsupported algorithm " + type);
- }
- }
-
- public void updateByte(byte b)
- {
- /* HACK - to test it with J2ME */
- byte[] tmp = new byte[1];
- tmp[0] = b;
- md.update(tmp);
- }
-
- public void updateBytes(byte[] b)
- {
- md.update(b);
- }
-
- public void updateUINT32(int v)
- {
- md.update((byte) (v >> 24));
- md.update((byte) (v >> 16));
- md.update((byte) (v >> 8));
- md.update((byte) (v));
- }
-
- public void updateByteString(byte[] b)
- {
- updateUINT32(b.length);
- updateBytes(b);
- }
-
- public void updateBigInt(BigInteger b)
- {
- updateByteString(b.toByteArray());
- }
-
- public void reset()
- {
- md.reset();
- }
-
- public int getDigestLength()
- {
- return md.getDigestLength();
- }
-
- public byte[] getDigest()
- {
- byte[] tmp = new byte[md.getDigestLength()];
- getDigest(tmp);
- return tmp;
- }
-
- public void getDigest(byte[] out)
- {
- getDigest(out, 0);
- }
-
- public void getDigest(byte[] out, int off)
- {
- try {
- md.digest(out, off, out.length - off);
- } catch (DigestException e) {
+ +package com.trilead.ssh2.crypto.digest; + +import java.math.BigInteger; +import java.security.DigestException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * HashForSSH2Types. + * + * @author Christian Plattner, plattner@trilead.com + * @version $Id: HashForSSH2Types.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ + */ +public class HashForSSH2Types +{ + MessageDigest md; + + public HashForSSH2Types(MessageDigest md) + { + this.md = md; + } + + public HashForSSH2Types(String type) + { + try { + if ("SHA1".equals(type) || "MD5".equals(type)) { + md = MessageDigest.getInstance(type); + } else { + throw new IllegalArgumentException("Unknown algorithm " + type); + } + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Unsupported algorithm " + type); + } + } + + public void updateByte(byte b) + { + /* HACK - to test it with J2ME */ + byte[] tmp = new byte[1]; + tmp[0] = b; + md.update(tmp); + } + + public void updateBytes(byte[] b) + { + md.update(b); + } + + public void updateUINT32(int v) + { + md.update((byte) (v >> 24)); + md.update((byte) (v >> 16)); + md.update((byte) (v >> 8)); + md.update((byte) (v)); + } + + public void updateByteString(byte[] b) + { + updateUINT32(b.length); + updateBytes(b); + } + + public void updateBigInt(BigInteger b) + { + updateByteString(b.toByteArray()); + } + + public void reset() + { + md.reset(); + } + + public int getDigestLength() + { + return md.getDigestLength(); + } + + public byte[] getDigest() + { + byte[] tmp = new byte[md.getDigestLength()]; + getDigest(tmp); + return tmp; + } + + public void getDigest(byte[] out) + { + getDigest(out, 0); + } + + public void getDigest(byte[] out, int off) + { + try { + md.digest(out, off, out.length - off); + } catch (DigestException e) { // TODO is this right?! - throw new RuntimeException("Unable to digest", e);
- }
- }
-}
+ throw new RuntimeException("Unable to digest", e); + } + } +} diff --git a/src/com/trilead/ssh2/crypto/digest/MAC.java b/src/com/trilead/ssh2/crypto/digest/MAC.java index 8138e63..20c52fa 100644 --- a/src/com/trilead/ssh2/crypto/digest/MAC.java +++ b/src/com/trilead/ssh2/crypto/digest/MAC.java @@ -1,118 +1,118 @@ -
-package com.trilead.ssh2.crypto.digest;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-
-import javax.crypto.Mac;
-import javax.crypto.ShortBufferException;
-import javax.crypto.spec.SecretKeySpec;
-
-/**
- * MAC.
- *
- * @author Christian Plattner, plattner@trilead.com
- * @version $Id: MAC.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $
- */
-public final class MAC
-{
- Mac mac;
- int outSize;
- int macSize;
- byte[] buffer;
-
- /* Higher Priority First */
- private static final String[] MAC_LIST = {
- "hmac-sha1-96", "hmac-sha1", "hmac-md5-96", "hmac-md5"
- };
-
- public final static String[] getMacList()
- {
- return MAC_LIST;
- }
-
- public final static void checkMacList(String[] macs)
- {
- for (int i = 0; i < macs.length; i++)
- getKeyLen(macs[i]);
- }
-
- public final static int getKeyLen(String type)
- {
- if (type.equals("hmac-sha1"))
- return 20;
- if (type.equals("hmac-sha1-96"))
- return 20;
- if (type.equals("hmac-md5"))
- return 16;
- if (type.equals("hmac-md5-96"))
- return 16;
- throw new IllegalArgumentException("Unkown algorithm " + type);
- }
-
- public MAC(String type, byte[] key)
- {
- try {
- if ("hmac-sha1".equals(type) || "hmac-sha1-96".equals(type))
- {
- mac = Mac.getInstance("HmacSHA1");
- }
- else if ("hmac-md5".equals(type) || "hmac-md5-96".equals(type))
- {
- mac = Mac.getInstance("HmacMD5");
- }
- else
- throw new IllegalArgumentException("Unkown algorithm " + type);
- } catch (NoSuchAlgorithmException e) {
- throw new IllegalArgumentException("Unknown algorithm " + type, e);
- }
-
- macSize = mac.getMacLength();
- if (type.endsWith("-96")) {
- outSize = 12;
- buffer = new byte[macSize];
- } else {
- outSize = macSize;
- buffer = null;
- }
-
- try {
- mac.init(new SecretKeySpec(key, type));
- } catch (InvalidKeyException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public final void initMac(int seq)
- {
- mac.reset();
- mac.update((byte) (seq >> 24));
- mac.update((byte) (seq >> 16));
- mac.update((byte) (seq >> 8));
- mac.update((byte) (seq));
- }
-
- public final void update(byte[] packetdata, int off, int len)
- {
- mac.update(packetdata, off, len);
- }
-
- public final void getMac(byte[] out, int off)
- {
- try {
- if (buffer != null) {
- mac.doFinal(buffer, 0);
- System.arraycopy(buffer, 0, out, off, out.length - off);
- } else {
- mac.doFinal(out, off);
- }
- } catch (ShortBufferException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public final int size()
- {
- return outSize;
- }
-}
+ +package com.trilead.ssh2.crypto.digest; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.Mac; +import javax.crypto.ShortBufferException; +import javax.crypto.spec.SecretKeySpec; + +/** + * MAC. + * + * @author Christian Plattner, plattner@trilead.com + * @version $Id: MAC.java,v 1.1 2007/10/15 12:49:57 cplattne Exp $ + */ +public final class MAC +{ + Mac mac; + int outSize; + int macSize; + byte[] buffer; + + /* Higher Priority First */ + private static final String[] MAC_LIST = { + "hmac-sha1-96", "hmac-sha1", "hmac-md5-96", "hmac-md5" + }; + + public final static String[] getMacList() + { + return MAC_LIST; + } + + public final static void checkMacList(String[] macs) + { + for (int i = 0; i < macs.length; i++) + getKeyLen(macs[i]); + } + + public final static int getKeyLen(String type) + { + if (type.equals("hmac-sha1")) + return 20; + if (type.equals("hmac-sha1-96")) + return 20; + if (type.equals("hmac-md5")) + return 16; + if (type.equals("hmac-md5-96")) + return 16; + throw new IllegalArgumentException("Unkown algorithm " + type); + } + + public MAC(String type, byte[] key) + { + try { + if ("hmac-sha1".equals(type) || "hmac-sha1-96".equals(type)) + { + mac = Mac.getInstance("HmacSHA1"); + } + else if ("hmac-md5".equals(type) || "hmac-md5-96".equals(type)) + { + mac = Mac.getInstance("HmacMD5"); + } + else + throw new IllegalArgumentException("Unkown algorithm " + type); + } catch (NoSuchAlgorithmException e) { + throw new IllegalArgumentException("Unknown algorithm " + type, e); + } + + macSize = mac.getMacLength(); + if (type.endsWith("-96")) { + outSize = 12; + buffer = new byte[macSize]; + } else { + outSize = macSize; + buffer = null; + } + + try { + mac.init(new SecretKeySpec(key, type)); + } catch (InvalidKeyException e) { + throw new IllegalArgumentException(e); + } + } + + public final void initMac(int seq) + { + mac.reset(); + mac.update((byte) (seq >> 24)); + mac.update((byte) (seq >> 16)); + mac.update((byte) (seq >> 8)); + mac.update((byte) (seq)); + } + + public final void update(byte[] packetdata, int off, int len) + { + mac.update(packetdata, off, len); + } + + public final void getMac(byte[] out, int off) + { + try { + if (buffer != null) { + mac.doFinal(buffer, 0); + System.arraycopy(buffer, 0, out, off, out.length - off); + } else { + mac.doFinal(out, off); + } + } catch (ShortBufferException e) { + throw new IllegalStateException(e); + } + } + + public final int size() + { + return outSize; + } +} |