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 package org.ibex.crypto;
7 public class HMAC extends Digest {
8 private final Digest h;
9 private final byte[] digest;
10 private final byte[] k_ipad = new byte[64];
11 private final byte[] k_opad = new byte[64];
13 public int getDigestSize() { return h.getDigestSize(); }
14 public HMAC(Digest h, byte[] key) {
18 h.update(key,0,key.length);
19 key = new byte[h.getDigestSize()];
22 digest = new byte[h.getDigestSize()];
23 for(int i=0;i<64;i++) {
24 byte b = i < key.length ? key[i] : 0;
25 k_ipad[i] = (byte)(b ^ 0x36);
26 k_opad[i] = (byte)(b ^ 0x5C);
32 h.update(k_ipad,0,64);
34 public void update(byte[] b, int off, int len) { h.update(b,off,len); }
35 public void doFinal(byte[] out, int off){
37 h.update(k_opad,0,64);
38 h.update(digest,0,digest.length);
42 protected void processWord(byte[] in, int inOff) {}
43 protected void processLength(long bitLength) {}
44 protected void processBlock() {}