2 * Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 and/or 3 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_BEECRYPT_H
18 #define H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_BEECRYPT_H
20 #include <beecrypt/beecrypt.h>
23 typedef hashFunction ensc_hash_method;
24 typedef hashFunctionContext ensc_hash_context;
27 ensc_crypto_init(void)
31 inline static ensc_hash_method const *
32 ensc_crypto_hash_get_default(void)
34 return hashFunctionDefault();
37 inline static ensc_hash_method const *
38 ensc_crypto_hash_find(char const *id_c)
40 char *id = strdupa(id_c);
50 while ((ptr=strchr(ptr, '-'))!=NULL)
51 memmove(ptr, ptr+1, strlen(ptr));
53 if (strcmp(id, "md2")==0)
55 else if (strcmp(id, "md5")==0)
57 else if (strcmp(id, "sha1")==0)
59 else if (strcasecmp(id, "sha256")==0)
62 /* sha-384 in beecrypt seems to be broken; digestsize is reported as
63 * 64 there although 48 is the correct value */
64 else if (strcasecmp(id, "sha384")==0)
67 else if (strcasecmp(id, "sha512")==0)
72 return hashFunctionFind(name);
75 inline static char const *
76 ensc_crypto_hash_get_name(ensc_hash_method const *m)
82 ensc_crypto_hash_get_digestsize(ensc_hash_method const *m)
90 ensc_crypto_hashctx_get_digestsize(ensc_hash_context const *ctx)
92 return ensc_crypto_hash_get_digestsize(ctx->algo);
96 ensc_crypto_hashctx_get_digest(ensc_hash_context *ctx, void *result,
97 size_t *res_len, size_t UNUSED max_res_len)
99 int rc = hashFunctionContextDigest(ctx, result);
101 *res_len = ctx->algo->digestsize;
107 ensc_crypto_hashctx_update(ensc_hash_context *ctx, void const *src, size_t len)
109 return hashFunctionContextUpdate(ctx, src, len);
113 ensc_crypto_hashctx_init(ensc_hash_context *ctx, ensc_hash_method const *m)
115 return hashFunctionContextInit(ctx, m);
119 ensc_crypto_hashctx_reset(ensc_hash_context *ctx)
121 return hashFunctionContextReset(ctx);
125 ensc_crypto_hashctx_free(ensc_hash_context *ctx)
127 hashFunctionContextFree(ctx);
130 #endif /* H_UTIL_VSERVER_LIB_INTERNAL_CRYPTO_WRAPPER_BEECRYPT_H */