Add `gnutls/dtls.h' to the distribution.
[gnutls.git] / tests / crypto_rng.c
blobfbeb10c5afa36f46def251fd869f1a265695021d
1 /*
2 * Copyright (C) 2008, 2010 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
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, see <http://www.gnu.org/licenses/>.
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <stdio.h>
29 #include "utils.h"
31 #include <gnutls/gnutls.h>
32 #include <gnutls/crypto.h>
33 #include "../lib/random.h"
35 static int
36 rng_init (void **ctx)
38 return 0;
41 static int
42 rng_rnd (void *ctx, int level, void *data, size_t datasize)
44 memset (data, 1, datasize);
45 return 0;
48 static void
49 rng_deinit (void *ctx)
53 void
54 doit (void)
56 int rc;
57 char buf1[32];
58 char buf2[32];
59 int failed = 0;
60 gnutls_crypto_rnd_st rng = { rng_init, rng_rnd, rng_deinit };
63 rc = gnutls_crypto_rnd_register (0, &rng);
65 gnutls_global_init ();
67 memset (buf2, 1, sizeof (buf2));
69 _gnutls_rnd (GNUTLS_RND_RANDOM, buf1, sizeof (buf1));
71 if (memcmp (buf1, buf2, sizeof (buf1)) != 0)
72 failed = 1;
74 gnutls_global_deinit ();
76 if (failed == 0)
78 success ("rng registered ok\n");
80 else
82 fail ("rng register test failed: %d\n", rc);