1 | /******************************************************************************
|
---|
2 | *
|
---|
3 | * Copyright (c) 1998-2000 by Mindbright Technology AB, Stockholm, Sweden.
|
---|
4 | * www.mindbright.se, [email protected]
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | *****************************************************************************
|
---|
17 | * $Author: mats $
|
---|
18 | * $Date: 2000/05/12 12:41:45 $
|
---|
19 | * $Name: rel1-2-1 $
|
---|
20 | *****************************************************************************/
|
---|
21 | package mindbright.security;
|
---|
22 |
|
---|
23 | public class NativeHashState extends MessageDigest {
|
---|
24 |
|
---|
25 | java.security.MessageDigest md;
|
---|
26 | String myAlg;
|
---|
27 |
|
---|
28 | public NativeHashState() {
|
---|
29 | }
|
---|
30 |
|
---|
31 | protected void init(String algorithm) throws Exception {
|
---|
32 | myAlg = algorithm;
|
---|
33 | if(algorithm.equals("SHA1"))
|
---|
34 | algorithm = "SHA";
|
---|
35 | md = java.security.MessageDigest.getInstance(algorithm);
|
---|
36 | }
|
---|
37 |
|
---|
38 | public String getName() {
|
---|
39 | return myAlg;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void reset() {
|
---|
43 | md.reset();
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void update(byte[] buffer, int offset, int length) {
|
---|
47 | md.update(buffer,offset,length);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public byte[] digest() {
|
---|
51 | return md.digest();
|
---|
52 | }
|
---|
53 |
|
---|
54 | public int blockSize() {
|
---|
55 | return 64;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public int hashSize() {
|
---|
59 | if(myAlg.equals("SHA")) {
|
---|
60 | return 20;
|
---|
61 | } else {
|
---|
62 | return 16;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|