#include "ecc-curve.h"
#endif
+static int
+_digest_nettle(int algo, uint8_t* buf, size_t len,
+ unsigned char* res)
+{
+ switch(algo) {
+ case SHA1_DIGEST_SIZE:
+ {
+ struct sha1_ctx ctx;
+ sha1_init(&ctx);
+ sha1_update(&ctx, len, buf);
+ sha1_digest(&ctx, SHA1_DIGEST_SIZE, res);
+ return 1;
+ }
+ case SHA256_DIGEST_SIZE:
+ {
+ struct sha256_ctx ctx;
+ sha256_init(&ctx);
+ sha256_update(&ctx, len, buf);
+ sha256_digest(&ctx, SHA256_DIGEST_SIZE, res);
+ return 1;
+ }
+ case SHA384_DIGEST_SIZE:
+ {
+ struct sha384_ctx ctx;
+ sha384_init(&ctx);
+ sha384_update(&ctx, len, buf);
+ sha384_digest(&ctx, SHA384_DIGEST_SIZE, res);
+ return 1;
+ }
+ case SHA512_DIGEST_SIZE:
+ {
+ struct sha512_ctx ctx;
+ sha512_init(&ctx);
+ sha512_update(&ctx, len, buf);
+ sha512_digest(&ctx, SHA512_DIGEST_SIZE, res);
+ return 1;
+ }
+ default:
+ break;
+ }
+ return 0;
+}
+
/* return size of digest if supported, or 0 otherwise */
size_t
nsec3_hash_algo_size_supported(int id)
{
switch(algo) {
case NSEC3_HASH_SHA1:
- {
- struct sha1_ctx ctx;
- sha1_init(&ctx);
- sha1_update(&ctx, len, (uint8_t*)buf);
- sha1_digest(&ctx, SHA1_DIGEST_SIZE, (uint8_t*)res);
- }
- return 1;
+ return _digest_nettle(SHA1_DIGEST_SIZE, (uint8_t*)buf, len,
+ res);
default:
return 0;
}
return 0;
}
-
-
-static int
-_digest_nettle(int algo, uint8_t* buf, size_t len,
- unsigned char* res)
-{
- switch(algo) {
- case SHA1_DIGEST_SIZE:
- {
- struct sha1_ctx ctx;
- sha1_init(&ctx);
- sha1_update(&ctx, len, buf);
- sha1_digest(&ctx, SHA1_DIGEST_SIZE, res);
- return 1;
- }
- case SHA256_DIGEST_SIZE:
- {
- struct sha256_ctx ctx;
- sha256_init(&ctx);
- sha256_update(&ctx, len, buf);
- sha256_digest(&ctx, SHA256_DIGEST_SIZE, res);
- return 1;
- }
- case SHA384_DIGEST_SIZE:
- {
- struct sha384_ctx ctx;
- sha384_init(&ctx);
- sha384_update(&ctx, len, buf);
- sha384_digest(&ctx, SHA384_DIGEST_SIZE, res);
- return 1;
- }
- case SHA512_DIGEST_SIZE:
- {
- struct sha512_ctx ctx;
- sha512_init(&ctx);
- sha512_update(&ctx, len, buf);
- sha512_digest(&ctx, SHA512_DIGEST_SIZE, res);
- return 1;
- }
- default:
- break;
- }
- return 0;
-}
-
int
secalgo_ds_digest(int algo, unsigned char* buf, size_t len,
unsigned char* res)