crypto_digest.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /* Copyright (c) 2001, Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file crypto_digest.c
  8. * \brief Block of functions related with digest and xof utilities and
  9. * operations.
  10. **/
  11. #include "lib/container/smartlist.h"
  12. #include "lib/crypt_ops/crypto_digest.h"
  13. #include "lib/crypt_ops/crypto_openssl_mgt.h"
  14. #include "lib/crypt_ops/crypto_util.h"
  15. #include "lib/log/log.h"
  16. #include "lib/log/util_bug.h"
  17. #include "keccak-tiny/keccak-tiny.h"
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "lib/arch/bytes.h"
  21. DISABLE_GCC_WARNING(redundant-decls)
  22. #include <openssl/hmac.h>
  23. #include <openssl/sha.h>
  24. ENABLE_GCC_WARNING(redundant-decls)
  25. /* Crypto digest functions */
  26. /** Compute the SHA1 digest of the <b>len</b> bytes on data stored in
  27. * <b>m</b>. Write the DIGEST_LEN byte result into <b>digest</b>.
  28. * Return 0 on success, -1 on failure.
  29. */
  30. int
  31. crypto_digest(char *digest, const char *m, size_t len)
  32. {
  33. tor_assert(m);
  34. tor_assert(digest);
  35. if (SHA1((const unsigned char*)m,len,(unsigned char*)digest) == NULL)
  36. return -1;
  37. return 0;
  38. }
  39. /** Compute a 256-bit digest of <b>len</b> bytes in data stored in <b>m</b>,
  40. * using the algorithm <b>algorithm</b>. Write the DIGEST_LEN256-byte result
  41. * into <b>digest</b>. Return 0 on success, -1 on failure. */
  42. int
  43. crypto_digest256(char *digest, const char *m, size_t len,
  44. digest_algorithm_t algorithm)
  45. {
  46. tor_assert(m);
  47. tor_assert(digest);
  48. tor_assert(algorithm == DIGEST_SHA256 || algorithm == DIGEST_SHA3_256);
  49. int ret = 0;
  50. if (algorithm == DIGEST_SHA256)
  51. ret = (SHA256((const uint8_t*)m,len,(uint8_t*)digest) != NULL);
  52. else
  53. ret = (sha3_256((uint8_t *)digest, DIGEST256_LEN,(const uint8_t *)m, len)
  54. > -1);
  55. if (!ret)
  56. return -1;
  57. return 0;
  58. }
  59. /** Compute a 512-bit digest of <b>len</b> bytes in data stored in <b>m</b>,
  60. * using the algorithm <b>algorithm</b>. Write the DIGEST_LEN512-byte result
  61. * into <b>digest</b>. Return 0 on success, -1 on failure. */
  62. int
  63. crypto_digest512(char *digest, const char *m, size_t len,
  64. digest_algorithm_t algorithm)
  65. {
  66. tor_assert(m);
  67. tor_assert(digest);
  68. tor_assert(algorithm == DIGEST_SHA512 || algorithm == DIGEST_SHA3_512);
  69. int ret = 0;
  70. if (algorithm == DIGEST_SHA512)
  71. ret = (SHA512((const unsigned char*)m,len,(unsigned char*)digest)
  72. != NULL);
  73. else
  74. ret = (sha3_512((uint8_t*)digest, DIGEST512_LEN, (const uint8_t*)m, len)
  75. > -1);
  76. if (!ret)
  77. return -1;
  78. return 0;
  79. }
  80. /** Set the common_digests_t in <b>ds_out</b> to contain every digest on the
  81. * <b>len</b> bytes in <b>m</b> that we know how to compute. Return 0 on
  82. * success, -1 on failure. */
  83. int
  84. crypto_common_digests(common_digests_t *ds_out, const char *m, size_t len)
  85. {
  86. tor_assert(ds_out);
  87. memset(ds_out, 0, sizeof(*ds_out));
  88. if (crypto_digest(ds_out->d[DIGEST_SHA1], m, len) < 0)
  89. return -1;
  90. if (crypto_digest256(ds_out->d[DIGEST_SHA256], m, len, DIGEST_SHA256) < 0)
  91. return -1;
  92. return 0;
  93. }
  94. /** Return the name of an algorithm, as used in directory documents. */
  95. const char *
  96. crypto_digest_algorithm_get_name(digest_algorithm_t alg)
  97. {
  98. switch (alg) {
  99. case DIGEST_SHA1:
  100. return "sha1";
  101. case DIGEST_SHA256:
  102. return "sha256";
  103. case DIGEST_SHA512:
  104. return "sha512";
  105. case DIGEST_SHA3_256:
  106. return "sha3-256";
  107. case DIGEST_SHA3_512:
  108. return "sha3-512";
  109. // LCOV_EXCL_START
  110. default:
  111. tor_fragile_assert();
  112. return "??unknown_digest??";
  113. // LCOV_EXCL_STOP
  114. }
  115. }
  116. /** Given the name of a digest algorithm, return its integer value, or -1 if
  117. * the name is not recognized. */
  118. int
  119. crypto_digest_algorithm_parse_name(const char *name)
  120. {
  121. if (!strcmp(name, "sha1"))
  122. return DIGEST_SHA1;
  123. else if (!strcmp(name, "sha256"))
  124. return DIGEST_SHA256;
  125. else if (!strcmp(name, "sha512"))
  126. return DIGEST_SHA512;
  127. else if (!strcmp(name, "sha3-256"))
  128. return DIGEST_SHA3_256;
  129. else if (!strcmp(name, "sha3-512"))
  130. return DIGEST_SHA3_512;
  131. else
  132. return -1;
  133. }
  134. /** Given an algorithm, return the digest length in bytes. */
  135. size_t
  136. crypto_digest_algorithm_get_length(digest_algorithm_t alg)
  137. {
  138. switch (alg) {
  139. case DIGEST_SHA1:
  140. return DIGEST_LEN;
  141. case DIGEST_SHA256:
  142. return DIGEST256_LEN;
  143. case DIGEST_SHA512:
  144. return DIGEST512_LEN;
  145. case DIGEST_SHA3_256:
  146. return DIGEST256_LEN;
  147. case DIGEST_SHA3_512:
  148. return DIGEST512_LEN;
  149. default:
  150. tor_assert(0); // LCOV_EXCL_LINE
  151. return 0; /* Unreachable */ // LCOV_EXCL_LINE
  152. }
  153. }
  154. /** Intermediate information about the digest of a stream of data. */
  155. struct crypto_digest_t {
  156. digest_algorithm_t algorithm; /**< Which algorithm is in use? */
  157. /** State for the digest we're using. Only one member of the
  158. * union is usable, depending on the value of <b>algorithm</b>. Note also
  159. * that space for other members might not even be allocated!
  160. */
  161. union {
  162. SHA_CTX sha1; /**< state for SHA1 */
  163. SHA256_CTX sha2; /**< state for SHA256 */
  164. SHA512_CTX sha512; /**< state for SHA512 */
  165. keccak_state sha3; /**< state for SHA3-[256,512] */
  166. } d;
  167. };
  168. #ifdef TOR_UNIT_TESTS
  169. digest_algorithm_t
  170. crypto_digest_get_algorithm(crypto_digest_t *digest)
  171. {
  172. tor_assert(digest);
  173. return digest->algorithm;
  174. }
  175. #endif /* defined(TOR_UNIT_TESTS) */
  176. /**
  177. * Return the number of bytes we need to malloc in order to get a
  178. * crypto_digest_t for <b>alg</b>, or the number of bytes we need to wipe
  179. * when we free one.
  180. */
  181. static size_t
  182. crypto_digest_alloc_bytes(digest_algorithm_t alg)
  183. {
  184. /* Helper: returns the number of bytes in the 'f' field of 'st' */
  185. #define STRUCT_FIELD_SIZE(st, f) (sizeof( ((st*)0)->f ))
  186. /* Gives the length of crypto_digest_t through the end of the field 'd' */
  187. #define END_OF_FIELD(f) (offsetof(crypto_digest_t, f) + \
  188. STRUCT_FIELD_SIZE(crypto_digest_t, f))
  189. switch (alg) {
  190. case DIGEST_SHA1:
  191. return END_OF_FIELD(d.sha1);
  192. case DIGEST_SHA256:
  193. return END_OF_FIELD(d.sha2);
  194. case DIGEST_SHA512:
  195. return END_OF_FIELD(d.sha512);
  196. case DIGEST_SHA3_256:
  197. case DIGEST_SHA3_512:
  198. return END_OF_FIELD(d.sha3);
  199. default:
  200. tor_assert(0); // LCOV_EXCL_LINE
  201. return 0; // LCOV_EXCL_LINE
  202. }
  203. #undef END_OF_FIELD
  204. #undef STRUCT_FIELD_SIZE
  205. }
  206. /**
  207. * Internal function: create and return a new digest object for 'algorithm'.
  208. * Does not typecheck the algorithm.
  209. */
  210. static crypto_digest_t *
  211. crypto_digest_new_internal(digest_algorithm_t algorithm)
  212. {
  213. crypto_digest_t *r = tor_malloc(crypto_digest_alloc_bytes(algorithm));
  214. r->algorithm = algorithm;
  215. switch (algorithm)
  216. {
  217. case DIGEST_SHA1:
  218. SHA1_Init(&r->d.sha1);
  219. break;
  220. case DIGEST_SHA256:
  221. SHA256_Init(&r->d.sha2);
  222. break;
  223. case DIGEST_SHA512:
  224. SHA512_Init(&r->d.sha512);
  225. break;
  226. case DIGEST_SHA3_256:
  227. keccak_digest_init(&r->d.sha3, 256);
  228. break;
  229. case DIGEST_SHA3_512:
  230. keccak_digest_init(&r->d.sha3, 512);
  231. break;
  232. default:
  233. tor_assert_unreached();
  234. }
  235. return r;
  236. }
  237. /** Allocate and return a new digest object to compute SHA1 digests.
  238. */
  239. crypto_digest_t *
  240. crypto_digest_new(void)
  241. {
  242. return crypto_digest_new_internal(DIGEST_SHA1);
  243. }
  244. /** Allocate and return a new digest object to compute 256-bit digests
  245. * using <b>algorithm</b>.
  246. *
  247. * C_RUST_COUPLED: `external::crypto_digest::crypto_digest256_new`
  248. * C_RUST_COUPLED: `crypto::digest::Sha256::default`
  249. */
  250. crypto_digest_t *
  251. crypto_digest256_new(digest_algorithm_t algorithm)
  252. {
  253. tor_assert(algorithm == DIGEST_SHA256 || algorithm == DIGEST_SHA3_256);
  254. return crypto_digest_new_internal(algorithm);
  255. }
  256. /** Allocate and return a new digest object to compute 512-bit digests
  257. * using <b>algorithm</b>. */
  258. crypto_digest_t *
  259. crypto_digest512_new(digest_algorithm_t algorithm)
  260. {
  261. tor_assert(algorithm == DIGEST_SHA512 || algorithm == DIGEST_SHA3_512);
  262. return crypto_digest_new_internal(algorithm);
  263. }
  264. /** Deallocate a digest object.
  265. */
  266. void
  267. crypto_digest_free_(crypto_digest_t *digest)
  268. {
  269. if (!digest)
  270. return;
  271. size_t bytes = crypto_digest_alloc_bytes(digest->algorithm);
  272. memwipe(digest, 0, bytes);
  273. tor_free(digest);
  274. }
  275. /** Add <b>len</b> bytes from <b>data</b> to the digest object.
  276. *
  277. * C_RUST_COUPLED: `external::crypto_digest::crypto_digest_add_bytess`
  278. * C_RUST_COUPLED: `crypto::digest::Sha256::process`
  279. */
  280. void
  281. crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
  282. size_t len)
  283. {
  284. tor_assert(digest);
  285. tor_assert(data);
  286. /* Using the SHA*_*() calls directly means we don't support doing
  287. * SHA in hardware. But so far the delay of getting the question
  288. * to the hardware, and hearing the answer, is likely higher than
  289. * just doing it ourselves. Hashes are fast.
  290. */
  291. switch (digest->algorithm) {
  292. case DIGEST_SHA1:
  293. SHA1_Update(&digest->d.sha1, (void*)data, len);
  294. break;
  295. case DIGEST_SHA256:
  296. SHA256_Update(&digest->d.sha2, (void*)data, len);
  297. break;
  298. case DIGEST_SHA512:
  299. SHA512_Update(&digest->d.sha512, (void*)data, len);
  300. break;
  301. case DIGEST_SHA3_256: /* FALLSTHROUGH */
  302. case DIGEST_SHA3_512:
  303. keccak_digest_update(&digest->d.sha3, (const uint8_t *)data, len);
  304. break;
  305. default:
  306. /* LCOV_EXCL_START */
  307. tor_fragile_assert();
  308. break;
  309. /* LCOV_EXCL_STOP */
  310. }
  311. }
  312. /** Compute the hash of the data that has been passed to the digest
  313. * object; write the first out_len bytes of the result to <b>out</b>.
  314. * <b>out_len</b> must be \<= DIGEST512_LEN.
  315. *
  316. * C_RUST_COUPLED: `external::crypto_digest::crypto_digest_get_digest`
  317. * C_RUST_COUPLED: `impl digest::FixedOutput for Sha256`
  318. */
  319. void
  320. crypto_digest_get_digest(crypto_digest_t *digest,
  321. char *out, size_t out_len)
  322. {
  323. unsigned char r[DIGEST512_LEN];
  324. crypto_digest_t tmpenv;
  325. tor_assert(digest);
  326. tor_assert(out);
  327. tor_assert(out_len <= crypto_digest_algorithm_get_length(digest->algorithm));
  328. /* The SHA-3 code handles copying into a temporary ctx, and also can handle
  329. * short output buffers by truncating appropriately. */
  330. if (digest->algorithm == DIGEST_SHA3_256 ||
  331. digest->algorithm == DIGEST_SHA3_512) {
  332. keccak_digest_sum(&digest->d.sha3, (uint8_t *)out, out_len);
  333. return;
  334. }
  335. const size_t alloc_bytes = crypto_digest_alloc_bytes(digest->algorithm);
  336. /* memcpy into a temporary ctx, since SHA*_Final clears the context */
  337. memcpy(&tmpenv, digest, alloc_bytes);
  338. switch (digest->algorithm) {
  339. case DIGEST_SHA1:
  340. SHA1_Final(r, &tmpenv.d.sha1);
  341. break;
  342. case DIGEST_SHA256:
  343. SHA256_Final(r, &tmpenv.d.sha2);
  344. break;
  345. case DIGEST_SHA512:
  346. SHA512_Final(r, &tmpenv.d.sha512);
  347. break;
  348. //LCOV_EXCL_START
  349. case DIGEST_SHA3_256: /* FALLSTHROUGH */
  350. case DIGEST_SHA3_512:
  351. default:
  352. log_warn(LD_BUG, "Handling unexpected algorithm %d", digest->algorithm);
  353. /* This is fatal, because it should never happen. */
  354. tor_assert_unreached();
  355. break;
  356. //LCOV_EXCL_STOP
  357. }
  358. memcpy(out, r, out_len);
  359. memwipe(r, 0, sizeof(r));
  360. }
  361. /** Allocate and return a new digest object with the same state as
  362. * <b>digest</b>
  363. *
  364. * C_RUST_COUPLED: `external::crypto_digest::crypto_digest_dup`
  365. * C_RUST_COUPLED: `impl Clone for crypto::digest::Sha256`
  366. */
  367. crypto_digest_t *
  368. crypto_digest_dup(const crypto_digest_t *digest)
  369. {
  370. tor_assert(digest);
  371. const size_t alloc_bytes = crypto_digest_alloc_bytes(digest->algorithm);
  372. return tor_memdup(digest, alloc_bytes);
  373. }
  374. /** Temporarily save the state of <b>digest</b> in <b>checkpoint</b>.
  375. * Asserts that <b>digest</b> is a SHA1 digest object.
  376. */
  377. void
  378. crypto_digest_checkpoint(crypto_digest_checkpoint_t *checkpoint,
  379. const crypto_digest_t *digest)
  380. {
  381. const size_t bytes = crypto_digest_alloc_bytes(digest->algorithm);
  382. tor_assert(bytes <= sizeof(checkpoint->mem));
  383. memcpy(checkpoint->mem, digest, bytes);
  384. }
  385. /** Restore the state of <b>digest</b> from <b>checkpoint</b>.
  386. * Asserts that <b>digest</b> is a SHA1 digest object. Requires that the
  387. * state was previously stored with crypto_digest_checkpoint() */
  388. void
  389. crypto_digest_restore(crypto_digest_t *digest,
  390. const crypto_digest_checkpoint_t *checkpoint)
  391. {
  392. const size_t bytes = crypto_digest_alloc_bytes(digest->algorithm);
  393. memcpy(digest, checkpoint->mem, bytes);
  394. }
  395. /** Replace the state of the digest object <b>into</b> with the state
  396. * of the digest object <b>from</b>. Requires that 'into' and 'from'
  397. * have the same digest type.
  398. */
  399. void
  400. crypto_digest_assign(crypto_digest_t *into,
  401. const crypto_digest_t *from)
  402. {
  403. tor_assert(into);
  404. tor_assert(from);
  405. tor_assert(into->algorithm == from->algorithm);
  406. const size_t alloc_bytes = crypto_digest_alloc_bytes(from->algorithm);
  407. memcpy(into,from,alloc_bytes);
  408. }
  409. /** Given a list of strings in <b>lst</b>, set the <b>len_out</b>-byte digest
  410. * at <b>digest_out</b> to the hash of the concatenation of those strings,
  411. * plus the optional string <b>append</b>, computed with the algorithm
  412. * <b>alg</b>.
  413. * <b>out_len</b> must be \<= DIGEST512_LEN. */
  414. void
  415. crypto_digest_smartlist(char *digest_out, size_t len_out,
  416. const smartlist_t *lst,
  417. const char *append,
  418. digest_algorithm_t alg)
  419. {
  420. crypto_digest_smartlist_prefix(digest_out, len_out, NULL, lst, append, alg);
  421. }
  422. /** Given a list of strings in <b>lst</b>, set the <b>len_out</b>-byte digest
  423. * at <b>digest_out</b> to the hash of the concatenation of: the
  424. * optional string <b>prepend</b>, those strings,
  425. * and the optional string <b>append</b>, computed with the algorithm
  426. * <b>alg</b>.
  427. * <b>len_out</b> must be \<= DIGEST512_LEN. */
  428. void
  429. crypto_digest_smartlist_prefix(char *digest_out, size_t len_out,
  430. const char *prepend,
  431. const smartlist_t *lst,
  432. const char *append,
  433. digest_algorithm_t alg)
  434. {
  435. crypto_digest_t *d = crypto_digest_new_internal(alg);
  436. if (prepend)
  437. crypto_digest_add_bytes(d, prepend, strlen(prepend));
  438. SMARTLIST_FOREACH(lst, const char *, cp,
  439. crypto_digest_add_bytes(d, cp, strlen(cp)));
  440. if (append)
  441. crypto_digest_add_bytes(d, append, strlen(append));
  442. crypto_digest_get_digest(d, digest_out, len_out);
  443. crypto_digest_free(d);
  444. }
  445. /** Compute the HMAC-SHA-256 of the <b>msg_len</b> bytes in <b>msg</b>, using
  446. * the <b>key</b> of length <b>key_len</b>. Store the DIGEST256_LEN-byte
  447. * result in <b>hmac_out</b>. Asserts on failure.
  448. */
  449. void
  450. crypto_hmac_sha256(char *hmac_out,
  451. const char *key, size_t key_len,
  452. const char *msg, size_t msg_len)
  453. {
  454. unsigned char *rv = NULL;
  455. /* If we've got OpenSSL >=0.9.8 we can use its hmac implementation. */
  456. tor_assert(key_len < INT_MAX);
  457. tor_assert(msg_len < INT_MAX);
  458. tor_assert(hmac_out);
  459. rv = HMAC(EVP_sha256(), key, (int)key_len, (unsigned char*)msg, (int)msg_len,
  460. (unsigned char*)hmac_out, NULL);
  461. tor_assert(rv);
  462. }
  463. /** Compute a MAC using SHA3-256 of <b>msg_len</b> bytes in <b>msg</b> using a
  464. * <b>key</b> of length <b>key_len</b> and a <b>salt</b> of length
  465. * <b>salt_len</b>. Store the result of <b>len_out</b> bytes in in
  466. * <b>mac_out</b>. This function can't fail. */
  467. void
  468. crypto_mac_sha3_256(uint8_t *mac_out, size_t len_out,
  469. const uint8_t *key, size_t key_len,
  470. const uint8_t *msg, size_t msg_len)
  471. {
  472. crypto_digest_t *digest;
  473. const uint64_t key_len_netorder = tor_htonll(key_len);
  474. tor_assert(mac_out);
  475. tor_assert(key);
  476. tor_assert(msg);
  477. digest = crypto_digest256_new(DIGEST_SHA3_256);
  478. /* Order matters here that is any subsystem using this function should
  479. * expect this very precise ordering in the MAC construction. */
  480. crypto_digest_add_bytes(digest, (const char *) &key_len_netorder,
  481. sizeof(key_len_netorder));
  482. crypto_digest_add_bytes(digest, (const char *) key, key_len);
  483. crypto_digest_add_bytes(digest, (const char *) msg, msg_len);
  484. crypto_digest_get_digest(digest, (char *) mac_out, len_out);
  485. crypto_digest_free(digest);
  486. }
  487. /* xof functions */
  488. /** Internal state for a eXtendable-Output Function (XOF). */
  489. struct crypto_xof_t {
  490. keccak_state s;
  491. };
  492. /** Allocate a new XOF object backed by SHAKE-256. The security level
  493. * provided is a function of the length of the output used. Read and
  494. * understand FIPS-202 A.2 "Additional Consideration for Extendable-Output
  495. * Functions" before using this construct.
  496. */
  497. crypto_xof_t *
  498. crypto_xof_new(void)
  499. {
  500. crypto_xof_t *xof;
  501. xof = tor_malloc(sizeof(crypto_xof_t));
  502. keccak_xof_init(&xof->s, 256);
  503. return xof;
  504. }
  505. /** Absorb bytes into a XOF object. Must not be called after a call to
  506. * crypto_xof_squeeze_bytes() for the same instance, and will assert
  507. * if attempted.
  508. */
  509. void
  510. crypto_xof_add_bytes(crypto_xof_t *xof, const uint8_t *data, size_t len)
  511. {
  512. int i = keccak_xof_absorb(&xof->s, data, len);
  513. tor_assert(i == 0);
  514. }
  515. /** Squeeze bytes out of a XOF object. Calling this routine will render
  516. * the XOF instance ineligible to absorb further data.
  517. */
  518. void
  519. crypto_xof_squeeze_bytes(crypto_xof_t *xof, uint8_t *out, size_t len)
  520. {
  521. int i = keccak_xof_squeeze(&xof->s, out, len);
  522. tor_assert(i == 0);
  523. }
  524. /** Cleanse and deallocate a XOF object. */
  525. void
  526. crypto_xof_free_(crypto_xof_t *xof)
  527. {
  528. if (!xof)
  529. return;
  530. memwipe(xof, 0, sizeof(crypto_xof_t));
  531. tor_free(xof);
  532. }