diff options
Diffstat (limited to 'src/util/crypto_mpi.c')
-rw-r--r-- | src/util/crypto_mpi.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/src/util/crypto_mpi.c b/src/util/crypto_mpi.c index 14c672383..2c402e95a 100644 --- a/src/util/crypto_mpi.c +++ b/src/util/crypto_mpi.c | |||
@@ -11,12 +11,12 @@ | |||
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/crypto_mpi.c | 22 | * @file util/crypto_mpi.c |
@@ -29,14 +29,14 @@ | |||
29 | #include "gnunet_crypto_lib.h" | 29 | #include "gnunet_crypto_lib.h" |
30 | 30 | ||
31 | 31 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-mpi", __VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from(kind, "util-crypto-mpi", __VA_ARGS__) |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Log an error message at log-level 'level' that indicates | 35 | * Log an error message at log-level 'level' that indicates |
36 | * a failure of the command 'cmd' with the message given | 36 | * a failure of the command 'cmd' with the message given |
37 | * by gcry_strerror(rc). | 37 | * by gcry_strerror(rc). |
38 | */ | 38 | */ |
39 | #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0) | 39 | #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while (0) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
@@ -48,17 +48,17 @@ | |||
48 | * @param target target size of the buffer | 48 | * @param target target size of the buffer |
49 | */ | 49 | */ |
50 | static void | 50 | static void |
51 | adjust (void *buf, | 51 | adjust(void *buf, |
52 | size_t size, | 52 | size_t size, |
53 | size_t target) | 53 | size_t target) |
54 | { | 54 | { |
55 | char *p = buf; | 55 | char *p = buf; |
56 | 56 | ||
57 | if (size < target) | 57 | if (size < target) |
58 | { | 58 | { |
59 | memmove (&p[target - size], buf, size); | 59 | memmove(&p[target - size], buf, size); |
60 | memset (buf, 0, target - size); | 60 | memset(buf, 0, target - size); |
61 | } | 61 | } |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
@@ -72,46 +72,46 @@ adjust (void *buf, | |||
72 | * @param val value to write to @a buf | 72 | * @param val value to write to @a buf |
73 | */ | 73 | */ |
74 | void | 74 | void |
75 | GNUNET_CRYPTO_mpi_print_unsigned (void *buf, | 75 | GNUNET_CRYPTO_mpi_print_unsigned(void *buf, |
76 | size_t size, | 76 | size_t size, |
77 | gcry_mpi_t val) | 77 | gcry_mpi_t val) |
78 | { | 78 | { |
79 | size_t rsize; | 79 | size_t rsize; |
80 | int rc; | 80 | int rc; |
81 | 81 | ||
82 | if (gcry_mpi_get_flag (val, GCRYMPI_FLAG_OPAQUE)) | 82 | if (gcry_mpi_get_flag(val, GCRYMPI_FLAG_OPAQUE)) |
83 | { | 83 | { |
84 | /* Store opaque MPIs left aligned into the buffer. */ | 84 | /* Store opaque MPIs left aligned into the buffer. */ |
85 | unsigned int nbits; | 85 | unsigned int nbits; |
86 | const void *p; | 86 | const void *p; |
87 | 87 | ||
88 | p = gcry_mpi_get_opaque (val, &nbits); | 88 | p = gcry_mpi_get_opaque(val, &nbits); |
89 | GNUNET_assert (p); | 89 | GNUNET_assert(p); |
90 | rsize = (nbits+7)/8; | 90 | rsize = (nbits + 7) / 8; |
91 | if (rsize > size) | 91 | if (rsize > size) |
92 | rsize = size; | 92 | rsize = size; |
93 | GNUNET_memcpy (buf, p, rsize); | 93 | GNUNET_memcpy(buf, p, rsize); |
94 | if (rsize < size) | 94 | if (rsize < size) |
95 | memset (buf+rsize, 0, size - rsize); | 95 | memset(buf + rsize, 0, size - rsize); |
96 | } | 96 | } |
97 | else | 97 | else |
98 | { | ||
99 | /* Store regular MPIs as unsigned integers right aligned into | ||
100 | the buffer. */ | ||
101 | rsize = size; | ||
102 | if (0 != | ||
103 | (rc = gcry_mpi_print (GCRYMPI_FMT_USG, | ||
104 | buf, | ||
105 | rsize, &rsize, | ||
106 | val))) | ||
107 | { | 98 | { |
108 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, | 99 | /* Store regular MPIs as unsigned integers right aligned into |
109 | "gcry_mpi_print", | 100 | the buffer. */ |
110 | rc); | 101 | rsize = size; |
111 | GNUNET_assert (0); | 102 | if (0 != |
103 | (rc = gcry_mpi_print(GCRYMPI_FMT_USG, | ||
104 | buf, | ||
105 | rsize, &rsize, | ||
106 | val))) | ||
107 | { | ||
108 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, | ||
109 | "gcry_mpi_print", | ||
110 | rc); | ||
111 | GNUNET_assert(0); | ||
112 | } | ||
113 | adjust(buf, rsize, size); | ||
112 | } | 114 | } |
113 | adjust (buf, rsize, size); | ||
114 | } | ||
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
@@ -125,21 +125,21 @@ GNUNET_CRYPTO_mpi_print_unsigned (void *buf, | |||
125 | * @param size number of bytes in @a data | 125 | * @param size number of bytes in @a data |
126 | */ | 126 | */ |
127 | void | 127 | void |
128 | GNUNET_CRYPTO_mpi_scan_unsigned (gcry_mpi_t *result, | 128 | GNUNET_CRYPTO_mpi_scan_unsigned(gcry_mpi_t *result, |
129 | const void *data, | 129 | const void *data, |
130 | size_t size) | 130 | size_t size) |
131 | { | 131 | { |
132 | int rc; | 132 | int rc; |
133 | 133 | ||
134 | if (0 != (rc = gcry_mpi_scan (result, | 134 | if (0 != (rc = gcry_mpi_scan(result, |
135 | GCRYMPI_FMT_USG, | 135 | GCRYMPI_FMT_USG, |
136 | data, size, &size))) | 136 | data, size, &size))) |
137 | { | 137 | { |
138 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, | 138 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, |
139 | "gcry_mpi_scan", | 139 | "gcry_mpi_scan", |
140 | rc); | 140 | rc); |
141 | GNUNET_assert (0); | 141 | GNUNET_assert(0); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | /* end of crypto_mpi.c */ | 145 | /* end of crypto_mpi.c */ |