5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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.
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
35 The hash object to tell what hash function to use with this HMAC.
40 The key and its length used to make the HMAC. This is set
41 with silc_hmac_set_key function.
43 void (*set_key)(SilcHmac, const unsigned char *, unsigned int)
45 Function used to set the key for the HMAC. Second argument is
46 the key to be set and last argument is the length of the key.
48 void (*make_hmac)(SilcHmac, unsigned char *, unsigned int,
51 Function what is used to create HMAC's. User can also use directly
52 silc_hmac_make fuction. Although, one needs to allocate a SilcHmac
53 object before doing it, naturally. This uses the key set with
54 silc_hmac_set_key function.
56 void (*make_hmac_with_key)(SilcHmac, unsigned char *, unsigned int,
57 unsigned char *, unsigned int, unsigned char *)
59 Same function as above except that the key used in the HMAC
60 creation is sent as argument. The key set with silc_hmac_set_key
61 is ignored in this case.
63 void (*make_hmac_truncated)(SilcHmac, unsigned char *, unsigned int,
64 unsigned int, unsigned char *)
66 Same function as above except that the output hash value is truncated
67 to the length sent as argument (second last argument). This makes
68 variable truncations possible, however, one should not truncate
69 hash values to less than half of the length of the hash value.
72 typedef struct SilcHmacStruct *SilcHmac;
74 struct SilcHmacStruct {
78 void (*set_key)(SilcHmac, const unsigned char *, unsigned int);
79 void (*make_hmac)(SilcHmac, unsigned char *, unsigned int,
81 void (*make_hmac_with_key)(SilcHmac, unsigned char *, unsigned int,
82 unsigned char *, unsigned int, unsigned char *);
83 void (*make_hmac_truncated)(SilcHmac, unsigned char *,
84 unsigned int, unsigned int, unsigned char *);
88 int silc_hmac_alloc(SilcHash hash, SilcHmac *new_hmac);
89 void silc_hmac_free(SilcHmac hmac);
90 void silc_hmac_set_key(SilcHmac hmac, const unsigned char *key,
91 unsigned int key_len);
92 void silc_hmac_make(SilcHmac hmac,
94 unsigned int data_len,
95 unsigned char *return_hash);
96 void silc_hmac_make_with_key(SilcHmac hmac,
98 unsigned int data_len,
100 unsigned int key_len,
101 unsigned char *return_hash);
102 void silc_hmac_make_truncated(SilcHmac hmac,
104 unsigned int data_len,
105 unsigned int truncated_len,
106 unsigned char *return_hash);