- switch (*hashtype) {
- case OPENPGP_HASH_MD5:
- md5_init(&md5_context);
- for (i = 0; i < chunks; i++) {
- md5_update(&md5_context, hashlen[i], hashdata[i]);
- }
- md5_digest(&md5_context, MD5_DIGEST_SIZE, hash);
- break;
- case OPENPGP_HASH_SHA1:
- sha1_init(&sha1_context);
- for (i = 0; i < chunks; i++) {
- sha1_update(&sha1_context, hashlen[i], hashdata[i]);
- }
- sha1_digest(&sha1_context, SHA1_DIGEST_SIZE, hash);
- break;
- case OPENPGP_HASH_SHA1X:
- sha1x_init(&sha1x_context);
- for (i = 0; i < chunks; i++) {
- sha1x_update(&sha1x_context, hashlen[i], hashdata[i]);
- }
- sha1x_digest(&sha1x_context, SHA1X_DIGEST_SIZE, hash);
- break;
-#ifdef HAVE_NETTLE
- case OPENPGP_HASH_RIPEMD160:
- ripemd160_init(&ripemd160_context);
- for (i = 0; i < chunks; i++) {
- ripemd160_update(&ripemd160_context, hashlen[i],
- hashdata[i]);
- }
- ripemd160_digest(&ripemd160_context, RIPEMD160_DIGEST_SIZE,
- hash);
- break;
- case OPENPGP_HASH_SHA224:
- sha224_init(&sha224_context);
- for (i = 0; i < chunks; i++) {
- sha224_update(&sha224_context, hashlen[i],
- hashdata[i]);
- }
- sha224_digest(&sha224_context, SHA224_DIGEST_SIZE, hash);
- break;
- case OPENPGP_HASH_SHA256:
- sha256_init(&sha256_context);
- for (i = 0; i < chunks; i++) {
- sha256_update(&sha256_context, hashlen[i],
- hashdata[i]);
- }
- sha256_digest(&sha256_context, SHA256_DIGEST_SIZE, hash);
- break;
- case OPENPGP_HASH_SHA384:
- sha384_init(&sha384_context);
- for (i = 0; i < chunks; i++) {
- sha384_update(&sha384_context, hashlen[i],
- hashdata[i]);
- }
- sha384_digest(&sha384_context, SHA384_DIGEST_SIZE, hash);
- break;
- case OPENPGP_HASH_SHA512:
- sha512_init(&sha512_context);
- for (i = 0; i < chunks; i++) {
- sha512_update(&sha512_context, hashlen[i],
- hashdata[i]);
- }
- sha512_digest(&sha512_context, SHA512_DIGEST_SIZE, hash);
- break;
-#endif
- default:
- return ONAK_E_UNSUPPORTED_FEATURE;
- }