00001 using System; 00002 00003 namespace Tamir.SharpSsh.jsch.jce 00004 { 00005 /* -*-mode:java; c-basic-offset:2; -*- */ 00006 /* 00007 Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved. 00008 00009 Redistribution and use in source and binary forms, with or without 00010 modification, are permitted provided that the following conditions are met: 00011 00012 1. Redistributions of source code must retain the above copyright notice, 00013 this list of conditions and the following disclaimer. 00014 00015 2. Redistributions in binary form must reproduce the above copyright 00016 notice, this list of conditions and the following disclaimer in 00017 the documentation and/or other materials provided with the distribution. 00018 00019 3. The names of the authors may not be used to endorse or promote products 00020 derived from this software without specific prior written permission. 00021 00022 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00023 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00024 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 00025 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00028 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00031 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 public class HMACSHA196 : MAC 00035 { 00036 private const String name="hmac-sha1-96"; 00037 private const int bsize=12; 00038 private Org.Mentalis.Security.Cryptography.HMAC mentalis_mac; 00039 private System.Security.Cryptography.CryptoStream cs; 00040 //private Mac mac; 00041 public int getBlockSize(){return bsize;} 00042 public void init(byte[] key) 00043 { 00044 if(key.Length>20) 00045 { 00046 byte[] tmp=new byte[20]; 00047 Array.Copy(key, 0, tmp, 0, 20); 00048 key=tmp; 00049 } 00050 // SecretKeySpec skey=new SecretKeySpec(key, "HmacSHA1"); 00051 // mac=Mac.getInstance("HmacSHA1"); 00052 // mac.init(skey); 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 private byte[] tmp=new byte[4]; 00057 public void update(int i) 00058 { 00059 tmp[0]=(byte)(i>>24); 00060 tmp[1]=(byte)(i>>16); 00061 tmp[2]=(byte)(i>>8); 00062 tmp[3]=(byte)i; 00063 update(tmp, 0, 4); 00064 } 00065 public void update(byte[] foo, int s, int l) 00066 { 00067 //mac.update(foo, s, l); 00068 cs.Write( foo , s, l); 00069 } 00070 private byte[] buf=new byte[12]; 00071 public byte[] doFinal() 00072 { 00073 // System.arraycopy(mac.doFinal(), 0, buf, 0, 12); 00074 // return buf; 00075 cs.Close(); 00076 Array.Copy( mentalis_mac.Hash, 0, buf, 0, 12); 00077 return buf; 00078 } 00079 public String getName() 00080 { 00081 return name; 00082 } 00083 } 00084 00085 }
1.5.9