1 package beecrypt.provider;
2 
3 import java.security.*;
4 import java.nio.*;
5 
6 public final class SHA512 extends MessageDigestSpi {
7 	private long param;
8 
allocParam()9 	private static native long allocParam();
10 
cloneParam(long param)11 	private static native long cloneParam(long param);
12 
freeParam(long param)13 	private static native void freeParam(long param);
14 
digest(long param)15 	private static native byte[] digest(long param);
16 
digest(long param, byte[] buf, int off, int len)17 	private static native int digest(long param, byte[] buf, int off, int len)
18 			throws DigestException;
19 
reset(long param)20 	private static native void reset(long param);
21 
update(long param, byte input)22 	private static native void update(long param, byte input);
23 
update(long param, byte[] input, int off, int len)24 	private static native void update(long param, byte[] input, int off, int len);
25 
SHA512()26 	public SHA512() {
27 		param = allocParam();
28 	}
29 
SHA512(SHA512 copy)30 	public SHA512(SHA512 copy) {
31 		param = cloneParam(copy.param);
32 	}
33 
clone()34 	public Object clone() throws CloneNotSupportedException {
35 		return new SHA512(this);
36 	}
37 
engineDigest()38 	protected byte[] engineDigest() {
39 		return digest(param);
40 	}
41 
engineDigest(byte[] buf, int off, int len)42 	protected int engineDigest(byte[] buf, int off, int len)
43 			throws DigestException {
44 		return digest(param, buf, off, len);
45 	}
46 
engineGetDigestLength()47 	protected int engineGetDigestLength() {
48 		return 64;
49 	}
50 
engineReset()51 	protected void engineReset() {
52 		reset(param);
53 	}
54 
engineUpdate(byte input)55 	protected void engineUpdate(byte input) {
56 		update(param, input);
57 	}
58 
engineUpdate(byte[] input, int off, int len)59 	protected void engineUpdate(byte[] input, int off, int len) {
60 		update(param, input, off, len);
61 	}
62 
engineUpdate(ByteBuffer input)63 	protected void engineUpdate(ByteBuffer input) {
64 		update(param, input.array(), input.position(), input.remaining());
65 	}
66 
finalize()67 	protected void finalize() {
68 		freeParam(param);
69 	}
70 }
71