More enum docs.
[gnutls.git] / tests / netconf-psk.c
blob6f82da679d16d5b5913dc7bb2d9490b9e9688dc1
1 /*
2 * Copyright (C) 2008, 2010 Free Software Foundation, Inc.
4 * Author: Simon Josefsson
6 * This file is part of GNUTLS.
8 * GNUTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GNUTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNUTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <unistd.h>
33 #include <gnutls/gnutls.h>
35 #include "utils.h"
37 static void
38 tls_log_func (int level, const char *str)
40 fprintf (stderr, "<%d>| %s", level, str);
43 void
44 doit (void)
46 const char *known =
47 "\x88\xf3\x82\x4b\x3e\x56\x59\xf5\x2d\x00"
48 "\xe9\x59\xba\xca\xb9\x54\xb6\x54\x03\x44";
49 gnutls_datum_t key = { NULL, 0 };
51 gnutls_global_init ();
53 gnutls_global_set_log_function (tls_log_func);
54 gnutls_global_set_log_level (2);
56 if (gnutls_psk_netconf_derive_key ("password", "psk_identity",
57 "psk_identity_hint", &key) == 0)
58 success ("success: gnutls_psk_netconf_derive_key\n");
59 else
60 fail ("gnutls_psk_netconf_derive_key failure\n");
62 if (debug)
63 hexprint (key.data, key.size);
65 if (key.size == 20 && memcmp (key.data, known, 20) == 0)
66 success ("success: match.\n");
67 else
68 fail ("FAIL: key differ.\n");
70 gnutls_free (key.data);
72 gnutls_global_deinit ();