aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_crypto_abe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_crypto_abe.c')
-rw-r--r--src/util/test_crypto_abe.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/util/test_crypto_abe.c b/src/util/test_crypto_abe.c
new file mode 100644
index 000000000..cb36dccae
--- /dev/null
+++ b/src/util/test_crypto_abe.c
@@ -0,0 +1,86 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20*/
21/**
22 * @author Martin Schanzenbach
23 * @file util/test_crypto_abe.c
24 * @brief test for ABE ciphers
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28
29#define TESTSTRING "Hello World!"
30
31static int
32testAbecipher ()
33{
34 struct GNUNET_CRYPTO_AbeMasterKey *msk;
35 struct GNUNET_CRYPTO_AbeKey *key;
36 char *result;
37 char **attrs;
38 int size;
39 char *res;
40 msk = GNUNET_CRYPTO_cpabe_create_master_key ();
41 size = GNUNET_CRYPTO_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
42 "testattr", //Policy
43 msk,
44 (void*)&result);
45 GNUNET_assert (-1 != size);
46 attrs = GNUNET_malloc (2 * sizeof (char*));
47 attrs[0] = "testattr";
48 attrs[1] = NULL;
49 key = GNUNET_CRYPTO_cpabe_create_key (msk,
50 attrs);
51
52 size = GNUNET_CRYPTO_cpabe_decrypt (result, size,
53 key,
54 (void*)&res);
55 if (strlen (TESTSTRING) + 1 != size)
56 {
57 printf ("abeciphertest failed: decryptBlock returned %d\n", size);
58 return 1;
59 }
60 if (0 != strcmp (res, TESTSTRING))
61 {
62 printf ("abeciphertest failed: %s != %s\n", res, TESTSTRING);
63 return 1;
64 }
65 else
66 return 0;
67}
68
69
70int
71main (int argc, char *argv[])
72{
73 int failureCount = 0;
74
75 GNUNET_log_setup ("test-crypto-abe", "WARNING", NULL);
76 failureCount += testAbecipher ();
77
78 if (failureCount != 0)
79 {
80 printf ("%d TESTS FAILED!\n", failureCount);
81 return -1;
82 }
83 return 0;
84}
85
86/* end of test_crypto_aes.c */