Integer type name change.
[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 - 2001 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   SilcUInt32 hash_len;
28   SilcUInt32 block_len;
29
30   void (*init)(void *);
31   void (*update)(void *, unsigned char *, SilcUInt32);
32   void (*final)(void *, unsigned char *);
33   void (*transform)(SilcUInt32 *, unsigned char *);
34   SilcUInt32 (*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                     SilcUInt32, unsigned char *);
45 } *SilcHash;
46
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)
50
51 /* Default hash functions for silc_hash_register_default(). */
52 extern DLLAPI SilcHashObject silc_default_hash[];
53
54 /* Default HASH function in the SILC protocol */
55 #define SILC_DEFAULT_HASH "sha1"
56
57 /* Macros */
58
59 /* Following macros are used to implement the SILC Hash API. These
60    macros should be used instead of declaring functions by hand. */
61
62 /* Function names in SILC Hash modules. The name of the hash function
63    is appended into these names and used to the get correct symbol out
64    of the module. All SILC Hash API compliant modules has to support
65    these names as function names (use macros below to assure this). */
66 #define SILC_HASH_SIM_INIT "init"
67 #define SILC_HASH_SIM_UPDATE "update"
68 #define SILC_HASH_SIM_FINAL "final"
69 #define SILC_HASH_SIM_TRANSFORM "transform"
70 #define SILC_HASH_SIM_CONTEXT_LEN "context_len"
71
72 /* Macros that can be used to declare SILC Hash API functions. */
73 #define SILC_HASH_API_INIT(hash)                \
74 void silc_##hash##_init(void *context)
75 #define SILC_HASH_API_UPDATE(hash)                              \
76 void silc_##hash##_update(void *context, unsigned char *data,   \
77                                         SilcUInt32 len)
78 #define SILC_HASH_API_FINAL(hash)                               \
79 void silc_##hash##_final(void *context, unsigned char *digest)
80 #define SILC_HASH_API_TRANSFORM(hash)                                   \
81 void silc_##hash##_transform(SilcUInt32 *state,                 \
82                                           unsigned char *buffer)
83 #define SILC_HASH_API_CONTEXT_LEN(hash)         \
84 SilcUInt32 silc_##hash##_context_len()
85
86 /* Prototypes */
87 bool silc_hash_register(SilcHashObject *hash);
88 bool silc_hash_unregister(SilcHashObject *hash);
89 bool silc_hash_register_default(void);
90 bool silc_hash_alloc(const unsigned char *name, SilcHash *new_hash);
91 void silc_hash_free(SilcHash hash);
92 SilcUInt32 silc_hash_len(SilcHash hash);
93 bool silc_hash_is_supported(const unsigned char *name);
94 char *silc_hash_get_supported(void);
95 void silc_hash_make(SilcHash hash, const unsigned char *data,
96                     SilcUInt32 len, unsigned char *return_hash);
97 char *silc_hash_fingerprint(SilcHash hash, const unsigned char *data,
98                             SilcUInt32 data_len);
99 char *silc_hash_babbleprint(SilcHash hash, const unsigned char *data,
100                             SilcUInt32 data_len);
101
102 #endif