1 /*
2  * Copyright (c) 2009 Bob Deblier
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22 
23 #include "beecrypt/c++/lang/NullPointerException.h"
24 using beecrypt::lang::NullPointerException;
25 #include "beecrypt/c++/security/ProviderException.h"
26 using beecrypt::security::ProviderException;
27 #include "beecrypt/c++/provider/SHA224Digest.h"
28 
29 using namespace beecrypt::provider;
30 
SHA224Digest()31 SHA224Digest::SHA224Digest() : _digest(28)
32 {
33 	if (sha224Reset(&_param))
34 		throw ProviderException("BeeCrypt internal error in sha224Reset");
35 }
36 
~SHA224Digest()37 SHA224Digest::~SHA224Digest()
38 {
39 }
40 
clone() const41 SHA224Digest* SHA224Digest::clone() const throw ()
42 {
43 	SHA224Digest* result = new SHA224Digest();
44 
45 	memcpy(&result->_param, &_param, sizeof(sha224Param));
46 
47 	return result;
48 }
49 
engineDigest()50 const bytearray& SHA224Digest::engineDigest()
51 {
52 	if (sha224Digest(&_param, _digest.data()))
53 		throw ProviderException("BeeCrypt internal error in sha224Digest");
54 
55 	return _digest;
56 }
57 
engineDigest(byte * data,int offset,int length)58 int SHA224Digest::engineDigest(byte* data, int offset, int length) throw (ShortBufferException)
59 {
60 	if (!data)
61 		throw NullPointerException();
62 
63 	if (length < 32)
64 		throw ShortBufferException();
65 
66 	if (sha224Digest(&_param, data))
67 		throw ProviderException("BeeCrypt internal error in sha224Digest");
68 
69 	return 32;
70 }
71 
engineGetDigestLength()72 int SHA224Digest::engineGetDigestLength()
73 {
74 	return 32;
75 }
76 
engineReset()77 void SHA224Digest::engineReset()
78 {
79 	if (sha224Reset(&_param))
80 		throw ProviderException("BeeCrypt internal error in sha224Reset");
81 }
82 
engineUpdate(byte b)83 void SHA224Digest::engineUpdate(byte b)
84 {
85 	if (sha224Update(&_param, &b, 1))
86 		throw ProviderException("BeeCrypt internal error in sha224Update");
87 }
88 
engineUpdate(const byte * data,int offset,int length)89 void SHA224Digest::engineUpdate(const byte* data, int offset, int length)
90 {
91 	if (sha224Update(&_param, data+offset, length))
92 		throw ProviderException("BeeCrypt internal error in sha224Update");
93 }
94