5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
24 /* The default Silc hash object to represent any hash function in SILC. */
27 unsigned int hash_len;
28 unsigned int block_len;
31 void (*update)(void *, unsigned char *, unsigned int);
32 void (*final)(void *, unsigned char *);
33 void (*transform)(unsigned long *, unsigned char *);
34 unsigned int (*context_len)();
37 /* The main SILC hash structure. Use SilcHash instead of SilcHashStruct.
38 Also remember that SilcHash is a pointer. */
39 typedef struct SilcHashStruct {
43 void (*make_hash)(struct SilcHashStruct *, const unsigned char *,
44 unsigned int, unsigned char *);
47 extern struct SilcHashListStruct *silc_hash_list;
49 /* Marks for all hash functions. This can be used in silc_hash_unregister
50 to unregister all hash function at once. */
51 #define SILC_ALL_HASH_FUNCTIONS ((SilcHashObject *)1)
55 /* Following macros are used to implement the SILC Hash API. These
56 macros should be used instead of declaring functions by hand. */
58 /* Function names in SILC Hash modules. The name of the hash function
59 is appended into these names and used to the get correct symbol out
60 of the module. All SILC Hash API compliant modules has to support
61 these names as function names (use macros below to assure this). */
62 #define SILC_HASH_SIM_INIT "init"
63 #define SILC_HASH_SIM_UPDATE "update"
64 #define SILC_HASH_SIM_FINAL "final"
65 #define SILC_HASH_SIM_TRANSFORM "transform"
66 #define SILC_HASH_SIM_CONTEXT_LEN "context_len"
68 /* Macros that can be used to declare SILC Hash API functions. */
69 #define SILC_HASH_API_INIT(hash) \
70 void silc_##hash##_init(void *context)
71 #define SILC_HASH_API_UPDATE(hash) \
72 void silc_##hash##_update(void *context, unsigned char *data, \
74 #define SILC_HASH_API_FINAL(hash) \
75 void silc_##hash##_final(void *context, unsigned char *digest)
76 #define SILC_HASH_API_TRANSFORM(hash) \
77 void silc_##hash##_transform(unsigned long *state, \
78 unsigned char *buffer)
79 #define SILC_HASH_API_CONTEXT_LEN(hash) \
80 unsigned int silc_##hash##_context_len()
83 int silc_hash_register(SilcHashObject *hash);
84 int silc_hash_unregister(SilcHashObject *hash);
85 int silc_hash_alloc(const unsigned char *name, SilcHash *new_hash);
86 void silc_hash_free(SilcHash hash);
87 int silc_hash_is_supported(const unsigned char *name);
88 char *silc_hash_get_supported();
89 void silc_hash_make(SilcHash hash, const unsigned char *data,
90 unsigned int len, unsigned char *return_hash);
91 char *silc_hash_fingerprint(SilcHash hash, const unsigned char *data,
92 unsigned int data_len);