5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 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. */
31 void (*update)(void *, unsigned char *, uint32);
32 void (*final)(void *, unsigned char *);
33 void (*transform)(uint32 *, unsigned char *);
34 uint32 (*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 uint32, unsigned char *);
47 /* Marks for all hash functions. This can be used in silc_hash_unregister
48 to unregister all hash function at once. */
49 #define SILC_ALL_HASH_FUNCTIONS ((SilcHashObject *)1)
51 /* Default hash functions for silc_hash_register_default(). */
52 extern SilcHashObject silc_default_hash[];
56 /* Following macros are used to implement the SILC Hash API. These
57 macros should be used instead of declaring functions by hand. */
59 /* Function names in SILC Hash modules. The name of the hash function
60 is appended into these names and used to the get correct symbol out
61 of the module. All SILC Hash API compliant modules has to support
62 these names as function names (use macros below to assure this). */
63 #define SILC_HASH_SIM_INIT "init"
64 #define SILC_HASH_SIM_UPDATE "update"
65 #define SILC_HASH_SIM_FINAL "final"
66 #define SILC_HASH_SIM_TRANSFORM "transform"
67 #define SILC_HASH_SIM_CONTEXT_LEN "context_len"
69 /* Macros that can be used to declare SILC Hash API functions. */
70 #define SILC_HASH_API_INIT(hash) \
71 void silc_##hash##_init(void *context)
72 #define SILC_HASH_API_UPDATE(hash) \
73 void silc_##hash##_update(void *context, unsigned char *data, \
75 #define SILC_HASH_API_FINAL(hash) \
76 void silc_##hash##_final(void *context, unsigned char *digest)
77 #define SILC_HASH_API_TRANSFORM(hash) \
78 void silc_##hash##_transform(uint32 *state, \
79 unsigned char *buffer)
80 #define SILC_HASH_API_CONTEXT_LEN(hash) \
81 uint32 silc_##hash##_context_len()
84 bool silc_hash_register(SilcHashObject *hash);
85 bool silc_hash_unregister(SilcHashObject *hash);
86 bool silc_hash_register_default(void);
87 bool silc_hash_alloc(const unsigned char *name, SilcHash *new_hash);
88 void silc_hash_free(SilcHash hash);
89 uint32 silc_hash_len(SilcHash hash);
90 bool silc_hash_is_supported(const unsigned char *name);
91 char *silc_hash_get_supported(void);
92 void silc_hash_make(SilcHash hash, const unsigned char *data,
93 uint32 len, unsigned char *return_hash);
94 char *silc_hash_fingerprint(SilcHash hash, const unsigned char *data,