aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/trilead/ssh2/crypto/digest
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-07-23 22:38:46 -0700
committerKenny Root <kenny@the-b.org>2015-07-24 15:35:39 -0700
commit147dae0102979a0217ac8a9eea82a4969a1ecf63 (patch)
tree40718fac7fc6a3afce07c910ffc243dd5d69d403 /app/src/main/java/com/trilead/ssh2/crypto/digest
parent739337624a5e69221a998cf10b1fd34fcc5ecd2d (diff)
downloadconnectbot-147dae0102979a0217ac8a9eea82a4969a1ecf63.tar.gz
connectbot-147dae0102979a0217ac8a9eea82a4969a1ecf63.tar.bz2
connectbot-147dae0102979a0217ac8a9eea82a4969a1ecf63.zip
Move to library-based build
Diffstat (limited to 'app/src/main/java/com/trilead/ssh2/crypto/digest')
-rw-r--r--app/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java91
-rw-r--r--app/src/main/java/com/trilead/ssh2/crypto/digest/MAC.java157
2 files changed, 0 insertions, 248 deletions
diff --git a/app/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java b/app/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java
deleted file mode 100644
index 6b0d6e3..0000000
--- a/app/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java
+++ /dev/null
@@ -1,91 +0,0 @@
-
-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(String type)
- {
- try {
- md = MessageDigest.getInstance(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);
- }
- }
-}
diff --git a/app/src/main/java/com/trilead/ssh2/crypto/digest/MAC.java b/app/src/main/java/com/trilead/ssh2/crypto/digest/MAC.java
deleted file mode 100644
index 561599c..0000000
--- a/app/src/main/java/com/trilead/ssh2/crypto/digest/MAC.java
+++ /dev/null
@@ -1,157 +0,0 @@
-
-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
-{
- /**
- * From http://tools.ietf.org/html/rfc4253
- */
- private static final String HMAC_MD5 = "hmac-md5";
-
- /**
- * From http://tools.ietf.org/html/rfc4253
- */
- private static final String HMAC_MD5_96 = "hmac-md5-96";
-
- /**
- * From http://tools.ietf.org/html/rfc4253
- */
- private static final String HMAC_SHA1 = "hmac-sha1";
-
- /**
- * From http://tools.ietf.org/html/rfc4253
- */
- private static final String HMAC_SHA1_96 = "hmac-sha1-96";
-
- /**
- * From http://tools.ietf.org/html/rfc6668
- */
- private static final String HMAC_SHA2_256 = "hmac-sha2-256";
-
- /**
- * From http://tools.ietf.org/html/rfc6668
- */
- private static final String HMAC_SHA2_512 = "hmac-sha2-512";
-
- Mac mac;
- int outSize;
- int macSize;
- byte[] buffer;
-
- /* Higher Priority First */
- private static final String[] MAC_LIST = {
- HMAC_SHA2_256, HMAC_SHA2_512,
- 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 (HMAC_SHA1.equals(type) || HMAC_SHA1_96.equals(type))
- return 20;
- if (HMAC_MD5.equals(type) || HMAC_MD5_96.equals(type))
- return 16;
- if (HMAC_SHA2_256.equals(type))
- return 32;
- if (HMAC_SHA2_512.equals(type))
- return 64;
- 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 if (HMAC_SHA2_256.equals(type))
- {
- mac = Mac.getInstance("HmacSHA256");
- }
- else if (HMAC_SHA2_512.equals(type))
- {
- mac = Mac.getInstance("HmacSHA512");
- }
- 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;
- }
-}