diff options
Diffstat (limited to 'src/util/test_crypto_rsa.c')
-rw-r--r-- | src/util/test_crypto_rsa.c | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index 36c47005e..0d8827c84 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014,2015 GNUnet e.V. | 3 | Copyright (C) 2014,2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file util/test_crypto_rsa.c | 22 | * @file util/test_crypto_rsa.c |
@@ -32,8 +32,8 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | int | 34 | int |
35 | main (int argc, | 35 | main(int argc, |
36 | char *argv[]) | 36 | char *argv[]) |
37 | { | 37 | { |
38 | #define RND_BLK_SIZE 4096 | 38 | #define RND_BLK_SIZE 4096 |
39 | unsigned char rnd_blk[RND_BLK_SIZE]; | 39 | unsigned char rnd_blk[RND_BLK_SIZE]; |
@@ -49,79 +49,79 @@ main (int argc, | |||
49 | char *blind_buf; | 49 | char *blind_buf; |
50 | size_t bsize; | 50 | size_t bsize; |
51 | 51 | ||
52 | GNUNET_log_setup ("test-rsa", "WARNING", NULL); | 52 | GNUNET_log_setup("test-rsa", "WARNING", NULL); |
53 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 53 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, |
54 | rnd_blk, | 54 | rnd_blk, |
55 | RND_BLK_SIZE); | 55 | RND_BLK_SIZE); |
56 | GNUNET_CRYPTO_hash (rnd_blk, | 56 | GNUNET_CRYPTO_hash(rnd_blk, |
57 | RND_BLK_SIZE, | 57 | RND_BLK_SIZE, |
58 | &hash); | 58 | &hash); |
59 | priv = GNUNET_CRYPTO_rsa_private_key_create (KEY_SIZE); | 59 | priv = GNUNET_CRYPTO_rsa_private_key_create(KEY_SIZE); |
60 | priv_copy = GNUNET_CRYPTO_rsa_private_key_dup (priv); | 60 | priv_copy = GNUNET_CRYPTO_rsa_private_key_dup(priv); |
61 | GNUNET_assert (NULL != priv_copy); | 61 | GNUNET_assert(NULL != priv_copy); |
62 | GNUNET_assert (0 == GNUNET_CRYPTO_rsa_private_key_cmp (priv, priv_copy)); | 62 | GNUNET_assert(0 == GNUNET_CRYPTO_rsa_private_key_cmp(priv, priv_copy)); |
63 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); | 63 | pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv); |
64 | 64 | ||
65 | /* Encoding */ | 65 | /* Encoding */ |
66 | size_t size; | 66 | size_t size; |
67 | char *enc; | 67 | char *enc; |
68 | enc = NULL; | 68 | enc = NULL; |
69 | size = GNUNET_CRYPTO_rsa_private_key_encode (priv, &enc); | 69 | size = GNUNET_CRYPTO_rsa_private_key_encode(priv, &enc); |
70 | 70 | ||
71 | /* Decoding */ | 71 | /* Decoding */ |
72 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 72 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
73 | priv = NULL; | 73 | priv = NULL; |
74 | priv = GNUNET_CRYPTO_rsa_private_key_decode (enc, size); | 74 | priv = GNUNET_CRYPTO_rsa_private_key_decode(enc, size); |
75 | GNUNET_assert (NULL != priv); | 75 | GNUNET_assert(NULL != priv); |
76 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 76 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, |
77 | enc, size); | 77 | enc, size); |
78 | GNUNET_assert (NULL == GNUNET_CRYPTO_rsa_private_key_decode (enc, size)); | 78 | GNUNET_assert(NULL == GNUNET_CRYPTO_rsa_private_key_decode(enc, size)); |
79 | (void) fprintf (stderr, "The above warning is expected.\n"); | 79 | (void)fprintf(stderr, "The above warning is expected.\n"); |
80 | GNUNET_free (enc); | 80 | GNUNET_free(enc); |
81 | 81 | ||
82 | /* try ordinary sig first */ | 82 | /* try ordinary sig first */ |
83 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, | 83 | sig = GNUNET_CRYPTO_rsa_sign_fdh(priv, |
84 | &hash); | 84 | &hash); |
85 | sig_copy = GNUNET_CRYPTO_rsa_signature_dup (sig); | 85 | sig_copy = GNUNET_CRYPTO_rsa_signature_dup(sig); |
86 | GNUNET_assert (NULL != sig); | 86 | GNUNET_assert(NULL != sig); |
87 | GNUNET_assert (0 == GNUNET_CRYPTO_rsa_signature_cmp (sig, sig_copy)); | 87 | GNUNET_assert(0 == GNUNET_CRYPTO_rsa_signature_cmp(sig, sig_copy)); |
88 | pub_copy = GNUNET_CRYPTO_rsa_public_key_dup (pub); | 88 | pub_copy = GNUNET_CRYPTO_rsa_public_key_dup(pub); |
89 | GNUNET_assert (NULL != pub_copy); | 89 | GNUNET_assert(NULL != pub_copy); |
90 | GNUNET_assert (GNUNET_OK == | 90 | GNUNET_assert(GNUNET_OK == |
91 | GNUNET_CRYPTO_rsa_verify (&hash, sig, pub_copy)); | 91 | GNUNET_CRYPTO_rsa_verify(&hash, sig, pub_copy)); |
92 | /* corrupt our hash and see if the signature is still valid */ | 92 | /* corrupt our hash and see if the signature is still valid */ |
93 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash, | 93 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &hash, |
94 | sizeof (struct GNUNET_HashCode)); | 94 | sizeof(struct GNUNET_HashCode)); |
95 | GNUNET_assert (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (&hash, | 95 | GNUNET_assert(GNUNET_OK != GNUNET_CRYPTO_rsa_verify(&hash, |
96 | sig, | 96 | sig, |
97 | pub)); | 97 | pub)); |
98 | (void) fprintf (stderr, "The above warning is expected.\n"); | 98 | (void)fprintf(stderr, "The above warning is expected.\n"); |
99 | GNUNET_CRYPTO_rsa_signature_free (sig); | 99 | GNUNET_CRYPTO_rsa_signature_free(sig); |
100 | 100 | ||
101 | /* test blind signing */ | 101 | /* test blind signing */ |
102 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 102 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, |
103 | &bsec, | 103 | &bsec, |
104 | sizeof (bsec)); | 104 | sizeof(bsec)); |
105 | GNUNET_CRYPTO_rsa_blind (&hash, | 105 | GNUNET_CRYPTO_rsa_blind(&hash, |
106 | &bsec, | 106 | &bsec, |
107 | pub, | 107 | pub, |
108 | &blind_buf,&bsize); | 108 | &blind_buf, &bsize); |
109 | GNUNET_assert (0 != bsize); | 109 | GNUNET_assert(0 != bsize); |
110 | bsig = GNUNET_CRYPTO_rsa_sign_blinded (priv, | 110 | bsig = GNUNET_CRYPTO_rsa_sign_blinded(priv, |
111 | blind_buf, | 111 | blind_buf, |
112 | bsize); | 112 | bsize); |
113 | GNUNET_free (blind_buf); | 113 | GNUNET_free(blind_buf); |
114 | sig = GNUNET_CRYPTO_rsa_unblind (bsig, | 114 | sig = GNUNET_CRYPTO_rsa_unblind(bsig, |
115 | &bsec, | 115 | &bsec, |
116 | pub); | 116 | pub); |
117 | GNUNET_CRYPTO_rsa_signature_free (bsig); | 117 | GNUNET_CRYPTO_rsa_signature_free(bsig); |
118 | GNUNET_assert (GNUNET_OK == | 118 | GNUNET_assert(GNUNET_OK == |
119 | GNUNET_CRYPTO_rsa_verify (&hash, sig, pub)); | 119 | GNUNET_CRYPTO_rsa_verify(&hash, sig, pub)); |
120 | GNUNET_CRYPTO_rsa_signature_free (sig); | 120 | GNUNET_CRYPTO_rsa_signature_free(sig); |
121 | GNUNET_CRYPTO_rsa_signature_free (sig_copy); | 121 | GNUNET_CRYPTO_rsa_signature_free(sig_copy); |
122 | GNUNET_CRYPTO_rsa_private_key_free (priv); | 122 | GNUNET_CRYPTO_rsa_private_key_free(priv); |
123 | GNUNET_CRYPTO_rsa_private_key_free (priv_copy); | 123 | GNUNET_CRYPTO_rsa_private_key_free(priv_copy); |
124 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 124 | GNUNET_CRYPTO_rsa_public_key_free(pub); |
125 | GNUNET_CRYPTO_rsa_public_key_free (pub_copy); | 125 | GNUNET_CRYPTO_rsa_public_key_free(pub_copy); |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |