diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-01-09 12:49:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-01-09 12:49:44 +0000 |
commit | 957037e37439b9378b1242270530db95b06a458c (patch) | |
tree | d17d7c0127f69a9ff317af4ee0e322000bdf4ea0 /src/util/crypto_hkdf.c | |
parent | 25744888266d74a3dbf444d6b1db2a8d46f9cdfb (diff) | |
download | gnunet-957037e37439b9378b1242270530db95b06a458c.tar.gz gnunet-957037e37439b9378b1242270530db95b06a458c.zip |
-revert 'optimization' that broke test_crypto_hkdf
Diffstat (limited to 'src/util/crypto_hkdf.c')
-rw-r--r-- | src/util/crypto_hkdf.c | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c index 1fc13ceaa..fa2bd1a69 100644 --- a/src/util/crypto_hkdf.c +++ b/src/util/crypto_hkdf.c | |||
@@ -87,11 +87,11 @@ doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf, | |||
87 | * @brief Generate pseudo-random key | 87 | * @brief Generate pseudo-random key |
88 | * @param mac gcrypt HMAC handle | 88 | * @param mac gcrypt HMAC handle |
89 | * @param xts salt | 89 | * @param xts salt |
90 | * @param xts_len length of the salt | 90 | * @param xts_len length of the @a xts salt |
91 | * @param skm source key material | 91 | * @param skm source key material |
92 | * @param skm_len length of skm | 92 | * @param skm_len length of @a skm |
93 | * @param prk result buffer (allocated by caller; at least gcry_md_dlen() bytes) | 93 | * @param prk result buffer (allocated by caller; at least gcry_md_dlen() bytes) |
94 | * @return GNUNET_YES on success | 94 | * @return #GNUNET_YES on success |
95 | */ | 95 | */ |
96 | static int | 96 | static int |
97 | getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm, | 97 | getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm, |
@@ -131,9 +131,9 @@ dump (const char *src, const void *p, unsigned int l) | |||
131 | * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_... | 131 | * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_... |
132 | * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_... | 132 | * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_... |
133 | * @param xts salt | 133 | * @param xts salt |
134 | * @param xts_len length of xts | 134 | * @param xts_len length of @a xts |
135 | * @param skm source key material | 135 | * @param skm source key material |
136 | * @param skm_len length of skm | 136 | * @param skm_len length of @a skm |
137 | * @param argp va_list of void * & size_t pairs for context chunks | 137 | * @param argp va_list of void * & size_t pairs for context chunks |
138 | * @return #GNUNET_YES on success | 138 | * @return #GNUNET_YES on success |
139 | */ | 139 | */ |
@@ -142,9 +142,8 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, | |||
142 | const void *xts, size_t xts_len, const void *skm, | 142 | const void *xts, size_t xts_len, const void *skm, |
143 | size_t skm_len, va_list argp) | 143 | size_t skm_len, va_list argp) |
144 | { | 144 | { |
145 | static int once; | 145 | gcry_md_hd_t xtr; |
146 | static gcry_md_hd_t xtr; | 146 | gcry_md_hd_t prf; |
147 | static gcry_md_hd_t prf; | ||
148 | const void *hc; | 147 | const void *hc; |
149 | unsigned long i; | 148 | unsigned long i; |
150 | unsigned long t; | 149 | unsigned long t; |
@@ -158,26 +157,15 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, | |||
158 | 157 | ||
159 | if (0 == k) | 158 | if (0 == k) |
160 | return GNUNET_SYSERR; | 159 | return GNUNET_SYSERR; |
161 | if (! once) | 160 | if (GPG_ERR_NO_ERROR != |
162 | { | 161 | gcry_md_open (&xtr, xtr_algo, GCRY_MD_FLAG_HMAC)) |
163 | if (GPG_ERR_NO_ERROR != | 162 | return GNUNET_SYSERR; |
164 | gcry_md_open (&xtr, xtr_algo, GCRY_MD_FLAG_HMAC)) | 163 | if (GPG_ERR_NO_ERROR != |
165 | return GNUNET_SYSERR; | 164 | gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC)) |
166 | |||
167 | if (GPG_ERR_NO_ERROR != | ||
168 | gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC)) | ||
169 | { | ||
170 | gcry_md_close (xtr); | ||
171 | return GNUNET_SYSERR; | ||
172 | } | ||
173 | once = 1; | ||
174 | } | ||
175 | else | ||
176 | { | 165 | { |
177 | gcry_md_reset (xtr); | 166 | gcry_md_close (xtr); |
178 | gcry_md_reset (prf); | 167 | return GNUNET_SYSERR; |
179 | } | 168 | } |
180 | |||
181 | va_copy (args, argp); | 169 | va_copy (args, argp); |
182 | 170 | ||
183 | ctx_len = 0; | 171 | ctx_len = 0; |
@@ -275,6 +263,8 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, | |||
275 | hkdf_error: | 263 | hkdf_error: |
276 | ret = GNUNET_SYSERR; | 264 | ret = GNUNET_SYSERR; |
277 | hkdf_ok: | 265 | hkdf_ok: |
266 | gcry_md_close (xtr); | ||
267 | gcry_md_close (prf); | ||
278 | return ret; | 268 | return ret; |
279 | } | 269 | } |
280 | 270 | ||