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
 * 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:
 package org.jboss.crypto.digest;

An alternate SHA Interleave algorithm as implemented in the SRP distribution. This version reverses the even and odd byte streams before performing the SHA digest. This product includes software developed by Tom Wu and Eugene Jhong for the SRP Distribution (

$Revision: 276 $
 public class SHAReverseInterleave extends MessageDigestSpi
    private static final int SHA_HASH_LEN = 20;
    private int count;
    private boolean skipLeadingZeros;
    private MessageDigest sha;

Creates a new instance of SHAReverseInterleave

ProviderException thrown if MessageDigest.getInstance("SHA") throws a NoSuchAlgorithmException.
    public SHAReverseInterleave()
           = MessageDigest.getInstance("SHA");
       catch(NoSuchAlgorithmException e)
          throw new ProviderException(ErrorCodes.FAILED_TO_OBTAIN_SHA);
        = new ByteArrayOutputStream();
        = new ByteArrayOutputStream();
    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.

the array of bytes for the resulting digest value.
    protected byte[] engineDigest()
       byte[] E = .toByteArray();
       // If the count is odd, drop the first byte
       int length = E.length;
       if % 2 == 1 )
          length --;
       // Reverse the order of the even bytes
       byte[] tmp = new byte[length];
       for(int i = 0; i < lengthi ++)
          tmp[i] = E[E.length - i - 1];
          ..println("E["+i+"] = "+tmp[i]);
      E = tmp;
      byte[] G = .digest(E);
      byte[] F = .toByteArray();
      // Reverse the order of the even bytes
      tmp = new byte[F.length];
      for(int i = 0; i < F.lengthi ++)
         tmp[i] = F[F.length - i - 1];
         ..println("F["+i+"] = "+tmp[i]);
      F = tmp;
      byte[] H = .digest(F);
      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];
      return digest;

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

Updates the digest using the specified byte.

input the byte to use for the update.
   protected void engineUpdate(byte input)
      if == true && input == 0 )
       = false;
      if % 2 == 0 )

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

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 ++)
New to GrepCode? Check out our FAQ X