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    unsigned int 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    unsigned int 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   unsigned int len;
67 } SilcHmacObject;
68
69 struct SilcHmacStruct {
70   SilcHmacObject *hmac;
71   SilcHash hash;
72   char allocated_hash;
73   unsigned char *key;
74   unsigned int key_len;
75 };
76
77 /* Prototypes */
78 int silc_hmac_register(SilcHmacObject *hmac);
79 int silc_hmac_unregister(SilcHmacObject *hmac);
80 int silc_hmac_alloc(char *name, SilcHash hash, SilcHmac *new_hmac);
81 void silc_hmac_free(SilcHmac hmac);
82 int silc_hmac_is_supported(const char *name);
83 char *silc_hmac_get_supported();
84 unsigned int silc_hmac_len(SilcHmac hmac);
85 void silc_hmac_set_key(SilcHmac hmac, const unsigned char *key,
86                        unsigned int key_len);
87 void silc_hmac_make(SilcHmac hmac, unsigned char *data,
88                     unsigned int data_len, unsigned char *return_hash,
89                     unsigned int *return_len);
90 void silc_hmac_make_with_key(SilcHmac hmac, unsigned char *data,
91                              unsigned int data_len, 
92                              unsigned char *key, unsigned int key_len,
93                              unsigned char *return_hash,
94                              unsigned int *return_len);
95 void silc_hmac_make_truncated(SilcHmac hmac, 
96                               unsigned char *data, 
97                               unsigned int data_len,
98                               unsigned int truncated_len,
99                               unsigned char *return_hash);
100
101 #endif