p12_mutl.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Copyright 1999-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*
  10. * HMAC low level APIs are deprecated for public use, but still ok for internal
  11. * use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <stdio.h>
  15. #include "internal/cryptlib.h"
  16. #include "crypto/evp.h"
  17. #include <openssl/crypto.h>
  18. #include <openssl/hmac.h>
  19. #include <openssl/rand.h>
  20. #include <openssl/pkcs12.h>
  21. #include "p12_local.h"
  22. static int pkcs12_pbmac1_pbkdf2_key_gen(const char *pass, int passlen,
  23. unsigned char *salt, int saltlen,
  24. int id, int iter, int keylen,
  25. unsigned char *out,
  26. const EVP_MD *md_type);
  27. int PKCS12_mac_present(const PKCS12 *p12)
  28. {
  29. return p12->mac ? 1 : 0;
  30. }
  31. void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
  32. const X509_ALGOR **pmacalg,
  33. const ASN1_OCTET_STRING **psalt,
  34. const ASN1_INTEGER **piter,
  35. const PKCS12 *p12)
  36. {
  37. if (p12->mac) {
  38. X509_SIG_get0(p12->mac->dinfo, pmacalg, pmac);
  39. if (psalt)
  40. *psalt = p12->mac->salt;
  41. if (piter)
  42. *piter = p12->mac->iter;
  43. } else {
  44. if (pmac)
  45. *pmac = NULL;
  46. if (pmacalg)
  47. *pmacalg = NULL;
  48. if (psalt)
  49. *psalt = NULL;
  50. if (piter)
  51. *piter = NULL;
  52. }
  53. }
  54. #define TK26_MAC_KEY_LEN 32
  55. static int pkcs12_gen_gost_mac_key(const char *pass, int passlen,
  56. const unsigned char *salt, int saltlen,
  57. int iter, int keylen, unsigned char *key,
  58. const EVP_MD *digest)
  59. {
  60. unsigned char out[96];
  61. if (keylen != TK26_MAC_KEY_LEN) {
  62. return 0;
  63. }
  64. if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter,
  65. digest, sizeof(out), out)) {
  66. return 0;
  67. }
  68. memcpy(key, out + sizeof(out) - TK26_MAC_KEY_LEN, TK26_MAC_KEY_LEN);
  69. OPENSSL_cleanse(out, sizeof(out));
  70. return 1;
  71. }
  72. PBKDF2PARAM *PBMAC1_get1_pbkdf2_param(const X509_ALGOR *macalg)
  73. {
  74. PBMAC1PARAM *param = NULL;
  75. PBKDF2PARAM *pbkdf2_param = NULL;
  76. const ASN1_OBJECT *kdf_oid;
  77. param = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBMAC1PARAM), macalg->parameter);
  78. if (param == NULL) {
  79. ERR_raise(ERR_LIB_PKCS12, ERR_R_PASSED_INVALID_ARGUMENT);
  80. return NULL;
  81. }
  82. X509_ALGOR_get0(&kdf_oid, NULL, NULL, param->keyDerivationFunc);
  83. if (OBJ_obj2nid(kdf_oid) != NID_id_pbkdf2) {
  84. ERR_raise(ERR_LIB_PKCS12, ERR_R_PASSED_INVALID_ARGUMENT);
  85. PBMAC1PARAM_free(param);
  86. return NULL;
  87. }
  88. pbkdf2_param = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBKDF2PARAM),
  89. param->keyDerivationFunc->parameter);
  90. PBMAC1PARAM_free(param);
  91. return pbkdf2_param;
  92. }
  93. static int PBMAC1_PBKDF2_HMAC(OSSL_LIB_CTX *ctx, const char *propq,
  94. const char *pass, int passlen,
  95. const X509_ALGOR *macalg, unsigned char *key)
  96. {
  97. PBKDF2PARAM *pbkdf2_param = NULL;
  98. const ASN1_OBJECT *kdf_hmac_oid;
  99. int kdf_hmac_nid;
  100. int ret = -1;
  101. int keylen = 0;
  102. EVP_MD *kdf_md = NULL;
  103. const ASN1_OCTET_STRING *pbkdf2_salt = NULL;
  104. pbkdf2_param = PBMAC1_get1_pbkdf2_param(macalg);
  105. if (pbkdf2_param == NULL) {
  106. ERR_raise(ERR_LIB_PKCS12, ERR_R_UNSUPPORTED);
  107. goto err;
  108. }
  109. keylen = ASN1_INTEGER_get(pbkdf2_param->keylength);
  110. pbkdf2_salt = pbkdf2_param->salt->value.octet_string;
  111. if (pbkdf2_param->prf == NULL) {
  112. kdf_hmac_nid = NID_hmacWithSHA1;
  113. } else {
  114. X509_ALGOR_get0(&kdf_hmac_oid, NULL, NULL, pbkdf2_param->prf);
  115. kdf_hmac_nid = OBJ_obj2nid(kdf_hmac_oid);
  116. }
  117. kdf_md = EVP_MD_fetch(ctx, OBJ_nid2sn(ossl_hmac2mdnid(kdf_hmac_nid)), propq);
  118. if (kdf_md == NULL) {
  119. ERR_raise(ERR_LIB_PKCS12, ERR_R_FETCH_FAILED);
  120. goto err;
  121. }
  122. if (PKCS5_PBKDF2_HMAC(pass, passlen, pbkdf2_salt->data, pbkdf2_salt->length,
  123. ASN1_INTEGER_get(pbkdf2_param->iter), kdf_md, keylen, key) <= 0) {
  124. ERR_raise(ERR_LIB_PKCS12, ERR_R_INTERNAL_ERROR);
  125. goto err;
  126. }
  127. ret = keylen;
  128. err:
  129. EVP_MD_free(kdf_md);
  130. PBKDF2PARAM_free(pbkdf2_param);
  131. return ret;
  132. }
  133. /* Generate a MAC, also used for verification */
  134. static int pkcs12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
  135. unsigned char *mac, unsigned int *maclen,
  136. int pbmac1_md_nid, int pbmac1_kdf_nid,
  137. int (*pkcs12_key_gen)(const char *pass, int passlen,
  138. unsigned char *salt, int slen,
  139. int id, int iter, int n,
  140. unsigned char *out,
  141. const EVP_MD *md_type))
  142. {
  143. int ret = 0;
  144. const EVP_MD *md;
  145. EVP_MD *md_fetch;
  146. HMAC_CTX *hmac = NULL;
  147. unsigned char key[EVP_MAX_MD_SIZE], *salt;
  148. int saltlen, iter;
  149. char md_name[80];
  150. int keylen = 0;
  151. int md_nid = NID_undef;
  152. const X509_ALGOR *macalg;
  153. const ASN1_OBJECT *macoid;
  154. if (!PKCS7_type_is_data(p12->authsafes)) {
  155. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_CONTENT_TYPE_NOT_DATA);
  156. return 0;
  157. }
  158. if (p12->authsafes->d.data == NULL) {
  159. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_DECODE_ERROR);
  160. return 0;
  161. }
  162. salt = p12->mac->salt->data;
  163. saltlen = p12->mac->salt->length;
  164. if (p12->mac->iter == NULL)
  165. iter = 1;
  166. else
  167. iter = ASN1_INTEGER_get(p12->mac->iter);
  168. X509_SIG_get0(p12->mac->dinfo, &macalg, NULL);
  169. X509_ALGOR_get0(&macoid, NULL, NULL, macalg);
  170. if (OBJ_obj2nid(macoid) == NID_pbmac1) {
  171. if (OBJ_obj2txt(md_name, sizeof(md_name), OBJ_nid2obj(pbmac1_md_nid), 0) < 0)
  172. return 0;
  173. } else {
  174. if (OBJ_obj2txt(md_name, sizeof(md_name), macoid, 0) < 0)
  175. return 0;
  176. }
  177. (void)ERR_set_mark();
  178. md = md_fetch = EVP_MD_fetch(p12->authsafes->ctx.libctx, md_name,
  179. p12->authsafes->ctx.propq);
  180. if (md == NULL)
  181. md = EVP_get_digestbynid(OBJ_obj2nid(macoid));
  182. if (md == NULL) {
  183. (void)ERR_clear_last_mark();
  184. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
  185. return 0;
  186. }
  187. (void)ERR_pop_to_mark();
  188. keylen = EVP_MD_get_size(md);
  189. md_nid = EVP_MD_get_type(md);
  190. if (keylen <= 0)
  191. goto err;
  192. /* For PBMAC1 we use a special keygen callback if not provided (e.g. on verification) */
  193. if (pbmac1_md_nid != NID_undef && pkcs12_key_gen == NULL) {
  194. keylen = PBMAC1_PBKDF2_HMAC(p12->authsafes->ctx.libctx, p12->authsafes->ctx.propq,
  195. pass, passlen, macalg, key);
  196. if (keylen < 0)
  197. goto err;
  198. } else if ((md_nid == NID_id_GostR3411_94
  199. || md_nid == NID_id_GostR3411_2012_256
  200. || md_nid == NID_id_GostR3411_2012_512)
  201. && ossl_safe_getenv("LEGACY_GOST_PKCS12") == NULL) {
  202. keylen = TK26_MAC_KEY_LEN;
  203. if (!pkcs12_gen_gost_mac_key(pass, passlen, salt, saltlen, iter,
  204. keylen, key, md)) {
  205. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_KEY_GEN_ERROR);
  206. goto err;
  207. }
  208. } else {
  209. EVP_MD *hmac_md = (EVP_MD *)md;
  210. int fetched = 0;
  211. if (pbmac1_kdf_nid != NID_undef) {
  212. char hmac_md_name[128];
  213. if (OBJ_obj2txt(hmac_md_name, sizeof(hmac_md_name), OBJ_nid2obj(pbmac1_kdf_nid), 0) < 0)
  214. goto err;
  215. hmac_md = EVP_MD_fetch(NULL, hmac_md_name, NULL);
  216. if (hmac_md == NULL)
  217. goto err;
  218. fetched = 1;
  219. }
  220. if (pkcs12_key_gen != NULL) {
  221. int res = (*pkcs12_key_gen)(pass, passlen, salt, saltlen, PKCS12_MAC_ID,
  222. iter, keylen, key, hmac_md);
  223. if (fetched)
  224. EVP_MD_free(hmac_md);
  225. if (res != 1) {
  226. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_KEY_GEN_ERROR);
  227. goto err;
  228. }
  229. } else {
  230. if (fetched)
  231. EVP_MD_free(hmac_md);
  232. /* Default to UTF-8 password */
  233. if (!PKCS12_key_gen_utf8_ex(pass, passlen, salt, saltlen, PKCS12_MAC_ID,
  234. iter, keylen, key, md,
  235. p12->authsafes->ctx.libctx, p12->authsafes->ctx.propq)) {
  236. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_KEY_GEN_ERROR);
  237. goto err;
  238. }
  239. }
  240. }
  241. if ((hmac = HMAC_CTX_new()) == NULL
  242. || !HMAC_Init_ex(hmac, key, keylen, md, NULL)
  243. || !HMAC_Update(hmac, p12->authsafes->d.data->data,
  244. p12->authsafes->d.data->length)
  245. || !HMAC_Final(hmac, mac, maclen)) {
  246. goto err;
  247. }
  248. ret = 1;
  249. err:
  250. OPENSSL_cleanse(key, sizeof(key));
  251. HMAC_CTX_free(hmac);
  252. EVP_MD_free(md_fetch);
  253. return ret;
  254. }
  255. int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
  256. unsigned char *mac, unsigned int *maclen)
  257. {
  258. return pkcs12_gen_mac(p12, pass, passlen, mac, maclen, NID_undef, NID_undef, NULL);
  259. }
  260. /* Verify the mac */
  261. int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen)
  262. {
  263. unsigned char mac[EVP_MAX_MD_SIZE];
  264. unsigned int maclen;
  265. const ASN1_OCTET_STRING *macoct;
  266. const X509_ALGOR *macalg;
  267. const ASN1_OBJECT *macoid;
  268. if (p12->mac == NULL) {
  269. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_ABSENT);
  270. return 0;
  271. }
  272. X509_SIG_get0(p12->mac->dinfo, &macalg, NULL);
  273. X509_ALGOR_get0(&macoid, NULL, NULL, macalg);
  274. if (OBJ_obj2nid(macoid) == NID_pbmac1) {
  275. PBMAC1PARAM *param = NULL;
  276. const ASN1_OBJECT *hmac_oid;
  277. int md_nid = NID_undef;
  278. param = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBMAC1PARAM), macalg->parameter);
  279. if (param == NULL) {
  280. ERR_raise(ERR_LIB_PKCS12, ERR_R_UNSUPPORTED);
  281. return 0;
  282. }
  283. X509_ALGOR_get0(&hmac_oid, NULL, NULL, param->messageAuthScheme);
  284. md_nid = ossl_hmac2mdnid(OBJ_obj2nid(hmac_oid));
  285. if (!pkcs12_gen_mac(p12, pass, passlen, mac, &maclen, md_nid, NID_undef, NULL)) {
  286. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_GENERATION_ERROR);
  287. PBMAC1PARAM_free(param);
  288. return 0;
  289. }
  290. PBMAC1PARAM_free(param);
  291. } else {
  292. if (!pkcs12_gen_mac(p12, pass, passlen, mac, &maclen, NID_undef, NID_undef, NULL)) {
  293. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_GENERATION_ERROR);
  294. return 0;
  295. }
  296. }
  297. X509_SIG_get0(p12->mac->dinfo, NULL, &macoct);
  298. if ((maclen != (unsigned int)ASN1_STRING_length(macoct))
  299. || CRYPTO_memcmp(mac, ASN1_STRING_get0_data(macoct), maclen) != 0)
  300. return 0;
  301. return 1;
  302. }
  303. /* Set a mac */
  304. int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
  305. unsigned char *salt, int saltlen, int iter,
  306. const EVP_MD *md_type)
  307. {
  308. unsigned char mac[EVP_MAX_MD_SIZE];
  309. unsigned int maclen;
  310. ASN1_OCTET_STRING *macoct;
  311. if (md_type == NULL)
  312. /* No need to do a fetch as the md_type is used only to get a NID */
  313. md_type = EVP_sha256();
  314. if (!iter)
  315. iter = PKCS12_DEFAULT_ITER;
  316. if (PKCS12_setup_mac(p12, iter, salt, saltlen, md_type) == PKCS12_ERROR) {
  317. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_SETUP_ERROR);
  318. return 0;
  319. }
  320. /*
  321. * Note that output mac is forced to UTF-8...
  322. */
  323. if (!pkcs12_gen_mac(p12, pass, passlen, mac, &maclen, NID_undef, NID_undef, NULL)) {
  324. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_GENERATION_ERROR);
  325. return 0;
  326. }
  327. X509_SIG_getm(p12->mac->dinfo, NULL, &macoct);
  328. if (!ASN1_OCTET_STRING_set(macoct, mac, maclen)) {
  329. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_STRING_SET_ERROR);
  330. return 0;
  331. }
  332. return 1;
  333. }
  334. static int pkcs12_pbmac1_pbkdf2_key_gen(const char *pass, int passlen,
  335. unsigned char *salt, int saltlen,
  336. int id, int iter, int keylen,
  337. unsigned char *out,
  338. const EVP_MD *md_type)
  339. {
  340. return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter,
  341. md_type, keylen, out);
  342. }
  343. static int pkcs12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
  344. int nid)
  345. {
  346. X509_ALGOR *macalg;
  347. PKCS12_MAC_DATA_free(p12->mac);
  348. p12->mac = NULL;
  349. if ((p12->mac = PKCS12_MAC_DATA_new()) == NULL)
  350. return PKCS12_ERROR;
  351. if (iter > 1) {
  352. if ((p12->mac->iter = ASN1_INTEGER_new()) == NULL) {
  353. ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
  354. return 0;
  355. }
  356. if (!ASN1_INTEGER_set(p12->mac->iter, iter)) {
  357. ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
  358. return 0;
  359. }
  360. }
  361. if (saltlen == 0)
  362. saltlen = PKCS12_SALT_LEN;
  363. else if (saltlen < 0)
  364. return 0;
  365. if ((p12->mac->salt->data = OPENSSL_malloc(saltlen)) == NULL)
  366. return 0;
  367. p12->mac->salt->length = saltlen;
  368. if (salt == NULL) {
  369. if (RAND_bytes_ex(p12->authsafes->ctx.libctx, p12->mac->salt->data,
  370. (size_t)saltlen, 0) <= 0)
  371. return 0;
  372. } else {
  373. memcpy(p12->mac->salt->data, salt, saltlen);
  374. }
  375. X509_SIG_getm(p12->mac->dinfo, &macalg, NULL);
  376. if (!X509_ALGOR_set0(macalg, OBJ_nid2obj(nid), V_ASN1_NULL, NULL)) {
  377. ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
  378. return 0;
  379. }
  380. return 1;
  381. }
  382. /* Set up a mac structure */
  383. int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
  384. const EVP_MD *md_type)
  385. {
  386. return pkcs12_setup_mac(p12, iter, salt, saltlen, EVP_MD_get_type(md_type));
  387. }
  388. int PKCS12_set_pbmac1_pbkdf2(PKCS12 *p12, const char *pass, int passlen,
  389. unsigned char *salt, int saltlen, int iter,
  390. const EVP_MD *md_type, const char *prf_md_name)
  391. {
  392. unsigned char mac[EVP_MAX_MD_SIZE];
  393. unsigned int maclen;
  394. ASN1_OCTET_STRING *macoct;
  395. X509_ALGOR *alg = NULL;
  396. int ret = 0;
  397. int prf_md_nid = NID_undef, prf_nid = NID_undef, hmac_nid;
  398. unsigned char *known_salt = NULL;
  399. int keylen = 0;
  400. PBMAC1PARAM *param = NULL;
  401. X509_ALGOR *hmac_alg = NULL, *macalg = NULL;
  402. if (md_type == NULL)
  403. /* No need to do a fetch as the md_type is used only to get a NID */
  404. md_type = EVP_sha256();
  405. if (prf_md_name == NULL)
  406. prf_md_nid = EVP_MD_get_type(md_type);
  407. else
  408. prf_md_nid = OBJ_txt2nid(prf_md_name);
  409. if (iter == 0)
  410. iter = PKCS12_DEFAULT_ITER;
  411. keylen = EVP_MD_get_size(md_type);
  412. prf_nid = ossl_md2hmacnid(prf_md_nid);
  413. hmac_nid = ossl_md2hmacnid(EVP_MD_get_type(md_type));
  414. if (prf_nid == NID_undef || hmac_nid == NID_undef) {
  415. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
  416. goto err;
  417. }
  418. if (salt == NULL) {
  419. known_salt = OPENSSL_malloc(saltlen);
  420. if (known_salt == NULL)
  421. goto err;
  422. if (RAND_bytes_ex(NULL, known_salt, saltlen, 0) <= 0) {
  423. ERR_raise(ERR_LIB_PKCS12, ERR_R_RAND_LIB);
  424. goto err;
  425. }
  426. }
  427. param = PBMAC1PARAM_new();
  428. hmac_alg = X509_ALGOR_new();
  429. alg = PKCS5_pbkdf2_set(iter, salt ? salt : known_salt, saltlen, prf_nid, keylen);
  430. if (param == NULL || hmac_alg == NULL || alg == NULL)
  431. goto err;
  432. if (pkcs12_setup_mac(p12, iter, salt ? salt : known_salt, saltlen,
  433. NID_pbmac1) == PKCS12_ERROR) {
  434. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_SETUP_ERROR);
  435. goto err;
  436. }
  437. if (!X509_ALGOR_set0(hmac_alg, OBJ_nid2obj(hmac_nid), V_ASN1_NULL, NULL)) {
  438. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_SETUP_ERROR);
  439. goto err;
  440. }
  441. X509_ALGOR_free(param->keyDerivationFunc);
  442. X509_ALGOR_free(param->messageAuthScheme);
  443. param->keyDerivationFunc = alg;
  444. param->messageAuthScheme = hmac_alg;
  445. X509_SIG_getm(p12->mac->dinfo, &macalg, &macoct);
  446. if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBMAC1PARAM), param, &macalg->parameter))
  447. goto err;
  448. /*
  449. * Note that output mac is forced to UTF-8...
  450. */
  451. if (!pkcs12_gen_mac(p12, pass, passlen, mac, &maclen,
  452. EVP_MD_get_type(md_type), prf_md_nid,
  453. pkcs12_pbmac1_pbkdf2_key_gen)) {
  454. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_GENERATION_ERROR);
  455. goto err;
  456. }
  457. if (!ASN1_OCTET_STRING_set(macoct, mac, maclen)) {
  458. ERR_raise(ERR_LIB_PKCS12, PKCS12_R_MAC_STRING_SET_ERROR);
  459. goto err;
  460. }
  461. ret = 1;
  462. err:
  463. PBMAC1PARAM_free(param);
  464. OPENSSL_free(known_salt);
  465. return ret;
  466. }