geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Dillon <ja...@planet57.com>
Subject Re: svn commit: r521413 - in /geronimo/server/trunk/modules/geronimo-util/src/main/java/org/apache/geronimo/util/crypto: ./ digests/ engines/ modes/ params/
Date Thu, 22 Mar 2007 19:39:32 GMT
Wasn't there some talk awhile ago about making a geronimo-crypto  
module and move this stuff in there?  I still think that is a good idea.

--jason


On Mar 22, 2007, at 12:32 PM, rickmcguire@apache.org wrote:

> Author: rickmcguire
> Date: Thu Mar 22 12:32:38 2007
> New Revision: 521413
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=521413
> Log:
> GERONIMO-3004 Add some additional bouncy-castle classes for  
> apacheds usage.
>
>
> Added:
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/ExtendedDigest.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/GeneralDigest.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/MD4Digest.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/MD5Digest.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/SHA1Digest.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/DESEngine.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/DESedeEngine.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/modes/
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/modes/CBCBlockCipher.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/DESParameters.java   (with props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/DESedeParameters.java   (with  
> props)
>     geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/ParametersWithIV.java   (with  
> props)
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/ExtendedDigest.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/ 
> ExtendedDigest.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/ExtendedDigest.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/ExtendedDigest.java Thu Mar 22 12:32:38  
> 2007
> @@ -0,0 +1,13 @@
> +package org.apache.geronimo.util.crypto;
> +
> +public interface ExtendedDigest
> +    extends Digest
> +{
> +    /**
> +     * Return the size in bytes of the internal buffer the digest  
> applies it's compression
> +     * function to.
> +     *
> +     * @return byte length of the digests internal buffer.
> +     */
> +    public int getByteLength();
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/ExtendedDigest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/ExtendedDigest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/ExtendedDigest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/digests/GeneralDigest.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/digests/ 
> GeneralDigest.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/GeneralDigest.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/GeneralDigest.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,152 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.digests;
> +
> +import org.apache.geronimo.util.crypto.ExtendedDigest;
> +
> +/**
> + * base implementation of MD4 family style digest as outlined in
> + * "Handbook of Applied Cryptography", pages 344 - 347.
> + */
> +public abstract class GeneralDigest
> +    implements ExtendedDigest
> +{
> +    private static final int BYTE_LENGTH = 64;
> +    private byte[]  xBuf;
> +    private int     xBufOff;
> +
> +    private long    byteCount;
> +
> +    /**
> +     * Standard constructor
> +     */
> +    protected GeneralDigest()
> +    {
> +        xBuf = new byte[4];
> +        xBufOff = 0;
> +    }
> +
> +    /**
> +     * Copy constructor.  We are using copy constructors in place
> +     * of the Object.clone() interface as this interface is not
> +     * supported by J2ME.
> +     */
> +    protected GeneralDigest(GeneralDigest t)
> +    {
> +        xBuf = new byte[t.xBuf.length];
> +        System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);
> +
> +        xBufOff = t.xBufOff;
> +        byteCount = t.byteCount;
> +    }
> +
> +    public void update(
> +        byte in)
> +    {
> +        xBuf[xBufOff++] = in;
> +
> +        if (xBufOff == xBuf.length)
> +        {
> +            processWord(xBuf, 0);
> +            xBufOff = 0;
> +        }
> +
> +        byteCount++;
> +    }
> +
> +    public void update(
> +        byte[]  in,
> +        int     inOff,
> +        int     len)
> +    {
> +        //
> +        // fill the current word
> +        //
> +        while ((xBufOff != 0) && (len > 0))
> +        {
> +            update(in[inOff]);
> +
> +            inOff++;
> +            len--;
> +        }
> +
> +        //
> +        // process whole words.
> +        //
> +        while (len > xBuf.length)
> +        {
> +            processWord(in, inOff);
> +
> +            inOff += xBuf.length;
> +            len -= xBuf.length;
> +            byteCount += xBuf.length;
> +        }
> +
> +        //
> +        // load in the remainder.
> +        //
> +        while (len > 0)
> +        {
> +            update(in[inOff]);
> +
> +            inOff++;
> +            len--;
> +        }
> +    }
> +
> +    public void finish()
> +    {
> +        long    bitLength = (byteCount << 3);
> +
> +        //
> +        // add the pad bytes.
> +        //
> +        update((byte)128);
> +
> +        while (xBufOff != 0)
> +        {
> +            update((byte)0);
> +        }
> +
> +        processLength(bitLength);
> +
> +        processBlock();
> +    }
> +
> +    public void reset()
> +    {
> +        byteCount = 0;
> +
> +        xBufOff = 0;
> +        for (int i = 0; i < xBuf.length; i++)
> +        {
> +            xBuf[i] = 0;
> +        }
> +    }
> +
> +    public int getByteLength()
> +    {
> +        return BYTE_LENGTH;
> +    }
> +
> +    protected abstract void processWord(byte[] in, int inOff);
> +
> +    protected abstract void processLength(long bitLength);
> +
> +    protected abstract void processBlock();
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/GeneralDigest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/GeneralDigest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/GeneralDigest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/digests/MD4Digest.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/digests/ 
> MD4Digest.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/MD4Digest.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/MD4Digest.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,287 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.digests;
> +
> +
> +/**
> + * implementation of MD4 as RFC 1320 by R. Rivest, MIT Laboratory for
> + * Computer Science and RSA Data Security, Inc.
> + * <p>
> + * <b>NOTE</b>: This algorithm is only included for backwards  
> compatability
> + * with legacy applications, it's not secure, don't use it for  
> anything new!
> + */
> +public class MD4Digest
> +    extends GeneralDigest
> +{
> +    private static final int    DIGEST_LENGTH = 16;
> +
> +    private int     H1, H2, H3, H4;         // IV's
> +
> +    private int[]   X = new int[16];
> +    private int     xOff;
> +
> +    /**
> +     * Standard constructor
> +     */
> +    public MD4Digest()
> +    {
> +        reset();
> +    }
> +
> +    /**
> +     * Copy constructor.  This will copy the state of the provided
> +     * message digest.
> +     */
> +    public MD4Digest(MD4Digest t)
> +    {
> +        super(t);
> +
> +        H1 = t.H1;
> +        H2 = t.H2;
> +        H3 = t.H3;
> +        H4 = t.H4;
> +
> +        System.arraycopy(t.X, 0, X, 0, t.X.length);
> +        xOff = t.xOff;
> +    }
> +
> +    public String getAlgorithmName()
> +    {
> +        return "MD4";
> +    }
> +
> +    public int getDigestSize()
> +    {
> +        return DIGEST_LENGTH;
> +    }
> +
> +    protected void processWord(
> +        byte[]  in,
> +        int     inOff)
> +    {
> +        X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff)  
> << 8)
> +            | ((in[inOff + 2] & 0xff) << 16) | ((in[inOff + 3] &  
> 0xff) << 24);
> +
> +        if (xOff == 16)
> +        {
> +            processBlock();
> +        }
> +    }
> +
> +    protected void processLength(
> +        long    bitLength)
> +    {
> +        if (xOff > 14)
> +        {
> +            processBlock();
> +        }
> +
> +        X[14] = (int)(bitLength & 0xffffffff);
> +        X[15] = (int)(bitLength >>> 32);
> +    }
> +
> +    private void unpackWord(
> +        int     word,
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        out[outOff]     = (byte)word;
> +        out[outOff + 1] = (byte)(word >>> 8);
> +        out[outOff + 2] = (byte)(word >>> 16);
> +        out[outOff + 3] = (byte)(word >>> 24);
> +    }
> +
> +    public int doFinal(
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        finish();
> +
> +        unpackWord(H1, out, outOff);
> +        unpackWord(H2, out, outOff + 4);
> +        unpackWord(H3, out, outOff + 8);
> +        unpackWord(H4, out, outOff + 12);
> +
> +        reset();
> +
> +        return DIGEST_LENGTH;
> +    }
> +
> +    /**
> +     * reset the chaining variables to the IV values.
> +     */
> +    public void reset()
> +    {
> +        super.reset();
> +
> +        H1 = 0x67452301;
> +        H2 = 0xefcdab89;
> +        H3 = 0x98badcfe;
> +        H4 = 0x10325476;
> +
> +        xOff = 0;
> +
> +        for (int i = 0; i != X.length; i++)
> +        {
> +            X[i] = 0;
> +        }
> +    }
> +
> +    //
> +    // round 1 left rotates
> +    //
> +    private static final int S11 = 3;
> +    private static final int S12 = 7;
> +    private static final int S13 = 11;
> +    private static final int S14 = 19;
> +
> +    //
> +    // round 2 left rotates
> +    //
> +    private static final int S21 = 3;
> +    private static final int S22 = 5;
> +    private static final int S23 = 9;
> +    private static final int S24 = 13;
> +
> +    //
> +    // round 3 left rotates
> +    //
> +    private static final int S31 = 3;
> +    private static final int S32 = 9;
> +    private static final int S33 = 11;
> +    private static final int S34 = 15;
> +
> +    /*
> +     * rotate int x left n bits.
> +     */
> +    private int rotateLeft(
> +        int x,
> +        int n)
> +    {
> +        return (x << n) | (x >>> (32 - n));
> +    }
> +
> +    /*
> +     * F, G, H and I are the basic MD4 functions.
> +     */
> +    private int F(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return (u & v) | (~u & w);
> +    }
> +
> +    private int G(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return (u & v) | (u & w) | (v & w);
> +    }
> +
> +    private int H(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return u ^ v ^ w;
> +    }
> +
> +    protected void processBlock()
> +    {
> +        int a = H1;
> +        int b = H2;
> +        int c = H3;
> +        int d = H4;
> +
> +        //
> +        // Round 1 - F cycle, 16 times.
> +        //
> +        a = rotateLeft(a + F(b, c, d) + X[ 0], S11);
> +        d = rotateLeft(d + F(a, b, c) + X[ 1], S12);
> +        c = rotateLeft(c + F(d, a, b) + X[ 2], S13);
> +        b = rotateLeft(b + F(c, d, a) + X[ 3], S14);
> +        a = rotateLeft(a + F(b, c, d) + X[ 4], S11);
> +        d = rotateLeft(d + F(a, b, c) + X[ 5], S12);
> +        c = rotateLeft(c + F(d, a, b) + X[ 6], S13);
> +        b = rotateLeft(b + F(c, d, a) + X[ 7], S14);
> +        a = rotateLeft(a + F(b, c, d) + X[ 8], S11);
> +        d = rotateLeft(d + F(a, b, c) + X[ 9], S12);
> +        c = rotateLeft(c + F(d, a, b) + X[10], S13);
> +        b = rotateLeft(b + F(c, d, a) + X[11], S14);
> +        a = rotateLeft(a + F(b, c, d) + X[12], S11);
> +        d = rotateLeft(d + F(a, b, c) + X[13], S12);
> +        c = rotateLeft(c + F(d, a, b) + X[14], S13);
> +        b = rotateLeft(b + F(c, d, a) + X[15], S14);
> +
> +        //
> +        // Round 2 - G cycle, 16 times.
> +        //
> +        a = rotateLeft(a + G(b, c, d) + X[ 0] + 0x5a827999, S21);
> +        d = rotateLeft(d + G(a, b, c) + X[ 4] + 0x5a827999, S22);
> +        c = rotateLeft(c + G(d, a, b) + X[ 8] + 0x5a827999, S23);
> +        b = rotateLeft(b + G(c, d, a) + X[12] + 0x5a827999, S24);
> +        a = rotateLeft(a + G(b, c, d) + X[ 1] + 0x5a827999, S21);
> +        d = rotateLeft(d + G(a, b, c) + X[ 5] + 0x5a827999, S22);
> +        c = rotateLeft(c + G(d, a, b) + X[ 9] + 0x5a827999, S23);
> +        b = rotateLeft(b + G(c, d, a) + X[13] + 0x5a827999, S24);
> +        a = rotateLeft(a + G(b, c, d) + X[ 2] + 0x5a827999, S21);
> +        d = rotateLeft(d + G(a, b, c) + X[ 6] + 0x5a827999, S22);
> +        c = rotateLeft(c + G(d, a, b) + X[10] + 0x5a827999, S23);
> +        b = rotateLeft(b + G(c, d, a) + X[14] + 0x5a827999, S24);
> +        a = rotateLeft(a + G(b, c, d) + X[ 3] + 0x5a827999, S21);
> +        d = rotateLeft(d + G(a, b, c) + X[ 7] + 0x5a827999, S22);
> +        c = rotateLeft(c + G(d, a, b) + X[11] + 0x5a827999, S23);
> +        b = rotateLeft(b + G(c, d, a) + X[15] + 0x5a827999, S24);
> +
> +        //
> +        // Round 3 - H cycle, 16 times.
> +        //
> +        a = rotateLeft(a + H(b, c, d) + X[ 0] + 0x6ed9eba1, S31);
> +        d = rotateLeft(d + H(a, b, c) + X[ 8] + 0x6ed9eba1, S32);
> +        c = rotateLeft(c + H(d, a, b) + X[ 4] + 0x6ed9eba1, S33);
> +        b = rotateLeft(b + H(c, d, a) + X[12] + 0x6ed9eba1, S34);
> +        a = rotateLeft(a + H(b, c, d) + X[ 2] + 0x6ed9eba1, S31);
> +        d = rotateLeft(d + H(a, b, c) + X[10] + 0x6ed9eba1, S32);
> +        c = rotateLeft(c + H(d, a, b) + X[ 6] + 0x6ed9eba1, S33);
> +        b = rotateLeft(b + H(c, d, a) + X[14] + 0x6ed9eba1, S34);
> +        a = rotateLeft(a + H(b, c, d) + X[ 1] + 0x6ed9eba1, S31);
> +        d = rotateLeft(d + H(a, b, c) + X[ 9] + 0x6ed9eba1, S32);
> +        c = rotateLeft(c + H(d, a, b) + X[ 5] + 0x6ed9eba1, S33);
> +        b = rotateLeft(b + H(c, d, a) + X[13] + 0x6ed9eba1, S34);
> +        a = rotateLeft(a + H(b, c, d) + X[ 3] + 0x6ed9eba1, S31);
> +        d = rotateLeft(d + H(a, b, c) + X[11] + 0x6ed9eba1, S32);
> +        c = rotateLeft(c + H(d, a, b) + X[ 7] + 0x6ed9eba1, S33);
> +        b = rotateLeft(b + H(c, d, a) + X[15] + 0x6ed9eba1, S34);
> +
> +        H1 += a;
> +        H2 += b;
> +        H3 += c;
> +        H4 += d;
> +
> +        //
> +        // reset the offset and clean out the word buffer.
> +        //
> +        xOff = 0;
> +        for (int i = 0; i != X.length; i++)
> +        {
> +            X[i] = 0;
> +        }
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/MD4Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/MD4Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/MD4Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/digests/MD5Digest.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/digests/ 
> MD5Digest.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/MD5Digest.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/MD5Digest.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,319 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.digests;
> +
> +
> +/**
> + * implementation of MD5 as outlined in "Handbook of Applied  
> Cryptography", pages 346 - 347.
> + */
> +public class MD5Digest
> +    extends GeneralDigest
> +{
> +    private static final int    DIGEST_LENGTH = 16;
> +
> +    private int     H1, H2, H3, H4;         // IV's
> +
> +    private int[]   X = new int[16];
> +    private int     xOff;
> +
> +    /**
> +     * Standard constructor
> +     */
> +    public MD5Digest()
> +    {
> +        reset();
> +    }
> +
> +    /**
> +     * Copy constructor.  This will copy the state of the provided
> +     * message digest.
> +     */
> +    public MD5Digest(MD5Digest t)
> +    {
> +        super(t);
> +
> +        H1 = t.H1;
> +        H2 = t.H2;
> +        H3 = t.H3;
> +        H4 = t.H4;
> +
> +        System.arraycopy(t.X, 0, X, 0, t.X.length);
> +        xOff = t.xOff;
> +    }
> +
> +    public String getAlgorithmName()
> +    {
> +        return "MD5";
> +    }
> +
> +    public int getDigestSize()
> +    {
> +        return DIGEST_LENGTH;
> +    }
> +
> +    protected void processWord(
> +        byte[]  in,
> +        int     inOff)
> +    {
> +        X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff)  
> << 8)
> +            | ((in[inOff + 2] & 0xff) << 16) | ((in[inOff + 3] &  
> 0xff) << 24);
> +
> +        if (xOff == 16)
> +        {
> +            processBlock();
> +        }
> +    }
> +
> +    protected void processLength(
> +        long    bitLength)
> +    {
> +        if (xOff > 14)
> +        {
> +            processBlock();
> +        }
> +
> +        X[14] = (int)(bitLength & 0xffffffff);
> +        X[15] = (int)(bitLength >>> 32);
> +    }
> +
> +    private void unpackWord(
> +        int     word,
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        out[outOff]     = (byte)word;
> +        out[outOff + 1] = (byte)(word >>> 8);
> +        out[outOff + 2] = (byte)(word >>> 16);
> +        out[outOff + 3] = (byte)(word >>> 24);
> +    }
> +
> +    public int doFinal(
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        finish();
> +
> +        unpackWord(H1, out, outOff);
> +        unpackWord(H2, out, outOff + 4);
> +        unpackWord(H3, out, outOff + 8);
> +        unpackWord(H4, out, outOff + 12);
> +
> +        reset();
> +
> +        return DIGEST_LENGTH;
> +    }
> +
> +    /**
> +     * reset the chaining variables to the IV values.
> +     */
> +    public void reset()
> +    {
> +        super.reset();
> +
> +        H1 = 0x67452301;
> +        H2 = 0xefcdab89;
> +        H3 = 0x98badcfe;
> +        H4 = 0x10325476;
> +
> +        xOff = 0;
> +
> +        for (int i = 0; i != X.length; i++)
> +        {
> +            X[i] = 0;
> +        }
> +    }
> +
> +    //
> +    // round 1 left rotates
> +    //
> +    private static final int S11 = 7;
> +    private static final int S12 = 12;
> +    private static final int S13 = 17;
> +    private static final int S14 = 22;
> +
> +    //
> +    // round 2 left rotates
> +    //
> +    private static final int S21 = 5;
> +    private static final int S22 = 9;
> +    private static final int S23 = 14;
> +    private static final int S24 = 20;
> +
> +    //
> +    // round 3 left rotates
> +    //
> +    private static final int S31 = 4;
> +    private static final int S32 = 11;
> +    private static final int S33 = 16;
> +    private static final int S34 = 23;
> +
> +    //
> +    // round 4 left rotates
> +    //
> +    private static final int S41 = 6;
> +    private static final int S42 = 10;
> +    private static final int S43 = 15;
> +    private static final int S44 = 21;
> +
> +    /*
> +     * rotate int x left n bits.
> +     */
> +    private int rotateLeft(
> +        int x,
> +        int n)
> +    {
> +        return (x << n) | (x >>> (32 - n));
> +    }
> +
> +    /*
> +     * F, G, H and I are the basic MD5 functions.
> +     */
> +    private int F(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return (u & v) | (~u & w);
> +    }
> +
> +    private int G(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return (u & w) | (v & ~w);
> +    }
> +
> +    private int H(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return u ^ v ^ w;
> +    }
> +
> +    private int K(
> +        int u,
> +        int v,
> +        int w)
> +    {
> +        return v ^ (u | ~w);
> +    }
> +
> +    protected void processBlock()
> +    {
> +        int a = H1;
> +        int b = H2;
> +        int c = H3;
> +        int d = H4;
> +
> +        //
> +        // Round 1 - F cycle, 16 times.
> +        //
> +        a = rotateLeft(a + F(b, c, d) + X[ 0] + 0xd76aa478, S11) + b;
> +        d = rotateLeft(d + F(a, b, c) + X[ 1] + 0xe8c7b756, S12) + a;
> +        c = rotateLeft(c + F(d, a, b) + X[ 2] + 0x242070db, S13) + d;
> +        b = rotateLeft(b + F(c, d, a) + X[ 3] + 0xc1bdceee, S14) + c;
> +        a = rotateLeft(a + F(b, c, d) + X[ 4] + 0xf57c0faf, S11) + b;
> +        d = rotateLeft(d + F(a, b, c) + X[ 5] + 0x4787c62a, S12) + a;
> +        c = rotateLeft(c + F(d, a, b) + X[ 6] + 0xa8304613, S13) + d;
> +        b = rotateLeft(b + F(c, d, a) + X[ 7] + 0xfd469501, S14) + c;
> +        a = rotateLeft(a + F(b, c, d) + X[ 8] + 0x698098d8, S11) + b;
> +        d = rotateLeft(d + F(a, b, c) + X[ 9] + 0x8b44f7af, S12) + a;
> +        c = rotateLeft(c + F(d, a, b) + X[10] + 0xffff5bb1, S13) + d;
> +        b = rotateLeft(b + F(c, d, a) + X[11] + 0x895cd7be, S14) + c;
> +        a = rotateLeft(a + F(b, c, d) + X[12] + 0x6b901122, S11) + b;
> +        d = rotateLeft(d + F(a, b, c) + X[13] + 0xfd987193, S12) + a;
> +        c = rotateLeft(c + F(d, a, b) + X[14] + 0xa679438e, S13) + d;
> +        b = rotateLeft(b + F(c, d, a) + X[15] + 0x49b40821, S14) + c;
> +
> +        //
> +        // Round 2 - G cycle, 16 times.
> +        //
> +        a = rotateLeft(a + G(b, c, d) + X[ 1] + 0xf61e2562, S21) + b;
> +        d = rotateLeft(d + G(a, b, c) + X[ 6] + 0xc040b340, S22) + a;
> +        c = rotateLeft(c + G(d, a, b) + X[11] + 0x265e5a51, S23) + d;
> +        b = rotateLeft(b + G(c, d, a) + X[ 0] + 0xe9b6c7aa, S24) + c;
> +        a = rotateLeft(a + G(b, c, d) + X[ 5] + 0xd62f105d, S21) + b;
> +        d = rotateLeft(d + G(a, b, c) + X[10] + 0x02441453, S22) + a;
> +        c = rotateLeft(c + G(d, a, b) + X[15] + 0xd8a1e681, S23) + d;
> +        b = rotateLeft(b + G(c, d, a) + X[ 4] + 0xe7d3fbc8, S24) + c;
> +        a = rotateLeft(a + G(b, c, d) + X[ 9] + 0x21e1cde6, S21) + b;
> +        d = rotateLeft(d + G(a, b, c) + X[14] + 0xc33707d6, S22) + a;
> +        c = rotateLeft(c + G(d, a, b) + X[ 3] + 0xf4d50d87, S23) + d;
> +        b = rotateLeft(b + G(c, d, a) + X[ 8] + 0x455a14ed, S24) + c;
> +        a = rotateLeft(a + G(b, c, d) + X[13] + 0xa9e3e905, S21) + b;
> +        d = rotateLeft(d + G(a, b, c) + X[ 2] + 0xfcefa3f8, S22) + a;
> +        c = rotateLeft(c + G(d, a, b) + X[ 7] + 0x676f02d9, S23) + d;
> +        b = rotateLeft(b + G(c, d, a) + X[12] + 0x8d2a4c8a, S24) + c;
> +
> +        //
> +        // Round 3 - H cycle, 16 times.
> +        //
> +        a = rotateLeft(a + H(b, c, d) + X[ 5] + 0xfffa3942, S31) + b;
> +        d = rotateLeft(d + H(a, b, c) + X[ 8] + 0x8771f681, S32) + a;
> +        c = rotateLeft(c + H(d, a, b) + X[11] + 0x6d9d6122, S33) + d;
> +        b = rotateLeft(b + H(c, d, a) + X[14] + 0xfde5380c, S34) + c;
> +        a = rotateLeft(a + H(b, c, d) + X[ 1] + 0xa4beea44, S31) + b;
> +        d = rotateLeft(d + H(a, b, c) + X[ 4] + 0x4bdecfa9, S32) + a;
> +        c = rotateLeft(c + H(d, a, b) + X[ 7] + 0xf6bb4b60, S33) + d;
> +        b = rotateLeft(b + H(c, d, a) + X[10] + 0xbebfbc70, S34) + c;
> +        a = rotateLeft(a + H(b, c, d) + X[13] + 0x289b7ec6, S31) + b;
> +        d = rotateLeft(d + H(a, b, c) + X[ 0] + 0xeaa127fa, S32) + a;
> +        c = rotateLeft(c + H(d, a, b) + X[ 3] + 0xd4ef3085, S33) + d;
> +        b = rotateLeft(b + H(c, d, a) + X[ 6] + 0x04881d05, S34) + c;
> +        a = rotateLeft(a + H(b, c, d) + X[ 9] + 0xd9d4d039, S31) + b;
> +        d = rotateLeft(d + H(a, b, c) + X[12] + 0xe6db99e5, S32) + a;
> +        c = rotateLeft(c + H(d, a, b) + X[15] + 0x1fa27cf8, S33) + d;
> +        b = rotateLeft(b + H(c, d, a) + X[ 2] + 0xc4ac5665, S34) + c;
> +
> +        //
> +        // Round 4 - K cycle, 16 times.
> +        //
> +        a = rotateLeft(a + K(b, c, d) + X[ 0] + 0xf4292244, S41) + b;
> +        d = rotateLeft(d + K(a, b, c) + X[ 7] + 0x432aff97, S42) + a;
> +        c = rotateLeft(c + K(d, a, b) + X[14] + 0xab9423a7, S43) + d;
> +        b = rotateLeft(b + K(c, d, a) + X[ 5] + 0xfc93a039, S44) + c;
> +        a = rotateLeft(a + K(b, c, d) + X[12] + 0x655b59c3, S41) + b;
> +        d = rotateLeft(d + K(a, b, c) + X[ 3] + 0x8f0ccc92, S42) + a;
> +        c = rotateLeft(c + K(d, a, b) + X[10] + 0xffeff47d, S43) + d;
> +        b = rotateLeft(b + K(c, d, a) + X[ 1] + 0x85845dd1, S44) + c;
> +        a = rotateLeft(a + K(b, c, d) + X[ 8] + 0x6fa87e4f, S41) + b;
> +        d = rotateLeft(d + K(a, b, c) + X[15] + 0xfe2ce6e0, S42) + a;
> +        c = rotateLeft(c + K(d, a, b) + X[ 6] + 0xa3014314, S43) + d;
> +        b = rotateLeft(b + K(c, d, a) + X[13] + 0x4e0811a1, S44) + c;
> +        a = rotateLeft(a + K(b, c, d) + X[ 4] + 0xf7537e82, S41) + b;
> +        d = rotateLeft(d + K(a, b, c) + X[11] + 0xbd3af235, S42) + a;
> +        c = rotateLeft(c + K(d, a, b) + X[ 2] + 0x2ad7d2bb, S43) + d;
> +        b = rotateLeft(b + K(c, d, a) + X[ 9] + 0xeb86d391, S44) + c;
> +
> +        H1 += a;
> +        H2 += b;
> +        H3 += c;
> +        H4 += d;
> +
> +        //
> +        // reset the offset and clean out the word buffer.
> +        //
> +        xOff = 0;
> +        for (int i = 0; i != X.length; i++)
> +        {
> +            X[i] = 0;
> +        }
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/MD5Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/MD5Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/MD5Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/digests/SHA1Digest.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/digests/ 
> SHA1Digest.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/SHA1Digest.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/digests/SHA1Digest.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,311 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.digests;
> +
> +/**
> + * implementation of SHA-1 as outlined in "Handbook of Applied  
> Cryptography", pages 346 - 349.
> + *
> + * It is interesting to ponder why the, apart from the extra IV,  
> the other difference here from MD5
> + * is the "endienness" of the word processing!
> + */
> +public class SHA1Digest
> +    extends GeneralDigest
> +{
> +    private static final int    DIGEST_LENGTH = 20;
> +
> +    private int     H1, H2, H3, H4, H5;
> +
> +    private int[]   X = new int[80];
> +    private int     xOff;
> +
> +    /**
> +     * Standard constructor
> +     */
> +    public SHA1Digest()
> +    {
> +        reset();
> +    }
> +
> +    /**
> +     * Copy constructor.  This will copy the state of the provided
> +     * message digest.
> +     */
> +    public SHA1Digest(SHA1Digest t)
> +    {
> +        super(t);
> +
> +        H1 = t.H1;
> +        H2 = t.H2;
> +        H3 = t.H3;
> +        H4 = t.H4;
> +        H5 = t.H5;
> +
> +        System.arraycopy(t.X, 0, X, 0, t.X.length);
> +        xOff = t.xOff;
> +    }
> +
> +    public String getAlgorithmName()
> +    {
> +        return "SHA-1";
> +    }
> +
> +    public int getDigestSize()
> +    {
> +        return DIGEST_LENGTH;
> +    }
> +
> +    protected void processWord(
> +        byte[]  in,
> +        int     inOff)
> +    {
> +        X[xOff++] = (in[inOff] & 0xff) << 24 | (in[inOff + 1] &  
> 0xff) << 16
> +                    | (in[inOff + 2] & 0xff) << 8 | in[inOff + 3]  
> & 0xff;
> +
> +        if (xOff == 16)
> +        {
> +            processBlock();
> +        }
> +    }
> +
> +    private void unpackWord(
> +        int     word,
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        out[outOff++] = (byte)(word >>> 24);
> +        out[outOff++] = (byte)(word >>> 16);
> +        out[outOff++] = (byte)(word >>> 8);
> +        out[outOff++] = (byte)word;
> +    }
> +
> +    protected void processLength(
> +        long    bitLength)
> +    {
> +        if (xOff > 14)
> +        {
> +            processBlock();
> +        }
> +
> +        X[14] = (int)(bitLength >>> 32);
> +        X[15] = (int)(bitLength & 0xffffffff);
> +    }
> +
> +    public int doFinal(
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        finish();
> +
> +        unpackWord(H1, out, outOff);
> +        unpackWord(H2, out, outOff + 4);
> +        unpackWord(H3, out, outOff + 8);
> +        unpackWord(H4, out, outOff + 12);
> +        unpackWord(H5, out, outOff + 16);
> +
> +        reset();
> +
> +        return DIGEST_LENGTH;
> +    }
> +
> +    /**
> +     * reset the chaining variables
> +     */
> +    public void reset()
> +    {
> +        super.reset();
> +
> +        H1 = 0x67452301;
> +        H2 = 0xefcdab89;
> +        H3 = 0x98badcfe;
> +        H4 = 0x10325476;
> +        H5 = 0xc3d2e1f0;
> +
> +        xOff = 0;
> +        for (int i = 0; i != X.length; i++)
> +        {
> +            X[i] = 0;
> +        }
> +    }
> +
> +    //
> +    // Additive constants
> +    //
> +    private static final int    Y1 = 0x5a827999;
> +    private static final int    Y2 = 0x6ed9eba1;
> +    private static final int    Y3 = 0x8f1bbcdc;
> +    private static final int    Y4 = 0xca62c1d6;
> +
> +    private int f(
> +        int    u,
> +        int    v,
> +        int    w)
> +    {
> +        return ((u & v) | ((~u) & w));
> +    }
> +
> +    private int h(
> +        int    u,
> +        int    v,
> +        int    w)
> +    {
> +        return (u ^ v ^ w);
> +    }
> +
> +    private int g(
> +        int    u,
> +        int    v,
> +        int    w)
> +    {
> +        return ((u & v) | (u & w) | (v & w));
> +    }
> +
> +    protected void processBlock()
> +    {
> +        //
> +        // expand 16 word block into 80 word block.
> +        //
> +        for (int i = 16; i < 80; i++)
> +        {
> +            int t = X[i - 3] ^ X[i - 8] ^ X[i - 14] ^ X[i - 16];
> +            X[i] = t << 1 | t >>> 31;
> +        }
> +
> +        //
> +        // set up working variables.
> +        //
> +        int     A = H1;
> +        int     B = H2;
> +        int     C = H3;
> +        int     D = H4;
> +        int     E = H5;
> +
> +        //
> +        // round 1
> +        //
> +        int idx = 0;
> +
> +        for (int j = 0; j < 4; j++)
> +        {
> +            // E = rotateLeft(A, 5) + f(B, C, D) + E + X[idx++] + Y1
> +            // B = rotateLeft(B, 30)
> +            E += (A << 5 | A >>> 27) + f(B, C, D) + X[idx++] + Y1;
> +            B = B << 30 | B >>> 2;
> +
> +            D += (E << 5 | E >>> 27) + f(A, B, C) + X[idx++] + Y1;
> +            A = A << 30 | A >>> 2;
> +
> +            C += (D << 5 | D >>> 27) + f(E, A, B) + X[idx++] + Y1;
> +            E = E << 30 | E >>> 2;
> +
> +            B += (C << 5 | C >>> 27) + f(D, E, A) + X[idx++] + Y1;
> +            D = D << 30 | D >>> 2;
> +
> +            A += (B << 5 | B >>> 27) + f(C, D, E) + X[idx++] + Y1;
> +            C = C << 30 | C >>> 2;
> +        }
> +
> +        //
> +        // round 2
> +        //
> +        for (int j = 0; j < 4; j++)
> +        {
> +            // E = rotateLeft(A, 5) + h(B, C, D) + E + X[idx++] + Y2
> +            // B = rotateLeft(B, 30)
> +            E += (A << 5 | A >>> 27) + h(B, C, D) + X[idx++] + Y2;
> +            B = B << 30 | B >>> 2;
> +
> +            D += (E << 5 | E >>> 27) + h(A, B, C) + X[idx++] + Y2;
> +            A = A << 30 | A >>> 2;
> +
> +            C += (D << 5 | D >>> 27) + h(E, A, B) + X[idx++] + Y2;
> +            E = E << 30 | E >>> 2;
> +
> +            B += (C << 5 | C >>> 27) + h(D, E, A) + X[idx++] + Y2;
> +            D = D << 30 | D >>> 2;
> +
> +            A += (B << 5 | B >>> 27) + h(C, D, E) + X[idx++] + Y2;
> +            C = C << 30 | C >>> 2;
> +        }
> +
> +        //
> +        // round 3
> +        //
> +        for (int j = 0; j < 4; j++)
> +        {
> +            // E = rotateLeft(A, 5) + g(B, C, D) + E + X[idx++] + Y3
> +            // B = rotateLeft(B, 30)
> +            E += (A << 5 | A >>> 27) + g(B, C, D) + X[idx++] + Y3;
> +            B = B << 30 | B >>> 2;
> +
> +            D += (E << 5 | E >>> 27) + g(A, B, C) + X[idx++] + Y3;
> +            A = A << 30 | A >>> 2;
> +
> +            C += (D << 5 | D >>> 27) + g(E, A, B) + X[idx++] + Y3;
> +            E = E << 30 | E >>> 2;
> +
> +            B += (C << 5 | C >>> 27) + g(D, E, A) + X[idx++] + Y3;
> +            D = D << 30 | D >>> 2;
> +
> +            A += (B << 5 | B >>> 27) + g(C, D, E) + X[idx++] + Y3;
> +            C = C << 30 | C >>> 2;
> +        }
> +
> +        //
> +        // round 4
> +        //
> +        for (int j = 0; j <= 3; j++)
> +        {
> +            // E = rotateLeft(A, 5) + h(B, C, D) + E + X[idx++] + Y4
> +            // B = rotateLeft(B, 30)
> +            E += (A << 5 | A >>> 27) + h(B, C, D) + X[idx++] + Y4;
> +            B = B << 30 | B >>> 2;
> +
> +            D += (E << 5 | E >>> 27) + h(A, B, C) + X[idx++] + Y4;
> +            A = A << 30 | A >>> 2;
> +
> +            C += (D << 5 | D >>> 27) + h(E, A, B) + X[idx++] + Y4;
> +            E = E << 30 | E >>> 2;
> +
> +            B += (C << 5 | C >>> 27) + h(D, E, A) + X[idx++] + Y4;
> +            D = D << 30 | D >>> 2;
> +
> +            A += (B << 5 | B >>> 27) + h(C, D, E) + X[idx++] + Y4;
> +            C = C << 30 | C >>> 2;
> +        }
> +
> +
> +        H1 += A;
> +        H2 += B;
> +        H3 += C;
> +        H4 += D;
> +        H5 += E;
> +
> +        //
> +        // reset start of the buffer.
> +        //
> +        xOff = 0;
> +        for (int i = 0; i < 16; i++)
> +        {
> +            X[i] = 0;
> +        }
> +    }
> +}
> +
> +
> +
> +
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/SHA1Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/SHA1Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/digests/SHA1Digest.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/engines/DESEngine.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/engines/ 
> DESEngine.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/DESEngine.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/DESEngine.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,494 @@
> +package org.apache.geronimo.util.crypto.engines;
> +
> +import org.apache.geronimo.util.crypto.BlockCipher;
> +import org.apache.geronimo.util.crypto.CipherParameters;
> +import org.apache.geronimo.util.crypto.DataLengthException;
> +import org.apache.geronimo.util.crypto.params.KeyParameter;
> +
> +/**
> + * a class that provides a basic DES engine.
> + */
> +public class DESEngine
> +    implements BlockCipher
> +{
> +    protected static final int  BLOCK_SIZE = 8;
> +
> +    private int[]               workingKey = null;
> +
> +    /**
> +     * standard constructor.
> +     */
> +    public DESEngine()
> +    {
> +    }
> +
> +    /**
> +     * initialise a DES cipher.
> +     *
> +     * @param encrypting whether or not we are for encryption.
> +     * @param params the parameters required to set up the cipher.
> +     * @exception IllegalArgumentException if the params argument is
> +     * inappropriate.
> +     */
> +    public void init(
> +        boolean           encrypting,
> +        CipherParameters  params)
> +    {
> +        if (params instanceof KeyParameter)
> +        {
> +            if (((KeyParameter)params).getKey().length > 8)
> +            {
> +                throw new IllegalArgumentException("DES key too  
> long - should be 8 bytes");
> +            }
> +
> +            workingKey = generateWorkingKey(encrypting,
> +                                  ((KeyParameter)params).getKey());
> +
> +            return;
> +        }
> +
> +        throw new IllegalArgumentException("invalid parameter  
> passed to DES init - " + params.getClass().getName());
> +    }
> +
> +    public String getAlgorithmName()
> +    {
> +        return "DES";
> +    }
> +
> +    public int getBlockSize()
> +    {
> +        return BLOCK_SIZE;
> +    }
> +
> +    public int processBlock(
> +        byte[] in,
> +        int inOff,
> +        byte[] out,
> +        int outOff)
> +    {
> +        if (workingKey == null)
> +        {
> +            throw new IllegalStateException("DES engine not  
> initialised");
> +        }
> +
> +        if ((inOff + BLOCK_SIZE) > in.length)
> +        {
> +            throw new DataLengthException("input buffer too short");
> +        }
> +
> +        if ((outOff + BLOCK_SIZE) > out.length)
> +        {
> +            throw new DataLengthException("output buffer too short");
> +        }
> +
> +        desFunc(workingKey, in, inOff, out, outOff);
> +
> +        return BLOCK_SIZE;
> +    }
> +
> +    public void reset()
> +    {
> +    }
> +
> +    /**
> +     * what follows is mainly taken from "Applied Cryptography", by
> +     * Bruce Schneier, however it also bears great resemblance to  
> Richard
> +     * Outerbridge's D3DES...
> +     */
> +
> +    private static final short[]    Df_Key =
> +        {
> +            0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
> +            0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
> +            0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
> +        };
> +
> +    private static final short[]    bytebit =
> +        {
> +            0200, 0100, 040, 020, 010, 04, 02, 01
> +        };
> +
> +    private static final int[]    bigbyte =
> +        {
> +            0x800000, 0x400000, 0x200000, 0x100000,
> +            0x80000,  0x40000,  0x20000,  0x10000,
> +            0x8000,      0x4000,   0x2000,   0x1000,
> +            0x800,    0x400,    0x200,    0x100,
> +            0x80,      0x40,        0x20,     0x10,
> +            0x8,      0x4,      0x2,      0x1
> +        };
> +
> +    /*
> +     * Use the key schedule specified in the Standard (ANSI  
> X3.92-1981).
> +     */
> +
> +    private static final byte[]    pc1 =
> +        {
> +            56, 48, 40, 32, 24, 16,  8,   0, 57, 49, 41, 33, 25, 17,
> +             9,  1, 58, 50, 42, 34, 26,  18, 10,  2, 59, 51, 43, 35,
> +            62, 54, 46, 38, 30, 22, 14,   6, 61, 53, 45, 37, 29, 21,
> +            13,  5, 60, 52, 44, 36, 28,  20, 12,  4, 27, 19, 11,  3
> +        };
> +
> +    private static final byte[] totrot =
> +        {
> +            1, 2, 4, 6, 8, 10, 12, 14,
> +            15, 17, 19, 21, 23, 25, 27, 28
> +        };
> +
> +    private static final byte[] pc2 =
> +        {
> +            13, 16, 10, 23,  0,  4,  2, 27, 14,  5, 20,  9,
> +            22, 18, 11,  3, 25,  7, 15,  6, 26, 19, 12,  1,
> +            40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,
> +            43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31
> +        };
> +
> +    private static final int[] SP1 = {
> +        0x01010400, 0x00000000, 0x00010000, 0x01010404,
> +        0x01010004, 0x00010404, 0x00000004, 0x00010000,
> +        0x00000400, 0x01010400, 0x01010404, 0x00000400,
> +        0x01000404, 0x01010004, 0x01000000, 0x00000004,
> +        0x00000404, 0x01000400, 0x01000400, 0x00010400,
> +        0x00010400, 0x01010000, 0x01010000, 0x01000404,
> +        0x00010004, 0x01000004, 0x01000004, 0x00010004,
> +        0x00000000, 0x00000404, 0x00010404, 0x01000000,
> +        0x00010000, 0x01010404, 0x00000004, 0x01010000,
> +        0x01010400, 0x01000000, 0x01000000, 0x00000400,
> +        0x01010004, 0x00010000, 0x00010400, 0x01000004,
> +        0x00000400, 0x00000004, 0x01000404, 0x00010404,
> +        0x01010404, 0x00010004, 0x01010000, 0x01000404,
> +        0x01000004, 0x00000404, 0x00010404, 0x01010400,
> +        0x00000404, 0x01000400, 0x01000400, 0x00000000,
> +        0x00010004, 0x00010400, 0x00000000, 0x01010004
> +    };
> +
> +    private static final int[] SP2 = {
> +        0x80108020, 0x80008000, 0x00008000, 0x00108020,
> +        0x00100000, 0x00000020, 0x80100020, 0x80008020,
> +        0x80000020, 0x80108020, 0x80108000, 0x80000000,
> +        0x80008000, 0x00100000, 0x00000020, 0x80100020,
> +        0x00108000, 0x00100020, 0x80008020, 0x00000000,
> +        0x80000000, 0x00008000, 0x00108020, 0x80100000,
> +        0x00100020, 0x80000020, 0x00000000, 0x00108000,
> +        0x00008020, 0x80108000, 0x80100000, 0x00008020,
> +        0x00000000, 0x00108020, 0x80100020, 0x00100000,
> +        0x80008020, 0x80100000, 0x80108000, 0x00008000,
> +        0x80100000, 0x80008000, 0x00000020, 0x80108020,
> +        0x00108020, 0x00000020, 0x00008000, 0x80000000,
> +        0x00008020, 0x80108000, 0x00100000, 0x80000020,
> +        0x00100020, 0x80008020, 0x80000020, 0x00100020,
> +        0x00108000, 0x00000000, 0x80008000, 0x00008020,
> +        0x80000000, 0x80100020, 0x80108020, 0x00108000
> +    };
> +
> +    private static final int[] SP3 = {
> +        0x00000208, 0x08020200, 0x00000000, 0x08020008,
> +        0x08000200, 0x00000000, 0x00020208, 0x08000200,
> +        0x00020008, 0x08000008, 0x08000008, 0x00020000,
> +        0x08020208, 0x00020008, 0x08020000, 0x00000208,
> +        0x08000000, 0x00000008, 0x08020200, 0x00000200,
> +        0x00020200, 0x08020000, 0x08020008, 0x00020208,
> +        0x08000208, 0x00020200, 0x00020000, 0x08000208,
> +        0x00000008, 0x08020208, 0x00000200, 0x08000000,
> +        0x08020200, 0x08000000, 0x00020008, 0x00000208,
> +        0x00020000, 0x08020200, 0x08000200, 0x00000000,
> +        0x00000200, 0x00020008, 0x08020208, 0x08000200,
> +        0x08000008, 0x00000200, 0x00000000, 0x08020008,
> +        0x08000208, 0x00020000, 0x08000000, 0x08020208,
> +        0x00000008, 0x00020208, 0x00020200, 0x08000008,
> +        0x08020000, 0x08000208, 0x00000208, 0x08020000,
> +        0x00020208, 0x00000008, 0x08020008, 0x00020200
> +    };
> +
> +    private static final int[] SP4 = {
> +        0x00802001, 0x00002081, 0x00002081, 0x00000080,
> +        0x00802080, 0x00800081, 0x00800001, 0x00002001,
> +        0x00000000, 0x00802000, 0x00802000, 0x00802081,
> +        0x00000081, 0x00000000, 0x00800080, 0x00800001,
> +        0x00000001, 0x00002000, 0x00800000, 0x00802001,
> +        0x00000080, 0x00800000, 0x00002001, 0x00002080,
> +        0x00800081, 0x00000001, 0x00002080, 0x00800080,
> +        0x00002000, 0x00802080, 0x00802081, 0x00000081,
> +        0x00800080, 0x00800001, 0x00802000, 0x00802081,
> +        0x00000081, 0x00000000, 0x00000000, 0x00802000,
> +        0x00002080, 0x00800080, 0x00800081, 0x00000001,
> +        0x00802001, 0x00002081, 0x00002081, 0x00000080,
> +        0x00802081, 0x00000081, 0x00000001, 0x00002000,
> +        0x00800001, 0x00002001, 0x00802080, 0x00800081,
> +        0x00002001, 0x00002080, 0x00800000, 0x00802001,
> +        0x00000080, 0x00800000, 0x00002000, 0x00802080
> +    };
> +
> +    private static final int[] SP5 = {
> +        0x00000100, 0x02080100, 0x02080000, 0x42000100,
> +        0x00080000, 0x00000100, 0x40000000, 0x02080000,
> +        0x40080100, 0x00080000, 0x02000100, 0x40080100,
> +        0x42000100, 0x42080000, 0x00080100, 0x40000000,
> +        0x02000000, 0x40080000, 0x40080000, 0x00000000,
> +        0x40000100, 0x42080100, 0x42080100, 0x02000100,
> +        0x42080000, 0x40000100, 0x00000000, 0x42000000,
> +        0x02080100, 0x02000000, 0x42000000, 0x00080100,
> +        0x00080000, 0x42000100, 0x00000100, 0x02000000,
> +        0x40000000, 0x02080000, 0x42000100, 0x40080100,
> +        0x02000100, 0x40000000, 0x42080000, 0x02080100,
> +        0x40080100, 0x00000100, 0x02000000, 0x42080000,
> +        0x42080100, 0x00080100, 0x42000000, 0x42080100,
> +        0x02080000, 0x00000000, 0x40080000, 0x42000000,
> +        0x00080100, 0x02000100, 0x40000100, 0x00080000,
> +        0x00000000, 0x40080000, 0x02080100, 0x40000100
> +    };
> +
> +    private static final int[] SP6 = {
> +        0x20000010, 0x20400000, 0x00004000, 0x20404010,
> +        0x20400000, 0x00000010, 0x20404010, 0x00400000,
> +        0x20004000, 0x00404010, 0x00400000, 0x20000010,
> +        0x00400010, 0x20004000, 0x20000000, 0x00004010,
> +        0x00000000, 0x00400010, 0x20004010, 0x00004000,
> +        0x00404000, 0x20004010, 0x00000010, 0x20400010,
> +        0x20400010, 0x00000000, 0x00404010, 0x20404000,
> +        0x00004010, 0x00404000, 0x20404000, 0x20000000,
> +        0x20004000, 0x00000010, 0x20400010, 0x00404000,
> +        0x20404010, 0x00400000, 0x00004010, 0x20000010,
> +        0x00400000, 0x20004000, 0x20000000, 0x00004010,
> +        0x20000010, 0x20404010, 0x00404000, 0x20400000,
> +        0x00404010, 0x20404000, 0x00000000, 0x20400010,
> +        0x00000010, 0x00004000, 0x20400000, 0x00404010,
> +        0x00004000, 0x00400010, 0x20004010, 0x00000000,
> +        0x20404000, 0x20000000, 0x00400010, 0x20004010
> +    };
> +
> +    private static final int[] SP7 = {
> +        0x00200000, 0x04200002, 0x04000802, 0x00000000,
> +        0x00000800, 0x04000802, 0x00200802, 0x04200800,
> +        0x04200802, 0x00200000, 0x00000000, 0x04000002,
> +        0x00000002, 0x04000000, 0x04200002, 0x00000802,
> +        0x04000800, 0x00200802, 0x00200002, 0x04000800,
> +        0x04000002, 0x04200000, 0x04200800, 0x00200002,
> +        0x04200000, 0x00000800, 0x00000802, 0x04200802,
> +        0x00200800, 0x00000002, 0x04000000, 0x00200800,
> +        0x04000000, 0x00200800, 0x00200000, 0x04000802,
> +        0x04000802, 0x04200002, 0x04200002, 0x00000002,
> +        0x00200002, 0x04000000, 0x04000800, 0x00200000,
> +        0x04200800, 0x00000802, 0x00200802, 0x04200800,
> +        0x00000802, 0x04000002, 0x04200802, 0x04200000,
> +        0x00200800, 0x00000000, 0x00000002, 0x04200802,
> +        0x00000000, 0x00200802, 0x04200000, 0x00000800,
> +        0x04000002, 0x04000800, 0x00000800, 0x00200002
> +    };
> +
> +    private static final int[] SP8 = {
> +        0x10001040, 0x00001000, 0x00040000, 0x10041040,
> +        0x10000000, 0x10001040, 0x00000040, 0x10000000,
> +        0x00040040, 0x10040000, 0x10041040, 0x00041000,
> +        0x10041000, 0x00041040, 0x00001000, 0x00000040,
> +        0x10040000, 0x10000040, 0x10001000, 0x00001040,
> +        0x00041000, 0x00040040, 0x10040040, 0x10041000,
> +        0x00001040, 0x00000000, 0x00000000, 0x10040040,
> +        0x10000040, 0x10001000, 0x00041040, 0x00040000,
> +        0x00041040, 0x00040000, 0x10041000, 0x00001000,
> +        0x00000040, 0x10040040, 0x00001000, 0x00041040,
> +        0x10001000, 0x00000040, 0x10000040, 0x10040000,
> +        0x10040040, 0x10000000, 0x00040000, 0x10001040,
> +        0x00000000, 0x10041040, 0x00040040, 0x10000040,
> +        0x10040000, 0x10001000, 0x10001040, 0x00000000,
> +        0x10041040, 0x00041000, 0x00041000, 0x00001040,
> +        0x00001040, 0x00040040, 0x10000000, 0x10041000
> +    };
> +
> +    /**
> +     * generate an integer based working key based on our secret key
> +     * and what we processing we are planning to do.
> +     *
> +     * Acknowledgements for this routine go to James Gillogly &  
> Phil Karn.
> +     *         (whoever, and wherever they are!).
> +     */
> +    protected int[] generateWorkingKey(
> +        boolean encrypting,
> +        byte[]  key)
> +    {
> +        int[]       newKey = new int[32];
> +        boolean[]   pc1m = new boolean[56],
> +                    pcr = new boolean[56];
> +
> +        for (int j = 0; j < 56; j++)
> +        {
> +            int    l = pc1[j];
> +
> +            pc1m[j] = ((key[l >>> 3] & bytebit[l & 07]) != 0);
> +        }
> +
> +        for (int i = 0; i < 16; i++)
> +        {
> +            int    l, m, n;
> +
> +            if (encrypting)
> +            {
> +                m = i << 1;
> +            }
> +            else
> +            {
> +                m = (15 - i) << 1;
> +            }
> +
> +            n = m + 1;
> +            newKey[m] = newKey[n] = 0;
> +
> +            for (int j = 0; j < 28; j++)
> +            {
> +                l = j + totrot[i];
> +                if (l < 28)
> +                {
> +                    pcr[j] = pc1m[l];
> +                }
> +                else
> +                {
> +                    pcr[j] = pc1m[l - 28];
> +                }
> +            }
> +
> +            for (int j = 28; j < 56; j++)
> +            {
> +                l = j + totrot[i];
> +                if (l < 56)
> +                {
> +                    pcr[j] = pc1m[l];
> +                }
> +                else
> +                {
> +                    pcr[j] = pc1m[l - 28];
> +                }
> +            }
> +
> +            for (int j = 0; j < 24; j++)
> +            {
> +                if (pcr[pc2[j]])
> +                {
> +                    newKey[m] |= bigbyte[j];
> +                }
> +
> +                if (pcr[pc2[j + 24]])
> +                {
> +                    newKey[n] |= bigbyte[j];
> +                }
> +            }
> +        }
> +
> +        //
> +        // store the processed key
> +        //
> +        for (int i = 0; i != 32; i += 2)
> +        {
> +            int    i1, i2;
> +
> +            i1 = newKey[i];
> +            i2 = newKey[i + 1];
> +
> +            newKey[i] = ((i1 & 0x00fc0000) << 6) | ((i1 &  
> 0x00000fc0) << 10)
> +                                   | ((i2 & 0x00fc0000) >>> 10) |  
> ((i2 & 0x00000fc0) >>> 6);
> +
> +            newKey[i + 1] = ((i1 & 0x0003f000) << 12) | ((i1 &  
> 0x0000003f) << 16)
> +                                   | ((i2 & 0x0003f000) >>> 4) |  
> (i2 & 0x0000003f);
> +        }
> +
> +        return newKey;
> +    }
> +
> +    /**
> +     * the DES engine.
> +     */
> +    protected void desFunc(
> +        int[]   wKey,
> +        byte[]  in,
> +        int     inOff,
> +        byte[]  out,
> +        int     outOff)
> +    {
> +        int     work, right, left;
> +
> +        left     = (in[inOff + 0] & 0xff) << 24;
> +        left    |= (in[inOff + 1] & 0xff) << 16;
> +        left    |= (in[inOff + 2] & 0xff) << 8;
> +        left    |= (in[inOff + 3] & 0xff);
> +
> +        right     = (in[inOff + 4] & 0xff) << 24;
> +        right    |= (in[inOff + 5] & 0xff) << 16;
> +        right    |= (in[inOff + 6] & 0xff) << 8;
> +        right    |= (in[inOff + 7] & 0xff);
> +
> +        work = ((left >>> 4) ^ right) & 0x0f0f0f0f;
> +        right ^= work;
> +        left ^= (work << 4);
> +        work = ((left >>> 16) ^ right) & 0x0000ffff;
> +        right ^= work;
> +        left ^= (work << 16);
> +        work = ((right >>> 2) ^ left) & 0x33333333;
> +        left ^= work;
> +        right ^= (work << 2);
> +        work = ((right >>> 8) ^ left) & 0x00ff00ff;
> +        left ^= work;
> +        right ^= (work << 8);
> +        right = ((right << 1) | ((right >>> 31) & 1)) & 0xffffffff;
> +        work = (left ^ right) & 0xaaaaaaaa;
> +        left ^= work;
> +        right ^= work;
> +        left = ((left << 1) | ((left >>> 31) & 1)) & 0xffffffff;
> +
> +        for (int round = 0; round < 8; round++)
> +        {
> +            int     fval;
> +
> +            work  = (right << 28) | (right >>> 4);
> +            work ^= wKey[round * 4 + 0];
> +            fval  = SP7[ work      & 0x3f];
> +            fval |= SP5[(work >>>  8) & 0x3f];
> +            fval |= SP3[(work >>> 16) & 0x3f];
> +            fval |= SP1[(work >>> 24) & 0x3f];
> +            work  = right ^ wKey[round * 4 + 1];
> +            fval |= SP8[ work      & 0x3f];
> +            fval |= SP6[(work >>>  8) & 0x3f];
> +            fval |= SP4[(work >>> 16) & 0x3f];
> +            fval |= SP2[(work >>> 24) & 0x3f];
> +            left ^= fval;
> +            work  = (left << 28) | (left >>> 4);
> +            work ^= wKey[round * 4 + 2];
> +            fval  = SP7[ work      & 0x3f];
> +            fval |= SP5[(work >>>  8) & 0x3f];
> +            fval |= SP3[(work >>> 16) & 0x3f];
> +            fval |= SP1[(work >>> 24) & 0x3f];
> +            work  = left ^ wKey[round * 4 + 3];
> +            fval |= SP8[ work      & 0x3f];
> +            fval |= SP6[(work >>>  8) & 0x3f];
> +            fval |= SP4[(work >>> 16) & 0x3f];
> +            fval |= SP2[(work >>> 24) & 0x3f];
> +            right ^= fval;
> +        }
> +
> +        right = (right << 31) | (right >>> 1);
> +        work = (left ^ right) & 0xaaaaaaaa;
> +        left ^= work;
> +        right ^= work;
> +        left = (left << 31) | (left >>> 1);
> +        work = ((left >>> 8) ^ right) & 0x00ff00ff;
> +        right ^= work;
> +        left ^= (work << 8);
> +        work = ((left >>> 2) ^ right) & 0x33333333;
> +        right ^= work;
> +        left ^= (work << 2);
> +        work = ((right >>> 16) ^ left) & 0x0000ffff;
> +        left ^= work;
> +        right ^= (work << 16);
> +        work = ((right >>> 4) ^ left) & 0x0f0f0f0f;
> +        left ^= work;
> +        right ^= (work << 4);
> +
> +        out[outOff + 0] = (byte)((right >>> 24) & 0xff);
> +        out[outOff + 1] = (byte)((right >>> 16) & 0xff);
> +        out[outOff + 2] = (byte)((right >>>  8) & 0xff);
> +        out[outOff + 3] = (byte)(right         & 0xff);
> +        out[outOff + 4] = (byte)((left >>> 24) & 0xff);
> +        out[outOff + 5] = (byte)((left >>> 16) & 0xff);
> +        out[outOff + 6] = (byte)((left >>>  8) & 0xff);
> +        out[outOff + 7] = (byte)(left         & 0xff);
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/engines/DESEngine.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/engines/DESEngine.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/engines/DESEngine.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/engines/DESedeEngine.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/engines/ 
> DESedeEngine.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/DESedeEngine.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/engines/DESedeEngine.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,126 @@
> +package org.apache.geronimo.util.crypto.engines;
> +
> +import org.apache.geronimo.util.crypto.CipherParameters;
> +import org.apache.geronimo.util.crypto.DataLengthException;
> +import org.apache.geronimo.util.crypto.params.KeyParameter;
> +
> +/**
> + * a class that provides a basic DESede (or Triple DES) engine.
> + */
> +public class DESedeEngine
> +    extends DESEngine
> +{
> +    protected static final int  BLOCK_SIZE = 8;
> +
> +    private int[]               workingKey1 = null;
> +    private int[]               workingKey2 = null;
> +    private int[]               workingKey3 = null;
> +
> +    private boolean             forEncryption;
> +
> +    /**
> +     * standard constructor.
> +     */
> +    public DESedeEngine()
> +    {
> +    }
> +
> +    /**
> +     * initialise a DESede cipher.
> +     *
> +     * @param encrypting whether or not we are for encryption.
> +     * @param params the parameters required to set up the cipher.
> +     * @exception IllegalArgumentException if the params argument is
> +     * inappropriate.
> +     */
> +    public void init(
> +        boolean           encrypting,
> +        CipherParameters  params)
> +    {
> +        if (!(params instanceof KeyParameter))
> +        {
> +            throw new IllegalArgumentException("invalid parameter  
> passed to DESede init - " + params.getClass().getName());
> +        }
> +
> +        byte[]      keyMaster = ((KeyParameter)params).getKey();
> +        byte[]      key1 = new byte[8], key2 = new byte[8], key3 =  
> new byte[8];
> +
> +        if (keyMaster.length > 24)
> +        {
> +            throw new IllegalArgumentException("key size greater  
> than 24 bytes");
> +        }
> +
> +        this.forEncryption = encrypting;
> +
> +        if (keyMaster.length == 24)
> +        {
> +            System.arraycopy(keyMaster, 0, key1, 0, key1.length);
> +            System.arraycopy(keyMaster, 8, key2, 0, key2.length);
> +            System.arraycopy(keyMaster, 16, key3, 0, key3.length);
> +
> +            workingKey1 = generateWorkingKey(encrypting, key1);
> +            workingKey2 = generateWorkingKey(!encrypting, key2);
> +            workingKey3 = generateWorkingKey(encrypting, key3);
> +        }
> +        else    // 16 byte key
> +        {
> +            System.arraycopy(keyMaster, 0, key1, 0, key1.length);
> +            System.arraycopy(keyMaster, 8, key2, 0, key2.length);
> +
> +            workingKey1 = generateWorkingKey(encrypting, key1);
> +            workingKey2 = generateWorkingKey(!encrypting, key2);
> +            workingKey3 = workingKey1;
> +        }
> +    }
> +
> +    public String getAlgorithmName()
> +    {
> +        return "DESede";
> +    }
> +
> +    public int getBlockSize()
> +    {
> +        return BLOCK_SIZE;
> +    }
> +
> +    public int processBlock(
> +        byte[] in,
> +        int inOff,
> +        byte[] out,
> +        int outOff)
> +    {
> +        if (workingKey1 == null)
> +        {
> +            throw new IllegalStateException("DESede engine not  
> initialised");
> +        }
> +
> +        if ((inOff + BLOCK_SIZE) > in.length)
> +        {
> +            throw new DataLengthException("input buffer too short");
> +        }
> +
> +        if ((outOff + BLOCK_SIZE) > out.length)
> +        {
> +            throw new DataLengthException("output buffer too short");
> +        }
> +
> +        if (forEncryption)
> +        {
> +            desFunc(workingKey1, in, inOff, out, outOff);
> +            desFunc(workingKey2, out, outOff, out, outOff);
> +            desFunc(workingKey3, out, outOff, out, outOff);
> +        }
> +        else
> +        {
> +            desFunc(workingKey3, in, inOff, out, outOff);
> +            desFunc(workingKey2, out, outOff, out, outOff);
> +            desFunc(workingKey1, out, outOff, out, outOff);
> +        }
> +
> +        return BLOCK_SIZE;
> +    }
> +
> +    public void reset()
> +    {
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/engines/DESedeEngine.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/engines/DESedeEngine.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/engines/DESedeEngine.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/modes/CBCBlockCipher.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/modes/ 
> CBCBlockCipher.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/modes/CBCBlockCipher.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/modes/CBCBlockCipher.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,250 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.modes;
> +
> +import org.apache.geronimo.util.crypto.BlockCipher;
> +import org.apache.geronimo.util.crypto.CipherParameters;
> +import org.apache.geronimo.util.crypto.DataLengthException;
> +import org.apache.geronimo.util.crypto.params.ParametersWithIV;
> +
> +/**
> + * implements Cipher-Block-Chaining (CBC) mode on top of a simple  
> cipher.
> + */
> +public class CBCBlockCipher
> +    implements BlockCipher
> +{
> +    private byte[]          IV;
> +    private byte[]          cbcV;
> +    private byte[]          cbcNextV;
> +
> +    private int             blockSize;
> +    private BlockCipher     cipher = null;
> +    private boolean         encrypting;
> +
> +    /**
> +     * Basic constructor.
> +     *
> +     * @param cipher the block cipher to be used as the basis of  
> chaining.
> +     */
> +    public CBCBlockCipher(
> +        BlockCipher cipher)
> +    {
> +        this.cipher = cipher;
> +        this.blockSize = cipher.getBlockSize();
> +
> +        this.IV = new byte[blockSize];
> +        this.cbcV = new byte[blockSize];
> +        this.cbcNextV = new byte[blockSize];
> +    }
> +
> +    /**
> +     * return the underlying block cipher that we are wrapping.
> +     *
> +     * @return the underlying block cipher that we are wrapping.
> +     */
> +    public BlockCipher getUnderlyingCipher()
> +    {
> +        return cipher;
> +    }
> +
> +    /**
> +     * Initialise the cipher and, possibly, the initialisation  
> vector (IV).
> +     * If an IV isn't passed as part of the parameter, the IV will  
> be all zeros.
> +     *
> +     * @param encrypting if true the cipher is initialised for
> +     *  encryption, if false for decryption.
> +     * @param params the key and other data required by the cipher.
> +     * @exception IllegalArgumentException if the params argument is
> +     * inappropriate.
> +     */
> +    public void init(
> +        boolean             encrypting,
> +        CipherParameters    params)
> +        throws IllegalArgumentException
> +    {
> +        this.encrypting = encrypting;
> +
> +        if (params instanceof ParametersWithIV)
> +        {
> +                ParametersWithIV ivParam = (ParametersWithIV)params;
> +                byte[]      iv = ivParam.getIV();
> +
> +                if (iv.length != blockSize)
> +                {
> +                    throw new IllegalArgumentException 
> ("initialisation vector must be the same length as block size");
> +                }
> +
> +                System.arraycopy(iv, 0, IV, 0, iv.length);
> +
> +                reset();
> +
> +                cipher.init(encrypting, ivParam.getParameters());
> +        }
> +        else
> +        {
> +                reset();
> +
> +                cipher.init(encrypting, params);
> +        }
> +    }
> +
> +    /**
> +     * return the algorithm name and mode.
> +     *
> +     * @return the name of the underlying algorithm followed by "/ 
> CBC".
> +     */
> +    public String getAlgorithmName()
> +    {
> +        return cipher.getAlgorithmName() + "/CBC";
> +    }
> +
> +    /**
> +     * return the block size of the underlying cipher.
> +     *
> +     * @return the block size of the underlying cipher.
> +     */
> +    public int getBlockSize()
> +    {
> +        return cipher.getBlockSize();
> +    }
> +
> +    /**
> +     * Process one block of input from the array in and write it to
> +     * the out array.
> +     *
> +     * @param in the array containing the input data.
> +     * @param inOff offset into the in array the data starts at.
> +     * @param out the array the output data will be copied into.
> +     * @param outOff the offset into the out array the output will  
> start at.
> +     * @exception DataLengthException if there isn't enough data  
> in in, or
> +     * space in out.
> +     * @exception IllegalStateException if the cipher isn't  
> initialised.
> +     * @return the number of bytes processed and produced.
> +     */
> +    public int processBlock(
> +        byte[]      in,
> +        int         inOff,
> +        byte[]      out,
> +        int         outOff)
> +        throws DataLengthException, IllegalStateException
> +    {
> +        return (encrypting) ? encryptBlock(in, inOff, out,  
> outOff) : decryptBlock(in, inOff, out, outOff);
> +    }
> +
> +    /**
> +     * reset the chaining vector back to the IV and reset the  
> underlying
> +     * cipher.
> +     */
> +    public void reset()
> +    {
> +        System.arraycopy(IV, 0, cbcV, 0, IV.length);
> +
> +        cipher.reset();
> +    }
> +
> +    /**
> +     * Do the appropriate chaining step for CBC mode encryption.
> +     *
> +     * @param in the array containing the data to be encrypted.
> +     * @param inOff offset into the in array the data starts at.
> +     * @param out the array the encrypted data will be copied into.
> +     * @param outOff the offset into the out array the output will  
> start at.
> +     * @exception DataLengthException if there isn't enough data  
> in in, or
> +     * space in out.
> +     * @exception IllegalStateException if the cipher isn't  
> initialised.
> +     * @return the number of bytes processed and produced.
> +     */
> +    private int encryptBlock(
> +        byte[]      in,
> +        int         inOff,
> +        byte[]      out,
> +        int         outOff)
> +        throws DataLengthException, IllegalStateException
> +    {
> +        if ((inOff + blockSize) > in.length)
> +        {
> +            throw new DataLengthException("input buffer too short");
> +        }
> +
> +        /*
> +         * XOR the cbcV and the input,
> +         * then encrypt the cbcV
> +         */
> +        for (int i = 0; i < blockSize; i++)
> +        {
> +            cbcV[i] ^= in[inOff + i];
> +        }
> +
> +        int length = cipher.processBlock(cbcV, 0, out, outOff);
> +
> +        /*
> +         * copy ciphertext to cbcV
> +         */
> +        System.arraycopy(out, outOff, cbcV, 0, cbcV.length);
> +
> +        return length;
> +    }
> +
> +    /**
> +     * Do the appropriate chaining step for CBC mode decryption.
> +     *
> +     * @param in the array containing the data to be decrypted.
> +     * @param inOff offset into the in array the data starts at.
> +     * @param out the array the decrypted data will be copied into.
> +     * @param outOff the offset into the out array the output will  
> start at.
> +     * @exception DataLengthException if there isn't enough data  
> in in, or
> +     * space in out.
> +     * @exception IllegalStateException if the cipher isn't  
> initialised.
> +     * @return the number of bytes processed and produced.
> +     */
> +    private int decryptBlock(
> +        byte[]      in,
> +        int         inOff,
> +        byte[]      out,
> +        int         outOff)
> +        throws DataLengthException, IllegalStateException
> +    {
> +        if ((inOff + blockSize) > in.length)
> +        {
> +            throw new DataLengthException("input buffer too short");
> +        }
> +
> +        System.arraycopy(in, inOff, cbcNextV, 0, blockSize);
> +
> +        int length = cipher.processBlock(in, inOff, out, outOff);
> +
> +        /*
> +         * XOR the cbcV and the output
> +         */
> +        for (int i = 0; i < blockSize; i++)
> +        {
> +            out[outOff + i] ^= cbcV[i];
> +        }
> +
> +        /*
> +         * swap the back up buffer into next position
> +         */
> +        byte[]  tmp;
> +
> +        tmp = cbcV;
> +        cbcV = cbcNextV;
> +        cbcNextV = tmp;
> +
> +        return length;
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/modes/CBCBlockCipher.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/modes/CBCBlockCipher.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/modes/CBCBlockCipher.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/params/DESParameters.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/params/ 
> DESParameters.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/DESParameters.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/DESParameters.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,124 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.params;
> +
> +public class DESParameters
> +    extends KeyParameter
> +{
> +    public DESParameters(
> +        byte[]  key)
> +    {
> +        super(key);
> +
> +        if (isWeakKey(key, 0))
> +        {
> +            throw new IllegalArgumentException("attempt to create  
> weak DES key");
> +        }
> +    }
> +
> +    /*
> +     * DES Key length in bytes.
> +     */
> +    static public final int DES_KEY_LENGTH = 8;
> +
> +    /*
> +     * Table of weak and semi-weak keys taken from Schneier pp281
> +     */
> +    static private final int N_DES_WEAK_KEYS = 16;
> +
> +    static private byte[] DES_weak_keys =
> +    {
> +        /* weak keys */
> +        (byte)0x01,(byte)0x01,(byte)0x01,(byte)0x01, (byte)0x01, 
> (byte)0x01,(byte)0x01,(byte)0x01,
> +        (byte)0x1f,(byte)0x1f,(byte)0x1f,(byte)0x1f, (byte)0x0e, 
> (byte)0x0e,(byte)0x0e,(byte)0x0e,
> +        (byte)0xe0,(byte)0xe0,(byte)0xe0,(byte)0xe0, (byte)0xf1, 
> (byte)0xf1,(byte)0xf1,(byte)0xf1,
> +        (byte)0xfe,(byte)0xfe,(byte)0xfe,(byte)0xfe, (byte)0xfe, 
> (byte)0xfe,(byte)0xfe,(byte)0xfe,
> +
> +        /* semi-weak keys */
> +        (byte)0x01,(byte)0xfe,(byte)0x01,(byte)0xfe, (byte)0x01, 
> (byte)0xfe,(byte)0x01,(byte)0xfe,
> +        (byte)0x1f,(byte)0xe0,(byte)0x1f,(byte)0xe0, (byte)0x0e, 
> (byte)0xf1,(byte)0x0e,(byte)0xf1,
> +        (byte)0x01,(byte)0xe0,(byte)0x01,(byte)0xe0, (byte)0x01, 
> (byte)0xf1,(byte)0x01,(byte)0xf1,
> +        (byte)0x1f,(byte)0xfe,(byte)0x1f,(byte)0xfe, (byte)0x0e, 
> (byte)0xfe,(byte)0x0e,(byte)0xfe,
> +        (byte)0x01,(byte)0x1f,(byte)0x01,(byte)0x1f, (byte)0x01, 
> (byte)0x0e,(byte)0x01,(byte)0x0e,
> +        (byte)0xe0,(byte)0xfe,(byte)0xe0,(byte)0xfe, (byte)0xf1, 
> (byte)0xfe,(byte)0xf1,(byte)0xfe,
> +        (byte)0xfe,(byte)0x01,(byte)0xfe,(byte)0x01, (byte)0xfe, 
> (byte)0x01,(byte)0xfe,(byte)0x01,
> +        (byte)0xe0,(byte)0x1f,(byte)0xe0,(byte)0x1f, (byte)0xf1, 
> (byte)0x0e,(byte)0xf1,(byte)0x0e,
> +        (byte)0xe0,(byte)0x01,(byte)0xe0,(byte)0x01, (byte)0xf1, 
> (byte)0x01,(byte)0xf1,(byte)0x01,
> +        (byte)0xfe,(byte)0x1f,(byte)0xfe,(byte)0x1f, (byte)0xfe, 
> (byte)0x0e,(byte)0xfe,(byte)0x0e,
> +        (byte)0x1f,(byte)0x01,(byte)0x1f,(byte)0x01, (byte)0x0e, 
> (byte)0x01,(byte)0x0e,(byte)0x01,
> +        (byte)0xfe,(byte)0xe0,(byte)0xfe,(byte)0xe0, (byte)0xfe, 
> (byte)0xf1,(byte)0xfe,(byte)0xf1
> +    };
> +
> +    /**
> +     * DES has 16 weak keys.  This method will check
> +     * if the given DES key material is weak or semi-weak.
> +     * Key material that is too short is regarded as weak.
> +     * <p>
> +     * See <a href="http://www.counterpane.com/applied.html">"Applied
> +     * Cryptography"</a> by Bruce Schneier for more information.
> +     *
> +     * @return true if the given DES key material is weak or semi- 
> weak,
> +     *     false otherwise.
> +     */
> +    public static boolean isWeakKey(
> +        byte[] key,
> +        int offset)
> +    {
> +        if (key.length - offset < DES_KEY_LENGTH)
> +        {
> +            throw new IllegalArgumentException("key material too  
> short.");
> +        }
> +
> +        nextkey: for (int i = 0; i < N_DES_WEAK_KEYS; i++)
> +        {
> +            for (int j = 0; j < DES_KEY_LENGTH; j++)
> +            {
> +                if (key[j + offset] != DES_weak_keys[i *  
> DES_KEY_LENGTH + j])
> +                {
> +                    continue nextkey;
> +                }
> +            }
> +
> +            return true;
> +        }
> +        return false;
> +    }
> +
> +    /**
> +     * DES Keys use the LSB as the odd parity bit.  This can
> +     * be used to check for corrupt keys.
> +     *
> +     * @param bytes the byte array to set the parity on.
> +     */
> +    public static void setOddParity(
> +        byte[] bytes)
> +    {
> +        for (int i = 0; i < bytes.length; i++)
> +        {
> +            int b = bytes[i];
> +            bytes[i] = (byte)((b & 0xfe) |
> +                            ((((b >> 1) ^
> +                            (b >> 2) ^
> +                            (b >> 3) ^
> +                            (b >> 4) ^
> +                            (b >> 5) ^
> +                            (b >> 6) ^
> +                            (b >> 7)) ^ 0x01) & 0x01));
> +        }
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/DESParameters.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/DESParameters.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/DESParameters.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/params/DESedeParameters.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/params/ 
> DESedeParameters.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/DESedeParameters.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/DESedeParameters.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,74 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.params;
> +
> +public class DESedeParameters
> +    extends DESParameters
> +{
> +    /*
> +     * DES-EDE Key length in bytes.
> +     */
> +    static public final int DES_EDE_KEY_LENGTH = 24;
> +
> +    public DESedeParameters(
> +        byte[]  key)
> +    {
> +        super(key);
> +
> +        if (isWeakKey(key, 0, key.length))
> +        {
> +            throw new IllegalArgumentException("attempt to create  
> weak DESede key");
> +        }
> +    }
> +
> +    /**
> +     * return true if the passed in key is a DES-EDE weak key.
> +     *
> +     * @param key bytes making up the key
> +     * @param offset offset into the byte array the key starts at
> +     * @param length number of bytes making up the key
> +     */
> +    public static boolean isWeakKey(
> +        byte[]  key,
> +        int     offset,
> +        int     length)
> +    {
> +        for (int i = offset; i < length; i += DES_KEY_LENGTH)
> +        {
> +            if (DESParameters.isWeakKey(key, i))
> +            {
> +                return true;
> +            }
> +        }
> +
> +        return false;
> +    }
> +
> +    /**
> +     * return true if the passed in key is a DES-EDE weak key.
> +     *
> +     * @param key bytes making up the key
> +     * @param offset offset into the byte array the key starts at
> +     */
> +    public static boolean isWeakKey(
> +        byte[]  key,
> +        int     offset)
> +    {
> +        return isWeakKey(key, offset, key.length - offset);
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/DESedeParameters.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/DESedeParameters.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/DESedeParameters.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
> Added: geronimo/server/trunk/modules/geronimo-util/src/main/java/ 
> org/apache/geronimo/util/crypto/params/ParametersWithIV.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ 
> geronimo-util/src/main/java/org/apache/geronimo/util/crypto/params/ 
> ParametersWithIV.java?view=auto&rev=521413
> ====================================================================== 
> ========
> --- geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/ParametersWithIV.java (added)
> +++ geronimo/server/trunk/modules/geronimo-util/src/main/java/org/ 
> apache/geronimo/util/crypto/params/ParametersWithIV.java Thu Mar 22  
> 12:32:38 2007
> @@ -0,0 +1,56 @@
> +/**
> + *  Licensed to the Apache Software Foundation (ASF) under one or  
> more
> + *  contributor license agreements.  See the NOTICE file  
> distributed with
> + *  this work for additional information regarding copyright  
> ownership.
> + *  The ASF licenses this file to You under the Apache License,  
> Version 2.0
> + *  (the "License"); you may not use this file except in  
> compliance with
> + *  the License.  You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + *  Unless required by applicable law or agreed to in writing,  
> software
> + *  distributed under the License is distributed on an "AS IS" BASIS,
> + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express  
> or implied.
> + *  See the License for the specific language governing  
> permissions and
> + *  limitations under the License.
> + */
> +
> +package org.apache.geronimo.util.crypto.params;
> +
> +import org.apache.geronimo.util.crypto.CipherParameters;
> +
> +public class ParametersWithIV
> +    implements CipherParameters
> +{
> +    private byte[]              iv;
> +    private CipherParameters    parameters;
> +
> +    public ParametersWithIV(
> +        CipherParameters    parameters,
> +        byte[]              iv)
> +    {
> +        this(parameters, iv, 0, iv.length);
> +    }
> +
> +    public ParametersWithIV(
> +        CipherParameters    parameters,
> +        byte[]              iv,
> +        int                 ivOff,
> +        int                 ivLen)
> +    {
> +        this.iv = new byte[ivLen];
> +        this.parameters = parameters;
> +
> +        System.arraycopy(iv, ivOff, this.iv, 0, ivLen);
> +    }
> +
> +    public byte[] getIV()
> +    {
> +        return iv;
> +    }
> +
> +    public CipherParameters getParameters()
> +    {
> +        return parameters;
> +    }
> +}
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/ParametersWithIV.java
> ---------------------------------------------------------------------- 
> --------
>     svn:eol-style = native
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/ParametersWithIV.java
> ---------------------------------------------------------------------- 
> --------
>     svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/modules/geronimo-util/src/main/ 
> java/org/apache/geronimo/util/crypto/params/ParametersWithIV.java
> ---------------------------------------------------------------------- 
> --------
>     svn:mime-type = text/plain
>
>


Mime
View raw message