Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.crypto.digest;
 
 
 import  org.jboss.security.PicketBoxMessages;

The SHA_Interleave algorithm as described in section 3.1 of RFC2945. This needs an SHA MessageDigest provider to function.

Author(s):
Scott.Stark@jboss.org
Version:
$Revision$
 
 public class SHAInterleave extends MessageDigestSpi
 {
    private static final int SHA_HASH_LEN = 20;
 
    private int count;
    private boolean skipLeadingZeros;
    private MessageDigest sha;

   
Creates a new instance of SHAInterleave

Throws:
ProviderException thrown if MessageDigest.getInstance("SHA") throws a NoSuchAlgorithmException.
 
    public SHAInterleave()
    {
       try
       {
           = MessageDigest.getInstance("SHA");
       }
       catch(NoSuchAlgorithmException e)
       {
          throw PicketBoxMessages.MESSAGES.failedToObtainSHAMessageDigest(e);
       }
        = new ByteArrayOutputStream();
        = new ByteArrayOutputStream();
       engineReset();
    }
 
    protected int engineGetDigestLength()
    {
       return 2 * ;
    }

   
Completes the digest computation by performing final operations such as padding. Once engineDigest has been called, the engine should be reset (see engineReset). Resetting is the responsibility of the engine implementor.

Returns:
the array of bytes for the resulting digest value.
 
    protected byte[] engineDigest()
    {
       byte[] E = .toByteArray();
       byte[] G = .digest(E);
       // If the count is odd, drop the first byte
       byte[] F = .toByteArray();
       int offset = 0;
       if % 2 == 1 )
          offset = 1;
       .reset();
       .update(FoffsetF.length-offset);
       byte[] H = .digest();
       int length = G.length + H.length;
       byte[] digest = new byte[length];
       for(int i = 0; i < G.length; ++i)
          digest[2 * i] = G[i];
       for(int i = 0; i < H.length; ++i)
          digest[2 * i + 1] = H[i];
      engineReset();
      return digest;
   }

   
Resets the digest for further use.
   protected void engineReset()
   {
       = true;
       = 0;
      .reset();
      .reset();
      .reset();
   }

   
Updates the digest using the specified byte.

Parameters:
input the byte to use for the update.
   protected void engineUpdate(byte input)
   {
      if == true && input == 0 )
         return;
       = false;
      if % 2 == 0 )
         .write(input);
      else
         .write(input);
       ++;
   }

   
Updates the digest using the specified array of bytes, starting at the specified offset.

Parameters:
input the array of bytes to use for the update.
offset the offset to start from in the array of bytes.
len the input of bytes to use, starting at offset.
   protected void engineUpdate(byte[] inputint offsetint len)
   {
      for(int i = offseti < offset+leni ++)
         engineUpdate(input[i]);
   }
New to GrepCode? Check out our FAQ X