Added SILC MAC API, removed the SILC HMAC API.
[crypto.git] / lib / silccrypt / silccrypto.c
1 /*
2
3   silccrypto.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2007 - 2008 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #include "silccrypto.h"
21
22 #ifndef SILC_SYMBIAN
23 SilcStack crypto_stack = NULL;          /* Crypto Toolkit's global stack */
24 #endif /* SILC_SYMBIAN */
25
26 /* Init crypto */
27
28 SilcBool silc_crypto_init(SilcStack stack)
29 {
30   SILC_LOG_DEBUG(("Initializing crypto"));
31
32 #ifndef SILC_SYMBIAN
33   /* Stack allocation is allowed to fail */
34   crypto_stack = silc_stack_alloc(0, stack);
35 #endif /* SILC_SYMBIAN */
36
37   /* Init crypto library */
38   if (!silc_cipher_register_default()) {
39     SILC_LOG_ERROR(("Error registering ciphers"));
40     goto err;
41   }
42   if (!silc_hash_register_default()) {
43     SILC_LOG_ERROR(("Error registering hash functions"));
44     goto err;
45   }
46   if (!silc_mac_register_default()) {
47     SILC_LOG_ERROR(("Error registering hash HMACs"));
48     goto err;
49   }
50   if (!silc_pkcs_register_default()) {
51     SILC_LOG_ERROR(("Error registering hash PKCSs"));
52     goto err;
53   }
54
55 #ifdef SILC_DIST_ACC
56   /* Initialize accelerator library */
57 #endif /* SILC_DIST_ACC */
58
59   return TRUE;
60
61  err:
62   silc_crypto_uninit();
63   return FALSE;
64 }
65
66 /* Uninit crypto */
67
68 void silc_crypto_uninit(void)
69 {
70   SILC_LOG_DEBUG(("Uninitializing crypto"));
71
72 #ifdef SILC_DIST_ACC
73   /* Uninit accelerator library */
74 #endif /* SILC_DIST_ACC */
75
76   /* Uninit crypto library */
77   silc_pkcs_unregister_all();
78   silc_mac_unregister_all();
79   silc_hash_unregister_all();
80   silc_cipher_unregister_all();
81
82 #ifndef SILC_SYMBIAN
83   silc_stack_free(crypto_stack);
84 #endif /* SILC_SYMBIAN */
85 }
86
87 /* Return stack */
88
89 SilcStack silc_crypto_stack(void)
90 {
91 #ifndef SILC_SYMBIAN
92   return crypto_stack;
93 #else
94   return NULL;
95 #endif /* SILC_SYMBIAN */
96 }