-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);
-
- return true;
-}
-
-bool digest_open_by_name(digest_t *digest, const char *name) {
- int algo;
-
- if(!nametodigest(name, &algo)) {
- logger(LOG_DEBUG, _("Unknown digest name '%s'!"), name);
- return false;
- }
-
- return digest_open(digest, algo);
-}
-
-bool digest_open_by_nid(digest_t *digest, int nid) {
- int algo;
-
- if(!nidtodigest(nid, &algo)) {
- logger(LOG_DEBUG, _("Unknown digest ID %d!"), nid);
- return false;
- }
-
- return digest_open(digest, algo);
-}
-
-bool digest_open_sha1(digest_t *digest) {
- return digest_open(digest, GCRY_MD_SHA1);
-}
-
-void digest_close(digest_t *digest) {
-}
-
-bool digest_create(digest_t *digest, void *indata, size_t inlen, void *outdata) {
- gcry_md_hash_buffer(digest->algo, outdata, indata, inlen);
- return true;
-}
-
-bool digest_verify(digest_t *digest, void *indata, size_t inlen, void *cmpdata) {
- char outdata[digest->len];
-
- gcry_md_hash_buffer(digest->algo, outdata, indata, inlen);
- return !memcmp(indata, outdata, digest->len);
-}
-
-int digest_get_nid(const digest_t *digest) {
- return digest->nid;
-}
-
-size_t digest_length(const digest_t *digest) {
- return digest->len;
-}
-
-bool digest_active(const digest_t *digest) {
- return digest->algo != GCRY_MD_NONE;
-}