Initial revision
[silc.git] / lib / silccrypt / silchash.h
1 /*
2
3   silchash.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
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.
13   
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.
18
19 */
20
21 #ifndef SILCHASH_H
22 #define SILCHASH_H
23
24 /* The default Silc hash object to represent any hash function in SILC. */
25 typedef struct {
26   char *name;
27   unsigned int hash_len;
28   unsigned int block_len;
29
30   void (*init)(void *);
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)();
35 } SilcHashObject;
36
37 /* The main SILC hash structure. Use SilcHash instead of SilcHashStruct.
38    Also remember that SilcHash is a pointer. */
39 typedef struct SilcHashStruct {
40   SilcHashObject *hash;
41   void *context;
42
43   void (*make_hash)(struct SilcHashStruct *, const unsigned char *, 
44                     unsigned int, unsigned char *);
45 } *SilcHash;
46
47 extern struct SilcHashListStruct *silc_hash_list;
48
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)
52
53 /* Macros */
54
55 /* Following macros are used to implement the SILC Hash API. These
56    macros should be used instead of declaring functions by hand. */
57
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"
67
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,   \
73                                         unsigned int len)
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()
81
82 /* Prototypes */
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
92 #endif