1 package org.bouncycastle.crypto.digests; 2 3 import org.bouncycastle.crypto.util.Pack; 4 5 6 /** 7 * FIPS 180-2 implementation of SHA-384. 8 * 9 * <pre> 10 * block word digest 11 * SHA-1 512 32 160 12 * SHA-256 512 32 256 13 * SHA-384 1024 64 384 14 * SHA-512 1024 64 512 15 * </pre> 16 */ 17 public class SHA384Digest 18 extends LongDigest 19 { 20 21 private static final int DIGEST_LENGTH = 48; 22 23 /** 24 * Standard constructor 25 */ SHA384Digest()26 public SHA384Digest() 27 { 28 } 29 30 /** 31 * Copy constructor. This will copy the state of the provided 32 * message digest. 33 */ SHA384Digest(SHA384Digest t)34 public SHA384Digest(SHA384Digest t) 35 { 36 super(t); 37 } 38 getAlgorithmName()39 public String getAlgorithmName() 40 { 41 return "SHA-384"; 42 } 43 getDigestSize()44 public int getDigestSize() 45 { 46 return DIGEST_LENGTH; 47 } 48 doFinal( byte[] out, int outOff)49 public int doFinal( 50 byte[] out, 51 int outOff) 52 { 53 finish(); 54 55 Pack.longToBigEndian(H1, out, outOff); 56 Pack.longToBigEndian(H2, out, outOff + 8); 57 Pack.longToBigEndian(H3, out, outOff + 16); 58 Pack.longToBigEndian(H4, out, outOff + 24); 59 Pack.longToBigEndian(H5, out, outOff + 32); 60 Pack.longToBigEndian(H6, out, outOff + 40); 61 62 reset(); 63 64 return DIGEST_LENGTH; 65 } 66 67 /** 68 * reset the chaining variables 69 */ reset()70 public void reset() 71 { 72 super.reset(); 73 74 /* SHA-384 initial hash value 75 * The first 64 bits of the fractional parts of the square roots 76 * of the 9th through 16th prime numbers 77 */ 78 H1 = 0xcbbb9d5dc1059ed8l; 79 H2 = 0x629a292a367cd507l; 80 H3 = 0x9159015a3070dd17l; 81 H4 = 0x152fecd8f70e5939l; 82 H5 = 0x67332667ffc00b31l; 83 H6 = 0x8eb44a8768581511l; 84 H7 = 0xdb0c2e0d64f98fa7l; 85 H8 = 0x47b5481dbefa4fa4l; 86 } 87 } 88