00001 using System;
00002
00003 namespace Tamir.SharpSsh.jsch.jce
00004 {
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 public class HMACMD5 : MAC
00035 {
00036 private const String name="hmac-md5";
00037 private const int bsize=16;
00038 private Org.Mentalis.Security.Cryptography.HMAC mentalis_mac;
00039 private System.Security.Cryptography.CryptoStream cs;
00040
00041 public int getBlockSize(){return bsize;}
00042 public void init(byte[] key)
00043 {
00044 if(key.Length>bsize)
00045 {
00046 byte[] tmp=new byte[bsize];
00047 Array.Copy(key, 0, tmp, 0, bsize);
00048 key=tmp;
00049 }
00050
00051
00052
00053 mentalis_mac = new Org.Mentalis.Security.Cryptography.HMAC(new System.Security.Cryptography.MD5CryptoServiceProvider(), key);
00054 cs = new System.Security.Cryptography.CryptoStream( System.IO.Stream.Null, mentalis_mac, System.Security.Cryptography.CryptoStreamMode.Write);
00055 }
00056
00057 private byte[] tmp=new byte[4];
00058 public void update(int i)
00059 {
00060 tmp[0]=(byte)(i>>24);
00061 tmp[1]=(byte)(i>>16);
00062 tmp[2]=(byte)(i>>8);
00063 tmp[3]=(byte)i;
00064 update(tmp, 0, 4);
00065 }
00066 public void update(byte[] foo, int s, int l)
00067 {
00068
00069 cs.Write( foo, s, l);
00070 }
00071 public byte[] doFinal()
00072 {
00073
00074 cs.Close();
00075 byte[] result = mentalis_mac.Hash;
00076 byte[] key = mentalis_mac.Key;
00077 mentalis_mac.Clear();
00078 init(key);
00079
00080 return result;
00081 }
00082 public String getName()
00083 {
00084 return name;
00085 }
00086 }
00087
00088 }