aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_crypto_kdf.c
diff options
context:
space:
mode:
authorJeff Burdges <burdges@gnunet.org>2016-05-30 16:08:03 +0000
committerJeff Burdges <burdges@gnunet.org>2016-05-30 16:08:03 +0000
commit0c9e498f3d07a285e1a3db51a1c6f1049f022362 (patch)
tree2fd81392ee91b25b92ee73a1c59e2c597ce640be /src/util/test_crypto_kdf.c
parentafb40a6d7a49d2608b709d6e8863675a6a301c99 (diff)
downloadgnunet-0c9e498f3d07a285e1a3db51a1c6f1049f022362.tar.gz
gnunet-0c9e498f3d07a285e1a3db51a1c6f1049f022362.zip
Testcases for KDF mod n
Currently just that the result is smaller than n, maybe should do more.
Diffstat (limited to 'src/util/test_crypto_kdf.c')
-rw-r--r--src/util/test_crypto_kdf.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/util/test_crypto_kdf.c b/src/util/test_crypto_kdf.c
new file mode 100644
index 000000000..f75bafbb1
--- /dev/null
+++ b/src/util/test_crypto_kdf.c
@@ -0,0 +1,70 @@
1/*
2 Copyright (c) 2010 Jeffrey Burdges
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21*/
22
23/**
24 * @file src/util/test_crypt_kdf.c
25 * @brief Testcases for KDF mod n
26 * @author Jeffrey Burdges <burdges@gnunet.org>
27 */
28
29#include <gcrypt.h>
30
31#include "platform.h"
32#include "gnunet_crypto_lib.h"
33
34
35int
36main ()
37{
38#define RND_BLK_SIZE 4096
39 unsigned char rnd_blk[RND_BLK_SIZE];
40 int i;
41 gcry_mpi_t r,n;
42
43 GNUNET_log_setup ("test-crypto-kdf", "WARNING", NULL);
44
45 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
46 rnd_blk,
47 RND_BLK_SIZE);
48
49 /* test full domain hash size */
50 for (i=0; i<100; i++) {
51 gcry_mpi_scan (&n,
52 GCRYMPI_FMT_USG,
53 rnd_blk, RND_BLK_SIZE,
54 NULL);
55 GNUNET_CRYPTO_kdf_mod_mpi (&r, n,
56 "", 0,
57 "", 0,
58 "");
59 GNUNET_assert( 0 > gcry_mpi_cmp(r,n) );
60
61 /* Is it worth checking that it's not too small? */
62 /* GNUNET_assert (gcry_mpi_get_nbits(r) > 3*RND_BLK_SIZE/4); */
63 /* This test necessarily randomly fails with probability 2^(3 - RND_BLK_SIZE/4) */
64
65 gcry_mpi_release(n);
66 gcry_mpi_release(r);
67 }
68
69 return 0;
70}