ocb128.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /* ====================================================================
  2. * Copyright (c) 2014 The OpenSSL Project. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * 3. All advertising materials mentioning features or use of this
  17. * software must display the following acknowledgment:
  18. * "This product includes software developed by the OpenSSL Project
  19. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  20. *
  21. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  22. * endorse or promote products derived from this software without
  23. * prior written permission. For written permission, please contact
  24. * openssl-core@openssl.org.
  25. *
  26. * 5. Products derived from this software may not be called "OpenSSL"
  27. * nor may "OpenSSL" appear in their names without prior written
  28. * permission of the OpenSSL Project.
  29. *
  30. * 6. Redistributions of any form whatsoever must retain the following
  31. * acknowledgment:
  32. * "This product includes software developed by the OpenSSL Project
  33. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  36. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46. * OF THE POSSIBILITY OF SUCH DAMAGE.
  47. * ====================================================================
  48. */
  49. #include <string.h>
  50. #include <openssl/crypto.h>
  51. #include "modes_lcl.h"
  52. #ifndef OPENSSL_NO_OCB
  53. union ublock {
  54. unsigned char *chrblk;
  55. OCB_BLOCK *ocbblk;
  56. };
  57. /*
  58. * Calculate the number of binary trailing zero's in any given number
  59. */
  60. static u32 ocb_ntz(u64 n)
  61. {
  62. u32 cnt = 0;
  63. /*
  64. * We do a right-to-left simple sequential search. This is surprisingly
  65. * efficient as the distribution of trailing zeros is not uniform,
  66. * e.g. the number of possible inputs with no trailing zeros is equal to
  67. * the number with 1 or more; the number with exactly 1 is equal to the
  68. * number with 2 or more, etc. Checking the last two bits covers 75% of
  69. * all numbers. Checking the last three covers 87.5%
  70. */
  71. while (!(n & 1)) {
  72. n >>= 1;
  73. cnt++;
  74. }
  75. return cnt;
  76. }
  77. /*
  78. * Shift a block of 16 bytes left by shift bits
  79. */
  80. static void ocb_block_lshift(OCB_BLOCK *in, size_t shift, OCB_BLOCK *out)
  81. {
  82. unsigned char shift_mask;
  83. int i;
  84. unsigned char mask[15];
  85. union ublock locin;
  86. union ublock locout;
  87. locin.ocbblk = in;
  88. locout.ocbblk = out;
  89. shift_mask = 0xff;
  90. shift_mask <<= (8 - shift);
  91. for (i = 15; i >= 0; i--) {
  92. if (i > 0) {
  93. mask[i - 1] = locin.chrblk[i] & shift_mask;
  94. mask[i - 1] >>= 8 - shift;
  95. }
  96. locout.chrblk[i] = locin.chrblk[i] << shift;
  97. if (i != 15) {
  98. locout.chrblk[i] ^= mask[i];
  99. }
  100. }
  101. }
  102. /*
  103. * Perform a "double" operation as per OCB spec
  104. */
  105. static void ocb_double(OCB_BLOCK *in, OCB_BLOCK *out)
  106. {
  107. unsigned char mask;
  108. union ublock locin;
  109. union ublock locout;
  110. locin.ocbblk = in;
  111. locout.ocbblk = out;
  112. /*
  113. * Calculate the mask based on the most significant bit. There are more
  114. * efficient ways to do this - but this way is constant time
  115. */
  116. mask = locin.chrblk[0] & 0x80;
  117. mask >>= 7;
  118. mask *= 135;
  119. ocb_block_lshift(in, 1, out);
  120. locout.chrblk[15] ^= mask;
  121. }
  122. /*
  123. * Perform an xor on in1 and in2 - each of len bytes. Store result in out
  124. */
  125. static void ocb_block_xor(const unsigned char *in1,
  126. const unsigned char *in2, size_t len,
  127. unsigned char *out)
  128. {
  129. size_t i;
  130. for (i = 0; i < len; i++) {
  131. out[i] = in1[i] ^ in2[i];
  132. }
  133. }
  134. /*
  135. * Lookup L_index in our lookup table. If we haven't already got it we need to
  136. * calculate it
  137. */
  138. static OCB_BLOCK *ocb_lookup_l(OCB128_CONTEXT *ctx, size_t idx)
  139. {
  140. if (idx <= ctx->l_index) {
  141. return ctx->l + idx;
  142. }
  143. /* We don't have it - so calculate it */
  144. ctx->l_index++;
  145. if (ctx->l_index == ctx->max_l_index) {
  146. ctx->max_l_index *= 2;
  147. ctx->l =
  148. OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK));
  149. if (!ctx->l)
  150. return NULL;
  151. }
  152. ocb_double(ctx->l + (idx - 1), ctx->l + idx);
  153. return ctx->l + idx;
  154. }
  155. /*
  156. * Encrypt a block from |in| and store the result in |out|
  157. */
  158. static void ocb_encrypt(OCB128_CONTEXT *ctx, OCB_BLOCK *in, OCB_BLOCK *out,
  159. void *keyenc)
  160. {
  161. union ublock locin;
  162. union ublock locout;
  163. locin.ocbblk = in;
  164. locout.ocbblk = out;
  165. ctx->encrypt(locin.chrblk, locout.chrblk, keyenc);
  166. }
  167. /*
  168. * Decrypt a block from |in| and store the result in |out|
  169. */
  170. static void ocb_decrypt(OCB128_CONTEXT *ctx, OCB_BLOCK *in, OCB_BLOCK *out,
  171. void *keydec)
  172. {
  173. union ublock locin;
  174. union ublock locout;
  175. locin.ocbblk = in;
  176. locout.ocbblk = out;
  177. ctx->decrypt(locin.chrblk, locout.chrblk, keydec);
  178. }
  179. /*
  180. * Create a new OCB128_CONTEXT
  181. */
  182. OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec,
  183. block128_f encrypt, block128_f decrypt)
  184. {
  185. OCB128_CONTEXT *octx;
  186. int ret;
  187. if ((octx = OPENSSL_malloc(sizeof(*octx)))) {
  188. ret = CRYPTO_ocb128_init(octx, keyenc, keydec, encrypt, decrypt);
  189. if (ret)
  190. return octx;
  191. OPENSSL_free(octx);
  192. }
  193. return NULL;
  194. }
  195. /*
  196. * Initialise an existing OCB128_CONTEXT
  197. */
  198. int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec,
  199. block128_f encrypt, block128_f decrypt)
  200. {
  201. memset(ctx, 0, sizeof(*ctx));
  202. ctx->l_index = 0;
  203. ctx->max_l_index = 1;
  204. ctx->l = OPENSSL_malloc(ctx->max_l_index * 16);
  205. if (!ctx->l)
  206. return 0;
  207. /*
  208. * We set both the encryption and decryption key schedules - decryption
  209. * needs both. Don't really need decryption schedule if only doing
  210. * encryption - but it simplifies things to take it anyway
  211. */
  212. ctx->encrypt = encrypt;
  213. ctx->decrypt = decrypt;
  214. ctx->keyenc = keyenc;
  215. ctx->keydec = keydec;
  216. /* L_* = ENCIPHER(K, zeros(128)) */
  217. ocb_encrypt(ctx, &ctx->l_star, &ctx->l_star, ctx->keyenc);
  218. /* L_$ = double(L_*) */
  219. ocb_double(&ctx->l_star, &ctx->l_dollar);
  220. /* L_0 = double(L_$) */
  221. ocb_double(&ctx->l_dollar, ctx->l);
  222. return 1;
  223. }
  224. /*
  225. * Copy an OCB128_CONTEXT object
  226. */
  227. int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src,
  228. void *keyenc, void *keydec)
  229. {
  230. memcpy(dest, src, sizeof(OCB128_CONTEXT));
  231. if (keyenc)
  232. dest->keyenc = keyenc;
  233. if (keydec)
  234. dest->keydec = keydec;
  235. if (src->l) {
  236. dest->l = OPENSSL_malloc(src->max_l_index * 16);
  237. if (!dest->l)
  238. return 0;
  239. memcpy(dest->l, src->l, (src->l_index + 1) * 16);
  240. }
  241. return 1;
  242. }
  243. /*
  244. * Set the IV to be used for this operation. Must be 1 - 15 bytes.
  245. */
  246. int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv,
  247. size_t len, size_t taglen)
  248. {
  249. unsigned char ktop[16], tmp[16], mask;
  250. unsigned char stretch[24], nonce[16];
  251. size_t bottom, shift;
  252. union ublock offset;
  253. offset.ocbblk = &ctx->offset;
  254. /*
  255. * Spec says IV is 120 bits or fewer - it allows non byte aligned lengths.
  256. * We don't support this at this stage
  257. */
  258. if ((len > 15) || (len < 1) || (taglen > 16) || (taglen < 1)) {
  259. return -1;
  260. }
  261. /* Nonce = num2str(TAGLEN mod 128,7) || zeros(120-bitlen(N)) || 1 || N */
  262. nonce[0] = ((taglen * 8) % 128) << 1;
  263. memset(nonce + 1, 0, 15);
  264. memcpy(nonce + 16 - len, iv, len);
  265. nonce[15 - len] |= 1;
  266. /* Ktop = ENCIPHER(K, Nonce[1..122] || zeros(6)) */
  267. memcpy(tmp, nonce, 16);
  268. tmp[15] &= 0xc0;
  269. ctx->encrypt(tmp, ktop, ctx->keyenc);
  270. /* Stretch = Ktop || (Ktop[1..64] xor Ktop[9..72]) */
  271. memcpy(stretch, ktop, 16);
  272. ocb_block_xor(ktop, ktop + 1, 8, stretch + 16);
  273. /* bottom = str2num(Nonce[123..128]) */
  274. bottom = nonce[15] & 0x3f;
  275. /* Offset_0 = Stretch[1+bottom..128+bottom] */
  276. shift = bottom % 8;
  277. ocb_block_lshift((OCB_BLOCK *)(stretch + (bottom / 8)), shift,
  278. &ctx->offset);
  279. mask = 0xff;
  280. mask <<= 8 - shift;
  281. offset.chrblk[15] |=
  282. (*(stretch + (bottom / 8) + 16) & mask) >> (8 - shift);
  283. return 1;
  284. }
  285. /*
  286. * Provide any AAD. This can be called multiple times. Only the final time can
  287. * have a partial block
  288. */
  289. int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad,
  290. size_t len)
  291. {
  292. u64 all_num_blocks, num_blocks;
  293. u64 i;
  294. OCB_BLOCK tmp1;
  295. OCB_BLOCK tmp2;
  296. int last_len;
  297. /* Calculate the number of blocks of AAD provided now, and so far */
  298. num_blocks = len / 16;
  299. all_num_blocks = num_blocks + ctx->blocks_hashed;
  300. /* Loop through all full blocks of AAD */
  301. for (i = ctx->blocks_hashed + 1; i <= all_num_blocks; i++) {
  302. OCB_BLOCK *lookup;
  303. OCB_BLOCK *aad_block;
  304. /* Offset_i = Offset_{i-1} xor L_{ntz(i)} */
  305. lookup = ocb_lookup_l(ctx, ocb_ntz(i));
  306. if (!lookup)
  307. return 0;
  308. ocb_block16_xor(&ctx->offset_aad, lookup, &ctx->offset_aad);
  309. /* Sum_i = Sum_{i-1} xor ENCIPHER(K, A_i xor Offset_i) */
  310. aad_block = (OCB_BLOCK *)(aad + ((i - ctx->blocks_hashed - 1) * 16));
  311. ocb_block16_xor(&ctx->offset_aad, aad_block, &tmp1);
  312. ocb_encrypt(ctx, &tmp1, &tmp2, ctx->keyenc);
  313. ocb_block16_xor(&ctx->sum, &tmp2, &ctx->sum);
  314. }
  315. /*
  316. * Check if we have any partial blocks left over. This is only valid in the
  317. * last call to this function
  318. */
  319. last_len = len % 16;
  320. if (last_len > 0) {
  321. /* Offset_* = Offset_m xor L_* */
  322. ocb_block16_xor(&ctx->offset_aad, &ctx->l_star, &ctx->offset_aad);
  323. /* CipherInput = (A_* || 1 || zeros(127-bitlen(A_*))) xor Offset_* */
  324. memset(&tmp1, 0, 16);
  325. memcpy(&tmp1, aad + (num_blocks * 16), last_len);
  326. ((unsigned char *)&tmp1)[last_len] = 0x80;
  327. ocb_block16_xor(&ctx->offset_aad, &tmp1, &tmp2);
  328. /* Sum = Sum_m xor ENCIPHER(K, CipherInput) */
  329. ocb_encrypt(ctx, &tmp2, &tmp1, ctx->keyenc);
  330. ocb_block16_xor(&ctx->sum, &tmp1, &ctx->sum);
  331. }
  332. ctx->blocks_hashed = all_num_blocks;
  333. return 1;
  334. }
  335. /*
  336. * Provide any data to be encrypted. This can be called multiple times. Only
  337. * the final time can have a partial block
  338. */
  339. int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx,
  340. const unsigned char *in, unsigned char *out,
  341. size_t len)
  342. {
  343. u64 i;
  344. u64 all_num_blocks, num_blocks;
  345. OCB_BLOCK tmp1;
  346. OCB_BLOCK tmp2;
  347. OCB_BLOCK pad;
  348. int last_len;
  349. /*
  350. * Calculate the number of blocks of data to be encrypted provided now, and
  351. * so far
  352. */
  353. num_blocks = len / 16;
  354. all_num_blocks = num_blocks + ctx->blocks_processed;
  355. /* Loop through all full blocks to be encrypted */
  356. for (i = ctx->blocks_processed + 1; i <= all_num_blocks; i++) {
  357. OCB_BLOCK *lookup;
  358. OCB_BLOCK *inblock;
  359. OCB_BLOCK *outblock;
  360. /* Offset_i = Offset_{i-1} xor L_{ntz(i)} */
  361. lookup = ocb_lookup_l(ctx, ocb_ntz(i));
  362. if (!lookup)
  363. return 0;
  364. ocb_block16_xor(&ctx->offset, lookup, &ctx->offset);
  365. /* C_i = Offset_i xor ENCIPHER(K, P_i xor Offset_i) */
  366. inblock = (OCB_BLOCK *)(in + ((i - ctx->blocks_processed - 1) * 16));
  367. ocb_block16_xor(&ctx->offset, inblock, &tmp1);
  368. ocb_encrypt(ctx, &tmp1, &tmp2, ctx->keyenc);
  369. outblock =
  370. (OCB_BLOCK *)(out + ((i - ctx->blocks_processed - 1) * 16));
  371. ocb_block16_xor(&ctx->offset, &tmp2, outblock);
  372. /* Checksum_i = Checksum_{i-1} xor P_i */
  373. ocb_block16_xor(&ctx->checksum, inblock, &ctx->checksum);
  374. }
  375. /*
  376. * Check if we have any partial blocks left over. This is only valid in the
  377. * last call to this function
  378. */
  379. last_len = len % 16;
  380. if (last_len > 0) {
  381. /* Offset_* = Offset_m xor L_* */
  382. ocb_block16_xor(&ctx->offset, &ctx->l_star, &ctx->offset);
  383. /* Pad = ENCIPHER(K, Offset_*) */
  384. ocb_encrypt(ctx, &ctx->offset, &pad, ctx->keyenc);
  385. /* C_* = P_* xor Pad[1..bitlen(P_*)] */
  386. ocb_block_xor(in + (len / 16) * 16, (unsigned char *)&pad, last_len,
  387. out + (num_blocks * 16));
  388. /* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
  389. memset(&tmp1, 0, 16);
  390. memcpy(&tmp1, in + (len / 16) * 16, last_len);
  391. ((unsigned char *)(&tmp1))[last_len] = 0x80;
  392. ocb_block16_xor(&ctx->checksum, &tmp1, &ctx->checksum);
  393. }
  394. ctx->blocks_processed = all_num_blocks;
  395. return 1;
  396. }
  397. /*
  398. * Provide any data to be decrypted. This can be called multiple times. Only
  399. * the final time can have a partial block
  400. */
  401. int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx,
  402. const unsigned char *in, unsigned char *out,
  403. size_t len)
  404. {
  405. u64 i;
  406. u64 all_num_blocks, num_blocks;
  407. OCB_BLOCK tmp1;
  408. OCB_BLOCK tmp2;
  409. OCB_BLOCK pad;
  410. int last_len;
  411. /*
  412. * Calculate the number of blocks of data to be decrypted provided now, and
  413. * so far
  414. */
  415. num_blocks = len / 16;
  416. all_num_blocks = num_blocks + ctx->blocks_processed;
  417. /* Loop through all full blocks to be decrypted */
  418. for (i = ctx->blocks_processed + 1; i <= all_num_blocks; i++) {
  419. OCB_BLOCK *inblock;
  420. OCB_BLOCK *outblock;
  421. /* Offset_i = Offset_{i-1} xor L_{ntz(i)} */
  422. OCB_BLOCK *lookup = ocb_lookup_l(ctx, ocb_ntz(i));
  423. if (!lookup)
  424. return 0;
  425. ocb_block16_xor(&ctx->offset, lookup, &ctx->offset);
  426. /* P_i = Offset_i xor DECIPHER(K, C_i xor Offset_i) */
  427. inblock = (OCB_BLOCK *)(in + ((i - ctx->blocks_processed - 1) * 16));
  428. ocb_block16_xor(&ctx->offset, inblock, &tmp1);
  429. ocb_decrypt(ctx, &tmp1, &tmp2, ctx->keydec);
  430. outblock =
  431. (OCB_BLOCK *)(out + ((i - ctx->blocks_processed - 1) * 16));
  432. ocb_block16_xor(&ctx->offset, &tmp2, outblock);
  433. /* Checksum_i = Checksum_{i-1} xor P_i */
  434. ocb_block16_xor(&ctx->checksum, outblock, &ctx->checksum);
  435. }
  436. /*
  437. * Check if we have any partial blocks left over. This is only valid in the
  438. * last call to this function
  439. */
  440. last_len = len % 16;
  441. if (last_len > 0) {
  442. /* Offset_* = Offset_m xor L_* */
  443. ocb_block16_xor(&ctx->offset, &ctx->l_star, &ctx->offset);
  444. /* Pad = ENCIPHER(K, Offset_*) */
  445. ocb_encrypt(ctx, &ctx->offset, &pad, ctx->keyenc);
  446. /* P_* = C_* xor Pad[1..bitlen(C_*)] */
  447. ocb_block_xor(in + (len / 16) * 16, (unsigned char *)&pad, last_len,
  448. out + (num_blocks * 16));
  449. /* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
  450. memset(&tmp1, 0, 16);
  451. memcpy(&tmp1, out + (len / 16) * 16, last_len);
  452. ((unsigned char *)(&tmp1))[last_len] = 0x80;
  453. ocb_block16_xor(&ctx->checksum, &tmp1, &ctx->checksum);
  454. }
  455. ctx->blocks_processed = all_num_blocks;
  456. return 1;
  457. }
  458. /*
  459. * Calculate the tag and verify it against the supplied tag
  460. */
  461. int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag,
  462. size_t len)
  463. {
  464. OCB_BLOCK tmp1, tmp2;
  465. /*
  466. * Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A)
  467. */
  468. ocb_block16_xor(&ctx->checksum, &ctx->offset, &tmp1);
  469. ocb_block16_xor(&tmp1, &ctx->l_dollar, &tmp2);
  470. ocb_encrypt(ctx, &tmp2, &tmp1, ctx->keyenc);
  471. ocb_block16_xor(&tmp1, &ctx->sum, &ctx->tag);
  472. if (len > 16 || len < 1) {
  473. return -1;
  474. }
  475. /* Compare the tag if we've been given one */
  476. if (tag)
  477. return CRYPTO_memcmp(&ctx->tag, tag, len);
  478. else
  479. return -1;
  480. }
  481. /*
  482. * Retrieve the calculated tag
  483. */
  484. int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len)
  485. {
  486. if (len > 16 || len < 1) {
  487. return -1;
  488. }
  489. /* Calculate the tag */
  490. CRYPTO_ocb128_finish(ctx, NULL, 0);
  491. /* Copy the tag into the supplied buffer */
  492. memcpy(tag, &ctx->tag, len);
  493. return 1;
  494. }
  495. /*
  496. * Release all resources
  497. */
  498. void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx)
  499. {
  500. if (ctx) {
  501. OPENSSL_clear_free(ctx->l, ctx->max_l_index * 16);
  502. OPENSSL_cleanse(ctx, sizeof(*ctx));
  503. }
  504. }
  505. #endif /* OPENSSL_NO_OCB */