updates.
[silc.git] / lib / silccrypt / silchmac.h
1 /*
2
3   silchmac.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 SILCHMAC_H
22 #define SILCHMAC_H
23
24 /* 
25    SILC HMAC object. 
26    
27    This is the HMAC object to create keyed hash values for message
28    authentication. These routines uses already implemented hash functions.
29    HMAC's can be created using any hash function implemented in SILC. These
30    routines were created according to RFC2104. Following short description 
31    of the fields:
32
33    SilcHmacObject:
34
35    char *name
36
37        Name of the HMAC.
38
39    uint32 len
40
41        Length of the MAC the HMAC is to produce (bytes).
42
43
44    SilcHmac:
45
46    SilcHash hash
47
48        The hash object to tell what hash function to use with this HMAC.
49
50    char allocated_hash
51
52        TRUE if the `hash' was allocated and FALSE if it is static and
53        must not be freed.
54
55    unsigned char *key
56    uint32 len
57
58        The key and its length used to make the HMAC. This is set
59        with silc_hmac_set_key function.
60
61 */
62 typedef struct SilcHmacStruct *SilcHmac;
63
64 typedef struct {
65   char *name;
66   uint32 len;
67 } SilcHmacObject;
68
69 struct SilcHmacStruct {
70   SilcHmacObject *hmac;
71   SilcHash hash;
72   char allocated_hash;
73   unsigned char *key;
74   uint32 key_len;
75 };
76
77 /* Marks for all hmacs. This can be used in silc_hmac_unregister
78    to unregister all hmacs at once. */
79 #define SILC_ALL_HMACS ((SilcHmacObject *)1)
80
81 /* Default hmacs for silc_hmac_register_default(). */
82 extern SilcHmacObject silc_default_hmacs[];
83
84 /* Prototypes */
85 bool silc_hmac_register(SilcHmacObject *hmac);
86 bool silc_hmac_unregister(SilcHmacObject *hmac);
87 bool silc_hmac_register_default(void);
88 bool silc_hmac_alloc(char *name, SilcHash hash, SilcHmac *new_hmac);
89 void silc_hmac_free(SilcHmac hmac);
90 bool silc_hmac_is_supported(const char *name);
91 char *silc_hmac_get_supported(void);
92 uint32 silc_hmac_len(SilcHmac hmac);
93 void silc_hmac_set_key(SilcHmac hmac, const unsigned char *key,
94                        uint32 key_len);
95 void silc_hmac_make(SilcHmac hmac, unsigned char *data,
96                     uint32 data_len, unsigned char *return_hash,
97                     uint32 *return_len);
98 void silc_hmac_make_with_key(SilcHmac hmac, unsigned char *data,
99                              uint32 data_len, 
100                              unsigned char *key, uint32 key_len,
101                              unsigned char *return_hash,
102                              uint32 *return_len);
103 void silc_hmac_make_truncated(SilcHmac hmac, 
104                               unsigned char *data, 
105                               uint32 data_len,
106                               uint32 truncated_len,
107                               unsigned char *return_hash);
108
109 #endif