1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 * org.ibex.crypto.HMAC - By Brian Alliet
6 * Copyright (C) 2004 Brian Alliet
9 package org.ibex.crypto;
11 public class HMAC extends Digest {
12 private final Digest h;
13 private final byte[] digest;
14 private final byte[] k_ipad = new byte[64];
15 private final byte[] k_opad = new byte[64];
17 public int getDigestSize() { return h.getDigestSize(); }
18 public HMAC(Digest h, byte[] key) {
22 h.update(key,0,key.length);
23 key = new byte[h.getDigestSize()];
26 digest = new byte[h.getDigestSize()];
27 for(int i=0;i<64;i++) {
28 byte b = i < key.length ? key[i] : 0;
29 k_ipad[i] = (byte)(b ^ 0x36);
30 k_opad[i] = (byte)(b ^ 0x5C);
36 h.update(k_ipad,0,64);
38 public void update(byte[] b, int off, int len) { h.update(b,off,len); }
39 public void doFinal(byte[] out, int off){
41 h.update(k_opad,0,64);
42 h.update(digest,0,digest.length);
46 protected void processWord(byte[] in, int inOff) {}
47 protected void processLength(long bitLength) {}
48 protected void processBlock() {}