X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fcrypto%2FDigest.java;h=c487ae895b73bd747191cfc90fc64d1b6e1a32b1;hb=4a23c660491a2418e138b261e230baa6cd284851;hp=15506fed5029c9fd7ca8d70b6c2272cb8e7e1684;hpb=4c1f76f2d51e8c0a8465a96d34ee201e35b00475;p=org.ibex.crypto.git diff --git a/src/org/ibex/crypto/Digest.java b/src/org/ibex/crypto/Digest.java index 15506fe..c487ae8 100644 --- a/src/org/ibex/crypto/Digest.java +++ b/src/org/ibex/crypto/Digest.java @@ -14,120 +14,75 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * AUTHORS OR COPYRIGHT HOLDER.S BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -package com.brian_web.crypto; +package org.ibex.crypto; /** * base implementation of MD4 family style digest as outlined in * "Handbook of Applied Cryptography", pages 344 - 347. */ -abstract class Digest -{ +public abstract class Digest { private byte[] xBuf; private int xBufOff; - private long byteCount; - /** - * Standard constructor - */ - protected Digest() - { - xBuf = new byte[4]; - xBufOff = 0; - } - - public void update( - byte in) - { + protected Digest() { xBuf = new byte[4]; xBufOff = 0; } + public void update(byte in) { xBuf[xBufOff++] = in; - - if (xBufOff == xBuf.length) - { + if (xBufOff == xBuf.length) { processWord(xBuf, 0); xBufOff = 0; } - byteCount++; } - public void update( - byte[] in, - int inOff, - int len) - { - // + public void update(byte[] in, int inOff, int len) { // fill the current word - // - while ((xBufOff != 0) && (len > 0)) - { + while ((xBufOff != 0) && (len > 0)) { update(in[inOff]); - inOff++; len--; } - // // process whole words. - // - while (len > xBuf.length) - { + while (len > xBuf.length) { processWord(in, inOff); - inOff += xBuf.length; len -= xBuf.length; byteCount += xBuf.length; } - // // load in the remainder. - // - while (len > 0) - { + while (len > 0) { update(in[inOff]); - inOff++; len--; } } - protected void finish() - { + protected void finish() { long bitLength = (byteCount << 3); - - // // add the pad bytes. - // update((byte)128); - - while (xBufOff != 0) - { - update((byte)0); - } - + while (xBufOff != 0) update((byte)0); processLength(bitLength); - processBlock(); } - public void reset() - { + public void reset() { byteCount = 0; - xBufOff = 0; - for ( int i = 0; i < xBuf.length; i++ ) { - xBuf[i] = 0; - } + for ( int i = 0; i < xBuf.length; i++) xBuf[i] = 0; } protected abstract void processWord(byte[] in, int inOff); - protected abstract void processLength(long bitLength); - protected abstract void processBlock(); + public abstract int getDigestSize(); + public abstract void doFinal(byte[] out, int outOff); }