20 #include <openssl/err.h>
21 #include <openssl/objects.h>
22 #include <openssl/sha.h>
90 d->method = toMethod(methodUri);
112 update(&data[0], (
unsigned int)data.size());
128 return OBJ_nid2sn(d->method);
138 case NID_sha1:
return SHA_DIGEST_LENGTH;
139 case NID_sha224:
return SHA224_DIGEST_LENGTH;
140 case NID_sha256:
return SHA256_DIGEST_LENGTH;
141 case NID_sha384:
return SHA384_DIGEST_LENGTH;
142 case NID_sha512:
return SHA512_DIGEST_LENGTH;
172 case NID_sha1: result = SHA1_Init(&d->sha1);
break;
173 case NID_sha224: result = SHA224_Init(&d->sha256);
break;
174 case NID_sha256: result = SHA256_Init(&d->sha256);
break;
175 case NID_sha384: result = SHA384_Init(&d->sha512);
break;
176 case NID_sha512: result = SHA512_Init(&d->sha512);
break;
181 THROW_IOEXCEPTION(
"Failed to initialize %s digest calculator: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
204 THROW_IOEXCEPTION(
"Digest method URI '%s' is not supported.", methodUri.c_str() );
245 if(!d->digest.empty())
251 case NID_sha1: result = SHA1_Update(&d->sha1, data, length);
break;
252 case NID_sha224: result = SHA224_Update(&d->sha256, data, length);
break;
253 case NID_sha256: result = SHA256_Update(&d->sha256, data, length);
break;
254 case NID_sha384: result = SHA384_Update(&d->sha512, data, length);
break;
255 case NID_sha512: result = SHA512_Update(&d->sha512, data, length);
break;
259 THROW_IOEXCEPTION(
"Failed to update %s digest value: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
272 if(!d->digest.empty())
276 unsigned char *
buf =
new unsigned char[getSize()];
279 case NID_sha1: result = SHA1_Final(
buf, &d->sha1);
break;
280 case NID_sha224: result = SHA224_Final(
buf, &d->sha256);
break;
281 case NID_sha256: result = SHA256_Final(
buf, &d->sha256);
break;
282 case NID_sha384: result = SHA384_Final(
buf, &d->sha512);
break;
283 case NID_sha512: result = SHA512_Final(
buf, &d->sha512);
break;
290 THROW_IOEXCEPTION(
"Failed to create %s digest: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
293 for(
unsigned int i = 0;
i < getSize();
i++)
294 d->digest.push_back(
buf[
i]);