ec_key.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /* crypto/ec/ec_key.c */
  2. /*
  3. * Written by Nils Larsch for the OpenSSL project.
  4. */
  5. /* ====================================================================
  6. * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. All advertising materials mentioning features or use of this
  21. * software must display the following acknowledgment:
  22. * "This product includes software developed by the OpenSSL Project
  23. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  24. *
  25. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  26. * endorse or promote products derived from this software without
  27. * prior written permission. For written permission, please contact
  28. * openssl-core@openssl.org.
  29. *
  30. * 5. Products derived from this software may not be called "OpenSSL"
  31. * nor may "OpenSSL" appear in their names without prior written
  32. * permission of the OpenSSL Project.
  33. *
  34. * 6. Redistributions of any form whatsoever must retain the following
  35. * acknowledgment:
  36. * "This product includes software developed by the OpenSSL Project
  37. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  40. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  41. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  43. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  45. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  46. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  48. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  50. * OF THE POSSIBILITY OF SUCH DAMAGE.
  51. * ====================================================================
  52. *
  53. * This product includes cryptographic software written by Eric Young
  54. * (eay@cryptsoft.com). This product includes software written by Tim
  55. * Hudson (tjh@cryptsoft.com).
  56. *
  57. */
  58. /* ====================================================================
  59. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  60. * Portions originally developed by SUN MICROSYSTEMS, INC., and
  61. * contributed to the OpenSSL project.
  62. */
  63. #define OPENSSL_FIPSAPI
  64. #include <string.h>
  65. #include "ec_lcl.h"
  66. #include <openssl/err.h>
  67. #include <string.h>
  68. EC_KEY *EC_KEY_new(void)
  69. {
  70. EC_KEY *ret;
  71. ret=(EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY));
  72. if (ret == NULL)
  73. {
  74. ECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE);
  75. return(NULL);
  76. }
  77. ret->version = 1;
  78. ret->flags = 0;
  79. ret->group = NULL;
  80. ret->pub_key = NULL;
  81. ret->priv_key= NULL;
  82. ret->enc_flag= 0;
  83. ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
  84. ret->references= 1;
  85. ret->method_data = NULL;
  86. return(ret);
  87. }
  88. EC_KEY *EC_KEY_new_by_curve_name(int nid)
  89. {
  90. EC_KEY *ret = EC_KEY_new();
  91. if (ret == NULL)
  92. return NULL;
  93. ret->group = EC_GROUP_new_by_curve_name(nid);
  94. if (ret->group == NULL)
  95. {
  96. EC_KEY_free(ret);
  97. return NULL;
  98. }
  99. return ret;
  100. }
  101. void EC_KEY_free(EC_KEY *r)
  102. {
  103. int i;
  104. if (r == NULL) return;
  105. i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_EC);
  106. #ifdef REF_PRINT
  107. REF_PRINT("EC_KEY",r);
  108. #endif
  109. if (i > 0) return;
  110. #ifdef REF_CHECK
  111. if (i < 0)
  112. {
  113. fprintf(stderr,"EC_KEY_free, bad reference count\n");
  114. abort();
  115. }
  116. #endif
  117. if (r->group != NULL)
  118. EC_GROUP_free(r->group);
  119. if (r->pub_key != NULL)
  120. EC_POINT_free(r->pub_key);
  121. if (r->priv_key != NULL)
  122. BN_clear_free(r->priv_key);
  123. EC_EX_DATA_free_all_data(&r->method_data);
  124. OPENSSL_cleanse((void *)r, sizeof(EC_KEY));
  125. OPENSSL_free(r);
  126. }
  127. EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
  128. {
  129. EC_EXTRA_DATA *d;
  130. if (dest == NULL || src == NULL)
  131. {
  132. ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER);
  133. return NULL;
  134. }
  135. /* copy the parameters */
  136. if (src->group)
  137. {
  138. const EC_METHOD *meth = EC_GROUP_method_of(src->group);
  139. /* clear the old group */
  140. if (dest->group)
  141. EC_GROUP_free(dest->group);
  142. dest->group = EC_GROUP_new(meth);
  143. if (dest->group == NULL)
  144. return NULL;
  145. if (!EC_GROUP_copy(dest->group, src->group))
  146. return NULL;
  147. }
  148. /* copy the public key */
  149. if (src->pub_key && src->group)
  150. {
  151. if (dest->pub_key)
  152. EC_POINT_free(dest->pub_key);
  153. dest->pub_key = EC_POINT_new(src->group);
  154. if (dest->pub_key == NULL)
  155. return NULL;
  156. if (!EC_POINT_copy(dest->pub_key, src->pub_key))
  157. return NULL;
  158. }
  159. /* copy the private key */
  160. if (src->priv_key)
  161. {
  162. if (dest->priv_key == NULL)
  163. {
  164. dest->priv_key = BN_new();
  165. if (dest->priv_key == NULL)
  166. return NULL;
  167. }
  168. if (!BN_copy(dest->priv_key, src->priv_key))
  169. return NULL;
  170. }
  171. /* copy method/extra data */
  172. EC_EX_DATA_free_all_data(&dest->method_data);
  173. for (d = src->method_data; d != NULL; d = d->next)
  174. {
  175. void *t = d->dup_func(d->data);
  176. if (t == NULL)
  177. return 0;
  178. if (!EC_EX_DATA_set_data(&dest->method_data, t, d->dup_func, d->free_func, d->clear_free_func))
  179. return 0;
  180. }
  181. /* copy the rest */
  182. dest->enc_flag = src->enc_flag;
  183. dest->conv_form = src->conv_form;
  184. dest->version = src->version;
  185. dest->flags = src->flags;
  186. return dest;
  187. }
  188. EC_KEY *EC_KEY_dup(const EC_KEY *ec_key)
  189. {
  190. EC_KEY *ret = EC_KEY_new();
  191. if (ret == NULL)
  192. return NULL;
  193. if (EC_KEY_copy(ret, ec_key) == NULL)
  194. {
  195. EC_KEY_free(ret);
  196. return NULL;
  197. }
  198. return ret;
  199. }
  200. int EC_KEY_up_ref(EC_KEY *r)
  201. {
  202. int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC);
  203. #ifdef REF_PRINT
  204. REF_PRINT("EC_KEY",r);
  205. #endif
  206. #ifdef REF_CHECK
  207. if (i < 2)
  208. {
  209. fprintf(stderr, "EC_KEY_up, bad reference count\n");
  210. abort();
  211. }
  212. #endif
  213. return ((i > 1) ? 1 : 0);
  214. }
  215. #ifdef OPENSSL_FIPS
  216. #include <openssl/evp.h>
  217. #include <openssl/fips.h>
  218. #include <openssl/fips_rand.h>
  219. static int fips_check_ec(EC_KEY *key)
  220. {
  221. EVP_PKEY pk;
  222. unsigned char tbs[] = "ECDSA Pairwise Check Data";
  223. pk.type = EVP_PKEY_EC;
  224. pk.pkey.ec = key;
  225. if (!fips_pkey_signature_test(FIPS_TEST_PAIRWISE,
  226. &pk, tbs, 0, NULL, 0, NULL, 0, NULL))
  227. {
  228. FIPSerr(FIPS_F_FIPS_CHECK_EC,FIPS_R_PAIRWISE_TEST_FAILED);
  229. fips_set_selftest_fail();
  230. return 0;
  231. }
  232. return 1;
  233. }
  234. int fips_check_ec_prng(EC_KEY *ec)
  235. {
  236. int bits, strength;
  237. if (!FIPS_module_mode())
  238. return 1;
  239. if (ec->flags & (EC_FLAG_NON_FIPS_ALLOW|EC_FLAG_FIPS_CHECKED))
  240. return 1;
  241. if (!ec->group)
  242. return 1;
  243. bits = BN_num_bits(&ec->group->order);
  244. if (bits < 160)
  245. {
  246. FIPSerr(FIPS_F_FIPS_CHECK_EC_PRNG,FIPS_R_KEY_TOO_SHORT);
  247. return 0;
  248. }
  249. /* Comparable algorithm strengths: from SP800-57 table 2 */
  250. if (bits >= 512)
  251. strength = 256;
  252. else if (bits >= 384)
  253. strength = 192;
  254. else if (bits >= 256)
  255. strength = 128;
  256. else if (bits >= 224)
  257. strength = 112;
  258. else
  259. strength = 80;
  260. if (FIPS_rand_strength() >= strength)
  261. return 1;
  262. FIPSerr(FIPS_F_FIPS_CHECK_EC_PRNG,FIPS_R_PRNG_STRENGTH_TOO_LOW);
  263. return 0;
  264. }
  265. #endif
  266. int EC_KEY_generate_key(EC_KEY *eckey)
  267. {
  268. int ok = 0;
  269. BN_CTX *ctx = NULL;
  270. BIGNUM *priv_key = NULL, *order = NULL;
  271. EC_POINT *pub_key = NULL;
  272. #ifdef OPENSSL_FIPS
  273. if(FIPS_selftest_failed())
  274. {
  275. FIPSerr(FIPS_F_EC_KEY_GENERATE_KEY,FIPS_R_FIPS_SELFTEST_FAILED);
  276. return 0;
  277. }
  278. #endif
  279. if (!eckey || !eckey->group)
  280. {
  281. ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);
  282. return 0;
  283. }
  284. if ((order = BN_new()) == NULL) goto err;
  285. if ((ctx = BN_CTX_new()) == NULL) goto err;
  286. if (eckey->priv_key == NULL)
  287. {
  288. priv_key = BN_new();
  289. if (priv_key == NULL)
  290. goto err;
  291. }
  292. else
  293. priv_key = eckey->priv_key;
  294. if (!EC_GROUP_get_order(eckey->group, order, ctx))
  295. goto err;
  296. #ifdef OPENSSL_FIPS
  297. if (!fips_check_ec_prng(eckey))
  298. goto err;
  299. #endif
  300. do
  301. if (!BN_rand_range(priv_key, order))
  302. goto err;
  303. while (BN_is_zero(priv_key));
  304. if (eckey->pub_key == NULL)
  305. {
  306. pub_key = EC_POINT_new(eckey->group);
  307. if (pub_key == NULL)
  308. goto err;
  309. }
  310. else
  311. pub_key = eckey->pub_key;
  312. if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))
  313. goto err;
  314. eckey->priv_key = priv_key;
  315. eckey->pub_key = pub_key;
  316. #ifdef OPENSSL_FIPS
  317. if(!fips_check_ec(eckey))
  318. {
  319. eckey->priv_key = NULL;
  320. eckey->pub_key = NULL;
  321. goto err;
  322. }
  323. #endif
  324. ok=1;
  325. err:
  326. if (order)
  327. BN_free(order);
  328. if (pub_key != NULL && eckey->pub_key == NULL)
  329. EC_POINT_free(pub_key);
  330. if (priv_key != NULL && eckey->priv_key == NULL)
  331. BN_free(priv_key);
  332. if (ctx != NULL)
  333. BN_CTX_free(ctx);
  334. return(ok);
  335. }
  336. int EC_KEY_check_key(const EC_KEY *eckey)
  337. {
  338. int ok = 0;
  339. BN_CTX *ctx = NULL;
  340. const BIGNUM *order = NULL;
  341. EC_POINT *point = NULL;
  342. if (!eckey || !eckey->group || !eckey->pub_key)
  343. {
  344. ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);
  345. return 0;
  346. }
  347. if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key))
  348. {
  349. ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY);
  350. goto err;
  351. }
  352. if ((ctx = BN_CTX_new()) == NULL)
  353. goto err;
  354. if ((point = EC_POINT_new(eckey->group)) == NULL)
  355. goto err;
  356. /* testing whether the pub_key is on the elliptic curve */
  357. if (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx))
  358. {
  359. ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE);
  360. goto err;
  361. }
  362. /* testing whether pub_key * order is the point at infinity */
  363. order = &eckey->group->order;
  364. if (BN_is_zero(order))
  365. {
  366. ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);
  367. goto err;
  368. }
  369. if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx))
  370. {
  371. ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
  372. goto err;
  373. }
  374. if (!EC_POINT_is_at_infinity(eckey->group, point))
  375. {
  376. ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
  377. goto err;
  378. }
  379. /* in case the priv_key is present :
  380. * check if generator * priv_key == pub_key
  381. */
  382. if (eckey->priv_key)
  383. {
  384. if (BN_cmp(eckey->priv_key, order) >= 0)
  385. {
  386. ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
  387. goto err;
  388. }
  389. if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
  390. NULL, NULL, ctx))
  391. {
  392. ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
  393. goto err;
  394. }
  395. if (EC_POINT_cmp(eckey->group, point, eckey->pub_key,
  396. ctx) != 0)
  397. {
  398. ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY);
  399. goto err;
  400. }
  401. }
  402. ok = 1;
  403. err:
  404. if (ctx != NULL)
  405. BN_CTX_free(ctx);
  406. if (point != NULL)
  407. EC_POINT_free(point);
  408. return(ok);
  409. }
  410. int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y)
  411. {
  412. BN_CTX *ctx = NULL;
  413. BIGNUM *tx, *ty;
  414. EC_POINT *point = NULL;
  415. int ok = 0, tmp_nid, is_char_two = 0;
  416. if (!key || !key->group || !x || !y)
  417. {
  418. ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES,
  419. ERR_R_PASSED_NULL_PARAMETER);
  420. return 0;
  421. }
  422. ctx = BN_CTX_new();
  423. if (!ctx)
  424. goto err;
  425. point = EC_POINT_new(key->group);
  426. if (!point)
  427. goto err;
  428. tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(key->group));
  429. if (tmp_nid == NID_X9_62_characteristic_two_field)
  430. is_char_two = 1;
  431. tx = BN_CTX_get(ctx);
  432. ty = BN_CTX_get(ctx);
  433. #ifndef OPENSSL_NO_EC2M
  434. if (is_char_two)
  435. {
  436. if (!EC_POINT_set_affine_coordinates_GF2m(key->group, point,
  437. x, y, ctx))
  438. goto err;
  439. if (!EC_POINT_get_affine_coordinates_GF2m(key->group, point,
  440. tx, ty, ctx))
  441. goto err;
  442. }
  443. else
  444. #endif
  445. {
  446. if (!EC_POINT_set_affine_coordinates_GFp(key->group, point,
  447. x, y, ctx))
  448. goto err;
  449. if (!EC_POINT_get_affine_coordinates_GFp(key->group, point,
  450. tx, ty, ctx))
  451. goto err;
  452. }
  453. /* Check if retrieved coordinates match originals and are less than
  454. * field order: if not values are out of range.
  455. */
  456. if (BN_cmp(x, tx) || BN_cmp(y, ty)
  457. || (BN_cmp(x, &key->group->field) >= 0)
  458. || (BN_cmp(y, &key->group->field) >= 0))
  459. {
  460. ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES,
  461. EC_R_COORDINATES_OUT_OF_RANGE);
  462. goto err;
  463. }
  464. if (!EC_KEY_set_public_key(key, point))
  465. goto err;
  466. if (EC_KEY_check_key(key) == 0)
  467. goto err;
  468. ok = 1;
  469. err:
  470. if (ctx)
  471. BN_CTX_free(ctx);
  472. if (point)
  473. EC_POINT_free(point);
  474. return ok;
  475. }
  476. const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  477. {
  478. return key->group;
  479. }
  480. int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)
  481. {
  482. if (key->group != NULL)
  483. EC_GROUP_free(key->group);
  484. key->group = EC_GROUP_dup(group);
  485. return (key->group == NULL) ? 0 : 1;
  486. }
  487. const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
  488. {
  489. return key->priv_key;
  490. }
  491. int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
  492. {
  493. if (key->priv_key)
  494. BN_clear_free(key->priv_key);
  495. key->priv_key = BN_dup(priv_key);
  496. return (key->priv_key == NULL) ? 0 : 1;
  497. }
  498. const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key)
  499. {
  500. return key->pub_key;
  501. }
  502. int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key)
  503. {
  504. if (key->pub_key != NULL)
  505. EC_POINT_free(key->pub_key);
  506. key->pub_key = EC_POINT_dup(pub_key, key->group);
  507. return (key->pub_key == NULL) ? 0 : 1;
  508. }
  509. unsigned int EC_KEY_get_enc_flags(const EC_KEY *key)
  510. {
  511. return key->enc_flag;
  512. }
  513. void EC_KEY_set_enc_flags(EC_KEY *key, unsigned int flags)
  514. {
  515. key->enc_flag = flags;
  516. }
  517. point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key)
  518. {
  519. return key->conv_form;
  520. }
  521. void EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform)
  522. {
  523. key->conv_form = cform;
  524. if (key->group != NULL)
  525. EC_GROUP_set_point_conversion_form(key->group, cform);
  526. }
  527. void *EC_KEY_get_key_method_data(EC_KEY *key,
  528. void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
  529. {
  530. return EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
  531. }
  532. void EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
  533. void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
  534. {
  535. EC_EXTRA_DATA *ex_data;
  536. CRYPTO_w_lock(CRYPTO_LOCK_EC);
  537. ex_data = EC_EX_DATA_get_data(key->method_data, dup_func, free_func, clear_free_func);
  538. if (ex_data == NULL)
  539. EC_EX_DATA_set_data(&key->method_data, data, dup_func, free_func, clear_free_func);
  540. CRYPTO_w_unlock(CRYPTO_LOCK_EC);
  541. }
  542. void EC_KEY_set_asn1_flag(EC_KEY *key, int flag)
  543. {
  544. if (key->group != NULL)
  545. EC_GROUP_set_asn1_flag(key->group, flag);
  546. }
  547. int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx)
  548. {
  549. if (key->group == NULL)
  550. return 0;
  551. return EC_GROUP_precompute_mult(key->group, ctx);
  552. }
  553. int EC_KEY_get_flags(const EC_KEY *key)
  554. {
  555. return key->flags;
  556. }
  557. void EC_KEY_set_flags(EC_KEY *key, int flags)
  558. {
  559. key->flags |= flags;
  560. }
  561. void EC_KEY_clear_flags(EC_KEY *key, int flags)
  562. {
  563. key->flags &= ~flags;
  564. }