OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
OPT_INFORM, OPT_OUTFORM, OPT_ENGINE, OPT_IN, OPT_OUT,
OPT_TOPK8, OPT_NOITER, OPT_NOCRYPT, OPT_NOOCT, OPT_NSDB, OPT_EMBED,
- OPT_V2, OPT_V1, OPT_V2PRF, OPT_ITER, OPT_PASSIN, OPT_PASSOUT
+ OPT_V2, OPT_V1, OPT_V2PRF, OPT_ITER, OPT_PASSIN, OPT_PASSOUT,
+ OPT_SCRYPT, OPT_SCRYPT_N, OPT_SCRYPT_R, OPT_SCRYPT_P
} OPTION_CHOICE;
OPTIONS pkcs8_options[] = {
#ifndef OPENSSL_NO_ENGINE
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
#endif
+ {"scrypt", OPT_SCRYPT, '-', "Use scrypt algorithm"},
+ {"scrypt_N", OPT_SCRYPT_N, 's', "Set scrypt N parameter"},
+ {"scrypt_r", OPT_SCRYPT_R, 's', "Set scrypt r parameter"},
+ {"scrypt_p", OPT_SCRYPT_P, 's', "Set scrypt p parameter"},
{NULL}
};
OPTION_CHOICE o;
int nocrypt = 0, ret = 1, iter = PKCS12_DEFAULT_ITER, p8_broken = PKCS8_OK;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, topk8 = 0, pbe_nid = -1;
+ uint64_t scrypt_N = 0, scrypt_r = 0, scrypt_p = 0;
prog = opt_init(argc, argv, pkcs8_options);
while ((o = opt_next()) != OPT_EOF) {
case OPT_ENGINE:
e = setup_engine(opt_arg(), 0);
break;
+ case OPT_SCRYPT:
+ scrypt_N = 1024;
+ scrypt_r = 8;
+ scrypt_p = 16;
+ if (cipher == NULL)
+ cipher = EVP_aes_256_cbc();
+ break;
+ case OPT_SCRYPT_N:
+ if (!opt_ulong(opt_arg(), &scrypt_N))
+ goto opthelp;
+ break;
+ case OPT_SCRYPT_R:
+ if (!opt_ulong(opt_arg(), &scrypt_r))
+ goto opthelp;
+ break;
+ case OPT_SCRYPT_P:
+ if (!opt_ulong(opt_arg(), &scrypt_p))
+ goto opthelp;
+ break;
}
}
argc = opt_num_rest();
}
} else {
X509_ALGOR *pbe;
- if (cipher)
- pbe = PKCS5_pbe2_set_iv(cipher, iter, NULL, 0, NULL, pbe_nid);
- else
+ if (cipher) {
+ if (scrypt_N && scrypt_r && scrypt_p)
+ pbe = PKCS5_pbe2_set_scrypt(cipher, NULL, 0, NULL,
+ scrypt_N, scrypt_r, scrypt_p);
+ else
+ pbe = PKCS5_pbe2_set_iv(cipher, iter, NULL, 0, NULL,
+ pbe_nid);
+ } else {
pbe = PKCS5_pbe_set(pbe_nid, iter, NULL, 0);
+ }
if (pbe == NULL) {
BIO_printf(bio_err, "Error setting PBE algorithm\n");
ERR_print_errors(bio_err);