-#include "logger.h"
-
-static struct {
- const char *name;
- int algo;
- int nid;
-} digesttable[] = {
- {"none", GCRY_MD_NONE, 0},
- {"sha1", GCRY_MD_SHA1, 64},
- {"sha256", GCRY_MD_SHA256, 672},
- {"sha384", GCRY_MD_SHA384, 673},
- {"sha512", GCRY_MD_SHA512, 674},
-};
-
-static bool nametodigest(const char *name, int *algo) {
- int i;
-
- for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) {
- if(digesttable[i].name && !strcasecmp(name, digesttable[i].name)) {
- *algo = digesttable[i].algo;
- return true;
- }
- }
-
- return false;
-}
-
-static bool nidtodigest(int nid, int *algo) {
- int i;
-
- for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) {
- if(nid == digesttable[i].nid) {
- *algo = digesttable[i].algo;
- return true;
- }
- }
-
- return false;
-}
-
-static bool digesttonid(int algo, int *nid) {
- int i;
-
- for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) {
- if(algo == digesttable[i].algo) {
- *nid = digesttable[i].nid;
- return true;
- }
- }
-
- return false;
-}
-
-static bool digest_open(digest_t *digest, int algo) {
- if(!digesttonid(algo, &digest->nid)) {
- logger(LOG_DEBUG, _("Digest %d has no corresponding nid!"), algo);
- return false;
- }
-
- digest->len = gcry_md_get_algo_dlen(algo);