comparison src/ch/ethz/ssh2/crypto/digest/SHA256.java @ 273:91a31873c42a ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Fri, 18 Jul 2014 11:21:46 -0700
parents
children 071eccdff8ea
comparison
equal deleted inserted replaced
272:ce2f4e397703 273:91a31873c42a
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2.crypto.digest;
6
7 import java.security.DigestException;
8 import java.security.MessageDigest;
9 import java.security.NoSuchAlgorithmException;
10
11 /**
12 * @version $Id: SHA256.java 152 2014-04-28 11:02:23Z dkocher@sudo.ch $
13 */
14 public final class SHA256 implements Digest {
15
16 private MessageDigest md;
17
18 public SHA256() {
19 try {
20 md = MessageDigest.getInstance("SHA-256");
21 }
22 catch(NoSuchAlgorithmException e) {
23 throw new IllegalArgumentException(e);
24 }
25 }
26
27 public final int getDigestLength() {
28 return md.getDigestLength();
29 }
30
31 public final void reset() {
32 md.reset();
33 }
34
35 public final void update(byte b[]) {
36 this.update(b, 0, b.length);
37 }
38
39 public final void update(byte b[], int off, int len) {
40 md.update(b, off, len);
41 }
42
43 public final void update(byte b) {
44 md.update(b);
45 }
46
47 public final void digest(byte[] out) throws DigestException {
48 this.digest(out, 0);
49 }
50
51 public final void digest(byte[] out, int off) throws DigestException {
52 md.digest(out, off, out.length);
53 }
54 }