bio_ok.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* crypto/evp/bio_ok.c */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. /*
  59. From: Arne Ansper <arne@cyber.ee>
  60. Why BIO_f_reliable?
  61. I wrote function which took BIO* as argument, read data from it
  62. and processed it. Then I wanted to store the input file in
  63. encrypted form. OK I pushed BIO_f_cipher to the BIO stack
  64. and everything was OK. BUT if user types wrong password
  65. BIO_f_cipher outputs only garbage and my function crashes. Yes
  66. I can and I should fix my function, but BIO_f_cipher is
  67. easy way to add encryption support to many existing applications
  68. and it's hard to debug and fix them all.
  69. So I wanted another BIO which would catch the incorrect passwords and
  70. file damages which cause garbage on BIO_f_cipher's output.
  71. The easy way is to push the BIO_f_md and save the checksum at
  72. the end of the file. However there are several problems with this
  73. approach:
  74. 1) you must somehow separate checksum from actual data.
  75. 2) you need lot's of memory when reading the file, because you
  76. must read to the end of the file and verify the checksum before
  77. letting the application to read the data.
  78. BIO_f_reliable tries to solve both problems, so that you can
  79. read and write arbitrary long streams using only fixed amount
  80. of memory.
  81. BIO_f_reliable splits data stream into blocks. Each block is prefixed
  82. with it's length and suffixed with it's digest. So you need only
  83. several Kbytes of memory to buffer single block before verifying
  84. it's digest.
  85. BIO_f_reliable goes further and adds several important capabilities:
  86. 1) the digest of the block is computed over the whole stream
  87. -- so nobody can rearrange the blocks or remove or replace them.
  88. 2) to detect invalid passwords right at the start BIO_f_reliable
  89. adds special prefix to the stream. In order to avoid known plain-text
  90. attacks this prefix is generated as follows:
  91. *) digest is initialized with random seed instead of
  92. standardized one.
  93. *) same seed is written to output
  94. *) well-known text is then hashed and the output
  95. of the digest is also written to output.
  96. reader can now read the seed from stream, hash the same string
  97. and then compare the digest output.
  98. Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I
  99. initially wrote and tested this code on x86 machine and wrote the
  100. digests out in machine-dependent order :( There are people using
  101. this code and I cannot change this easily without making existing
  102. data files unreadable.
  103. */
  104. #include <stdio.h>
  105. #include <errno.h>
  106. #include <assert.h>
  107. #include "cryptlib.h"
  108. #include <openssl/buffer.h>
  109. #include <openssl/bio.h>
  110. #include <openssl/evp.h>
  111. #include <openssl/rand.h>
  112. static int ok_write(BIO *h, const char *buf, int num);
  113. static int ok_read(BIO *h, char *buf, int size);
  114. static long ok_ctrl(BIO *h, int cmd, long arg1, void *arg2);
  115. static int ok_new(BIO *h);
  116. static int ok_free(BIO *data);
  117. static long ok_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
  118. static __owur int sig_out(BIO* b);
  119. static __owur int sig_in(BIO* b);
  120. static __owur int block_out(BIO* b);
  121. static __owur int block_in(BIO* b);
  122. #define OK_BLOCK_SIZE (1024*4)
  123. #define OK_BLOCK_BLOCK 4
  124. #define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE)
  125. #define WELLKNOWN "The quick brown fox jumped over the lazy dog's back."
  126. typedef struct ok_struct
  127. {
  128. size_t buf_len;
  129. size_t buf_off;
  130. size_t buf_len_save;
  131. size_t buf_off_save;
  132. int cont; /* <= 0 when finished */
  133. int finished;
  134. EVP_MD_CTX md;
  135. int blockout; /* output block is ready */
  136. int sigio; /* must process signature */
  137. unsigned char buf[IOBS];
  138. } BIO_OK_CTX;
  139. static BIO_METHOD methods_ok=
  140. {
  141. BIO_TYPE_CIPHER,"reliable",
  142. ok_write,
  143. ok_read,
  144. NULL, /* ok_puts, */
  145. NULL, /* ok_gets, */
  146. ok_ctrl,
  147. ok_new,
  148. ok_free,
  149. ok_callback_ctrl,
  150. };
  151. BIO_METHOD *BIO_f_reliable(void)
  152. {
  153. return(&methods_ok);
  154. }
  155. static int ok_new(BIO *bi)
  156. {
  157. BIO_OK_CTX *ctx;
  158. ctx=(BIO_OK_CTX *)OPENSSL_malloc(sizeof(BIO_OK_CTX));
  159. if (ctx == NULL) return(0);
  160. ctx->buf_len=0;
  161. ctx->buf_off=0;
  162. ctx->buf_len_save=0;
  163. ctx->buf_off_save=0;
  164. ctx->cont=1;
  165. ctx->finished=0;
  166. ctx->blockout= 0;
  167. ctx->sigio=1;
  168. EVP_MD_CTX_init(&ctx->md);
  169. bi->init=0;
  170. bi->ptr=(char *)ctx;
  171. bi->flags=0;
  172. return(1);
  173. }
  174. static int ok_free(BIO *a)
  175. {
  176. if (a == NULL) return(0);
  177. EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md);
  178. OPENSSL_cleanse(a->ptr,sizeof(BIO_OK_CTX));
  179. OPENSSL_free(a->ptr);
  180. a->ptr=NULL;
  181. a->init=0;
  182. a->flags=0;
  183. return(1);
  184. }
  185. static int ok_read(BIO *b, char *out, int outl)
  186. {
  187. int ret=0,i,n;
  188. BIO_OK_CTX *ctx;
  189. if (out == NULL) return(0);
  190. ctx=(BIO_OK_CTX *)b->ptr;
  191. if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
  192. while(outl > 0)
  193. {
  194. /* copy clean bytes to output buffer */
  195. if (ctx->blockout)
  196. {
  197. i=ctx->buf_len-ctx->buf_off;
  198. if (i > outl) i=outl;
  199. memcpy(out,&(ctx->buf[ctx->buf_off]),i);
  200. ret+=i;
  201. out+=i;
  202. outl-=i;
  203. ctx->buf_off+=i;
  204. /* all clean bytes are out */
  205. if (ctx->buf_len == ctx->buf_off)
  206. {
  207. ctx->buf_off=0;
  208. /* copy start of the next block into proper place */
  209. if(ctx->buf_len_save- ctx->buf_off_save > 0)
  210. {
  211. ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save;
  212. memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]),
  213. ctx->buf_len);
  214. }
  215. else
  216. {
  217. ctx->buf_len=0;
  218. }
  219. ctx->blockout= 0;
  220. }
  221. }
  222. /* output buffer full -- cancel */
  223. if (outl == 0) break;
  224. /* no clean bytes in buffer -- fill it */
  225. n=IOBS- ctx->buf_len;
  226. i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n);
  227. if (i <= 0) break; /* nothing new */
  228. ctx->buf_len+= i;
  229. /* no signature yet -- check if we got one */
  230. if (ctx->sigio == 1)
  231. {
  232. if (!sig_in(b))
  233. {
  234. BIO_clear_retry_flags(b);
  235. return 0;
  236. }
  237. }
  238. /* signature ok -- check if we got block */
  239. if (ctx->sigio == 0)
  240. {
  241. if (!block_in(b))
  242. {
  243. BIO_clear_retry_flags(b);
  244. return 0;
  245. }
  246. }
  247. /* invalid block -- cancel */
  248. if (ctx->cont <= 0) break;
  249. }
  250. BIO_clear_retry_flags(b);
  251. BIO_copy_next_retry(b);
  252. return(ret);
  253. }
  254. static int ok_write(BIO *b, const char *in, int inl)
  255. {
  256. int ret=0,n,i;
  257. BIO_OK_CTX *ctx;
  258. if (inl <= 0) return inl;
  259. ctx=(BIO_OK_CTX *)b->ptr;
  260. ret=inl;
  261. if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
  262. if(ctx->sigio && !sig_out(b))
  263. return 0;
  264. do{
  265. BIO_clear_retry_flags(b);
  266. n=ctx->buf_len-ctx->buf_off;
  267. while (ctx->blockout && n > 0)
  268. {
  269. i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
  270. if (i <= 0)
  271. {
  272. BIO_copy_next_retry(b);
  273. if(!BIO_should_retry(b))
  274. ctx->cont= 0;
  275. return(i);
  276. }
  277. ctx->buf_off+=i;
  278. n-=i;
  279. }
  280. /* at this point all pending data has been written */
  281. ctx->blockout= 0;
  282. if (ctx->buf_len == ctx->buf_off)
  283. {
  284. ctx->buf_len=OK_BLOCK_BLOCK;
  285. ctx->buf_off=0;
  286. }
  287. if ((in == NULL) || (inl <= 0)) return(0);
  288. n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ?
  289. (int)(OK_BLOCK_SIZE+OK_BLOCK_BLOCK-ctx->buf_len) : inl;
  290. memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n);
  291. ctx->buf_len+= n;
  292. inl-=n;
  293. in+=n;
  294. if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK)
  295. {
  296. if (!block_out(b))
  297. {
  298. BIO_clear_retry_flags(b);
  299. return 0;
  300. }
  301. }
  302. }while(inl > 0);
  303. BIO_clear_retry_flags(b);
  304. BIO_copy_next_retry(b);
  305. return(ret);
  306. }
  307. static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
  308. {
  309. BIO_OK_CTX *ctx;
  310. EVP_MD *md;
  311. const EVP_MD **ppmd;
  312. long ret=1;
  313. int i;
  314. ctx=b->ptr;
  315. switch (cmd)
  316. {
  317. case BIO_CTRL_RESET:
  318. ctx->buf_len=0;
  319. ctx->buf_off=0;
  320. ctx->buf_len_save=0;
  321. ctx->buf_off_save=0;
  322. ctx->cont=1;
  323. ctx->finished=0;
  324. ctx->blockout= 0;
  325. ctx->sigio=1;
  326. ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
  327. break;
  328. case BIO_CTRL_EOF: /* More to read */
  329. if (ctx->cont <= 0)
  330. ret=1;
  331. else
  332. ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
  333. break;
  334. case BIO_CTRL_PENDING: /* More to read in buffer */
  335. case BIO_CTRL_WPENDING: /* More to read in buffer */
  336. ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0;
  337. if (ret <= 0)
  338. ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
  339. break;
  340. case BIO_CTRL_FLUSH:
  341. /* do a final write */
  342. if(ctx->blockout == 0)
  343. if (!block_out(b))
  344. return 0;
  345. while (ctx->blockout)
  346. {
  347. i=ok_write(b,NULL,0);
  348. if (i < 0)
  349. {
  350. ret=i;
  351. break;
  352. }
  353. }
  354. ctx->finished=1;
  355. ctx->buf_off=ctx->buf_len=0;
  356. ctx->cont=(int)ret;
  357. /* Finally flush the underlying BIO */
  358. ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
  359. break;
  360. case BIO_C_DO_STATE_MACHINE:
  361. BIO_clear_retry_flags(b);
  362. ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
  363. BIO_copy_next_retry(b);
  364. break;
  365. case BIO_CTRL_INFO:
  366. ret=(long)ctx->cont;
  367. break;
  368. case BIO_C_SET_MD:
  369. md=ptr;
  370. if (!EVP_DigestInit_ex(&ctx->md, md, NULL))
  371. return 0;
  372. b->init=1;
  373. break;
  374. case BIO_C_GET_MD:
  375. if (b->init)
  376. {
  377. ppmd=ptr;
  378. *ppmd=ctx->md.digest;
  379. }
  380. else
  381. ret=0;
  382. break;
  383. default:
  384. ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
  385. break;
  386. }
  387. return(ret);
  388. }
  389. static long ok_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
  390. {
  391. long ret=1;
  392. if (b->next_bio == NULL) return(0);
  393. switch (cmd)
  394. {
  395. default:
  396. ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
  397. break;
  398. }
  399. return(ret);
  400. }
  401. static void longswap(void *_ptr, size_t len)
  402. { const union { long one; char little; } is_endian = {1};
  403. if (is_endian.little) {
  404. size_t i;
  405. unsigned char *p=_ptr,c;
  406. for(i= 0;i < len;i+= 4) {
  407. c=p[0],p[0]=p[3],p[3]=c;
  408. c=p[1],p[1]=p[2],p[2]=c;
  409. }
  410. }
  411. }
  412. static int sig_out(BIO* b)
  413. {
  414. BIO_OK_CTX *ctx;
  415. EVP_MD_CTX *md;
  416. ctx=b->ptr;
  417. md=&ctx->md;
  418. if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return 1;
  419. if (!EVP_DigestInit_ex(md, md->digest, NULL))
  420. goto berr;
  421. /* FIXME: there's absolutely no guarantee this makes any sense at all,
  422. * particularly now EVP_MD_CTX has been restructured.
  423. */
  424. RAND_pseudo_bytes(md->md_data, md->digest->md_size);
  425. memcpy(&(ctx->buf[ctx->buf_len]), md->md_data, md->digest->md_size);
  426. longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
  427. ctx->buf_len+= md->digest->md_size;
  428. if (!EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN)))
  429. goto berr;
  430. if (!EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL))
  431. goto berr;
  432. ctx->buf_len+= md->digest->md_size;
  433. ctx->blockout= 1;
  434. ctx->sigio= 0;
  435. return 1;
  436. berr:
  437. BIO_clear_retry_flags(b);
  438. return 0;
  439. }
  440. static int sig_in(BIO* b)
  441. {
  442. BIO_OK_CTX *ctx;
  443. EVP_MD_CTX *md;
  444. unsigned char tmp[EVP_MAX_MD_SIZE];
  445. int ret= 0;
  446. ctx=b->ptr;
  447. md=&ctx->md;
  448. if((int)(ctx->buf_len-ctx->buf_off) < 2*md->digest->md_size) return 1;
  449. if (!EVP_DigestInit_ex(md, md->digest, NULL))
  450. goto berr;
  451. memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size);
  452. longswap(md->md_data, md->digest->md_size);
  453. ctx->buf_off+= md->digest->md_size;
  454. if (!EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN)))
  455. goto berr;
  456. if (!EVP_DigestFinal_ex(md, tmp, NULL))
  457. goto berr;
  458. ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
  459. ctx->buf_off+= md->digest->md_size;
  460. if(ret == 1)
  461. {
  462. ctx->sigio= 0;
  463. if(ctx->buf_len != ctx->buf_off)
  464. {
  465. memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
  466. }
  467. ctx->buf_len-= ctx->buf_off;
  468. ctx->buf_off= 0;
  469. }
  470. else
  471. {
  472. ctx->cont= 0;
  473. }
  474. return 1;
  475. berr:
  476. BIO_clear_retry_flags(b);
  477. return 0;
  478. }
  479. static int block_out(BIO* b)
  480. {
  481. BIO_OK_CTX *ctx;
  482. EVP_MD_CTX *md;
  483. unsigned long tl;
  484. ctx=b->ptr;
  485. md=&ctx->md;
  486. tl= ctx->buf_len- OK_BLOCK_BLOCK;
  487. ctx->buf[0]=(unsigned char)(tl>>24);
  488. ctx->buf[1]=(unsigned char)(tl>>16);
  489. ctx->buf[2]=(unsigned char)(tl>>8);
  490. ctx->buf[3]=(unsigned char)(tl);
  491. if (!EVP_DigestUpdate(md,
  492. (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl))
  493. goto berr;
  494. if (!EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL))
  495. goto berr;
  496. ctx->buf_len+= md->digest->md_size;
  497. ctx->blockout= 1;
  498. return 1;
  499. berr:
  500. BIO_clear_retry_flags(b);
  501. return 0;
  502. }
  503. static int block_in(BIO* b)
  504. {
  505. BIO_OK_CTX *ctx;
  506. EVP_MD_CTX *md;
  507. unsigned long tl= 0;
  508. unsigned char tmp[EVP_MAX_MD_SIZE];
  509. ctx=b->ptr;
  510. md=&ctx->md;
  511. assert(sizeof(tl)>=OK_BLOCK_BLOCK); /* always true */
  512. tl =ctx->buf[0]; tl<<=8;
  513. tl|=ctx->buf[1]; tl<<=8;
  514. tl|=ctx->buf[2]; tl<<=8;
  515. tl|=ctx->buf[3];
  516. if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return 1;
  517. if (!EVP_DigestUpdate(md,
  518. (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl))
  519. goto berr;
  520. if (!EVP_DigestFinal_ex(md, tmp, NULL))
  521. goto berr;
  522. if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0)
  523. {
  524. /* there might be parts from next block lurking around ! */
  525. ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size;
  526. ctx->buf_len_save= ctx->buf_len;
  527. ctx->buf_off= OK_BLOCK_BLOCK;
  528. ctx->buf_len= tl+ OK_BLOCK_BLOCK;
  529. ctx->blockout= 1;
  530. }
  531. else
  532. {
  533. ctx->cont= 0;
  534. }
  535. return 1;
  536. berr:
  537. BIO_clear_retry_flags(b);
  538. return 0;
  539. }