updates.
[silc.git] / lib / silccrypt / silchmac.h
index d69822d06a2091fd7b919f0f5f145e8274122d35..532c1b68d162127ec2f8c8e623c0f51a9e72787c 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
 
-  Copyright (C) 1997 - 2000 Pekka Riikonen
+  Copyright (C) 1997 - 2001 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
    routines were created according to RFC2104. Following short description 
    of the fields:
 
-   SilcHash hash
+   SilcHmacObject:
 
-       The hash object to tell what hash function to use with this HMAC.
+   char *name
 
-   unsigned char *key
-   unsigned int len
+       Name of the HMAC.
 
-       The key and its length used to make the HMAC. This is set
-       with silc_hmac_set_key function.
+   uint32 len
+
+       Length of the MAC the HMAC is to produce (bytes).
 
-   void (*set_key)(SilcHmac, const unsigned char *, unsigned int)
 
-       Function used to set the key for the HMAC. Second argument is
-       the key to be set and last argument is the length of the key.
+   SilcHmac:
 
-   void (*make_hmac)(SilcHmac, unsigned char *, unsigned int,
-                     unsigned char *)
+   SilcHash hash
 
-       Function what is used to create HMAC's. User can also use directly
-       silc_hmac_make fuction. Although, one needs to allocate a SilcHmac
-       object before doing it, naturally. This uses the key set with
-       silc_hmac_set_key function.
+       The hash object to tell what hash function to use with this HMAC.
 
-   void (*make_hmac_with_key)(SilcHmac, unsigned char *, unsigned int,
-                              unsigned char *, unsigned int, unsigned char *)
+   char allocated_hash
 
-       Same function as above except that the key used in the HMAC
-       creation is sent as argument. The key set with silc_hmac_set_key
-       is ignored in this case.
+       TRUE if the `hash' was allocated and FALSE if it is static and
+       must not be freed.
 
-   void (*make_hmac_truncated)(SilcHmac, unsigned char *, unsigned int,
-                              unsigned int, unsigned char *)
+   unsigned char *key
+   uint32 len
 
-       Same function as above except that the output hash value is truncated
-       to the length sent as argument (second last argument). This makes
-       variable truncations possible, however, one should not truncate
-       hash values to less than half of the length of the hash value.
+       The key and its length used to make the HMAC. This is set
+       with silc_hmac_set_key function.
 
 */
 typedef struct SilcHmacStruct *SilcHmac;
 
+typedef struct {
+  char *name;
+  uint32 len;
+} SilcHmacObject;
+
 struct SilcHmacStruct {
+  SilcHmacObject *hmac;
   SilcHash hash;
+  char allocated_hash;
   unsigned char *key;
-  unsigned int key_len;
-  void (*set_key)(SilcHmac, const unsigned char *, unsigned int);
-  void (*make_hmac)(SilcHmac, unsigned char *, unsigned int,
-                   unsigned char *);
-  void (*make_hmac_with_key)(SilcHmac, unsigned char *, unsigned int,
-                            unsigned char *, unsigned int, unsigned char *);
-  void (*make_hmac_truncated)(SilcHmac, unsigned char *, 
-                             unsigned int, unsigned int, unsigned char *);
+  uint32 key_len;
 };
 
+/* Marks for all hmacs. This can be used in silc_hmac_unregister
+   to unregister all hmacs at once. */
+#define SILC_ALL_HMACS ((SilcHmacObject *)1)
+
+/* Default hmacs for silc_hmac_register_default(). */
+extern SilcHmacObject silc_default_hmacs[];
+
 /* Prototypes */
-int silc_hmac_alloc(SilcHash hash, SilcHmac *new_hmac);
+bool silc_hmac_register(SilcHmacObject *hmac);
+bool silc_hmac_unregister(SilcHmacObject *hmac);
+bool silc_hmac_register_default(void);
+bool silc_hmac_alloc(char *name, SilcHash hash, SilcHmac *new_hmac);
 void silc_hmac_free(SilcHmac hmac);
+bool silc_hmac_is_supported(const char *name);
+char *silc_hmac_get_supported(void);
+uint32 silc_hmac_len(SilcHmac hmac);
 void silc_hmac_set_key(SilcHmac hmac, const unsigned char *key,
-                      unsigned int key_len);
-void silc_hmac_make(SilcHmac hmac, 
-                   unsigned char *data, 
-                   unsigned int data_len,
-                   unsigned char *return_hash);
-void silc_hmac_make_with_key(SilcHmac hmac, 
-                            unsigned char *data, 
-                            unsigned int data_len,
-                            unsigned char *key, 
-                            unsigned int key_len, 
-                            unsigned char *return_hash);
+                      uint32 key_len);
+void silc_hmac_make(SilcHmac hmac, unsigned char *data,
+                   uint32 data_len, unsigned char *return_hash,
+                   uint32 *return_len);
+void silc_hmac_make_with_key(SilcHmac hmac, unsigned char *data,
+                            uint32 data_len, 
+                            unsigned char *key, uint32 key_len,
+                            unsigned char *return_hash,
+                            uint32 *return_len);
 void silc_hmac_make_truncated(SilcHmac hmac, 
                              unsigned char *data, 
-                             unsigned int data_len,
-                             unsigned int truncated_len,
+                             uint32 data_len,
+                             uint32 truncated_len,
                              unsigned char *return_hash);
 
 #endif