static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
                     char *passwd, BIO *out, int quiet, int table,
                     int reverse, size_t pw_maxlen, passwd_modes mode)
{
    char *hash = NULL;
    assert(salt_p != NULL);
    assert(salt_malloc_p != NULL);
    if (!passed_salt) {
# ifndef OPENSSL_NO_DES
        if (mode == passwd_crypt) {
            if (*salt_malloc_p == NULL)
                *salt_p = *salt_malloc_p = app_malloc(3, "salt buffer");
            if (RAND_bytes((unsigned char *)*salt_p, 2) <= 0)
                goto end;
            (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f];
            (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f];
            (*salt_p)[2] = 0;
#  ifdef CHARSET_EBCDIC
            ascii2ebcdic(*salt_p, *salt_p, 2);
#  endif
        }
# endif
# ifndef NO_MD5CRYPT_1
        if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5) {
            int i;
            if (*salt_malloc_p == NULL)
                *salt_p = *salt_malloc_p = app_malloc(9, "salt buffer");
            if (RAND_bytes((unsigned char *)*salt_p, 8) <= 0)
                goto end;
            for (i = 0; i < 8; i++)
                (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f];
            (*salt_p)[8] = 0;
        }
# endif
# ifndef NO_SHACRYPT
        if (mode == passwd_sha256 || mode == passwd_sha512) {
            int i;
            if (*salt_malloc_p == NULL)
                *salt_p = *salt_malloc_p = app_malloc(17, "salt buffer");
            if (RAND_bytes((unsigned char *)*salt_p, 16) <= 0)
                goto end;
            for (i = 0; i < 16; i++)
                (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f];
            (*salt_p)[16] = 0;
        }
# endif
    }
    assert(*salt_p != NULL);
    if ((strlen(passwd) > pw_maxlen)) {
        if (!quiet)
            BIO_printf(bio_err,
                       "Warning: truncating password to %u characters\n",
                       (unsigned)pw_maxlen);
        passwd[pw_maxlen] = 0;
    }
    assert(strlen(passwd) <= pw_maxlen);
# ifndef OPENSSL_NO_DES
    if (mode == passwd_crypt)
        hash = DES_crypt(passwd, *salt_p);
# endif
# ifndef NO_MD5CRYPT_1
    if (mode == passwd_md5 || mode == passwd_apr1)
        hash = md5crypt(passwd, (mode == passwd_md5 ? "1" : "apr1"), *salt_p);
    if (mode == passwd_aixmd5)
        hash = md5crypt(passwd, "", *salt_p);
# endif
# ifndef NO_SHACRYPT
    if (mode == passwd_sha256 || mode == passwd_sha512)
        hash = shacrypt(passwd, (mode == passwd_sha256 ? "5" : "6"), *salt_p);
# endif
    assert(hash != NULL);
    if (table && !reverse)
        BIO_printf(out, "%s\t%s\n", passwd, hash);
    else if (table && reverse)
        BIO_printf(out, "%s\t%s\n", hash, passwd);
    else
        BIO_printf(out, "%s\n", hash);
    return 1;
 end:
    return 0;
}
['int passwd_main(int argc, char **argv)\n{\n    BIO *in = NULL;\n    char *infile = NULL, *salt = NULL, *passwd = NULL, **passwds = NULL;\n    char *salt_malloc = NULL, *passwd_malloc = NULL, *prog;\n    OPTION_CHOICE o;\n    int in_stdin = 0, pw_source_defined = 0;\n# ifndef OPENSSL_NO_UI_CONSOLE\n    int in_noverify = 0;\n# endif\n    int passed_salt = 0, quiet = 0, table = 0, reverse = 0;\n    int ret = 1;\n    passwd_modes mode = passwd_unset;\n    size_t passwd_malloc_size = 0;\n    size_t pw_maxlen = 256;\n    prog = opt_init(argc, argv, passwd_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(passwd_options);\n            ret = 0;\n            goto end;\n        case OPT_IN:\n            if (pw_source_defined)\n                goto opthelp;\n            infile = opt_arg();\n            pw_source_defined = 1;\n            break;\n        case OPT_NOVERIFY:\n# ifndef OPENSSL_NO_UI_CONSOLE\n            in_noverify = 1;\n# endif\n            break;\n        case OPT_QUIET:\n            quiet = 1;\n            break;\n        case OPT_TABLE:\n            table = 1;\n            break;\n        case OPT_REVERSE:\n            reverse = 1;\n            break;\n        case OPT_1:\n            if (mode != passwd_unset)\n                goto opthelp;\n            mode = passwd_md5;\n            break;\n        case OPT_5:\n            if (mode != passwd_unset)\n                goto opthelp;\n            mode = passwd_sha256;\n            break;\n        case OPT_6:\n            if (mode != passwd_unset)\n                goto opthelp;\n            mode = passwd_sha512;\n            break;\n        case OPT_APR1:\n            if (mode != passwd_unset)\n                goto opthelp;\n            mode = passwd_apr1;\n            break;\n        case OPT_AIXMD5:\n            if (mode != passwd_unset)\n                goto opthelp;\n            mode = passwd_aixmd5;\n            break;\n        case OPT_CRYPT:\n            if (mode != passwd_unset)\n                goto opthelp;\n            mode = passwd_crypt;\n            break;\n        case OPT_SALT:\n            passed_salt = 1;\n            salt = opt_arg();\n            break;\n        case OPT_STDIN:\n            if (pw_source_defined)\n                goto opthelp;\n            in_stdin = 1;\n            pw_source_defined = 1;\n            break;\n        case OPT_R_CASES:\n            if (!opt_rand(o))\n                goto end;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (*argv != NULL) {\n        if (pw_source_defined)\n            goto opthelp;\n        pw_source_defined = 1;\n        passwds = argv;\n    }\n    if (mode == passwd_unset) {\n        mode = passwd_crypt;\n    }\n# ifdef OPENSSL_NO_DES\n    if (mode == passwd_crypt)\n        goto opthelp;\n# endif\n# ifdef NO_MD5CRYPT_1\n    if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5)\n        goto opthelp;\n# endif\n# ifdef NO_SHACRYPT\n    if (mode == passwd_sha256 || mode == passwd_sha512)\n        goto opthelp;\n# endif\n    if (infile != NULL && in_stdin) {\n        BIO_printf(bio_err, "%s: Can\'t combine -in and -stdin\\n", prog);\n        goto end;\n    }\n    if (infile != NULL || in_stdin) {\n        in = bio_open_default(infile, \'r\', FORMAT_TEXT);\n        if (in == NULL)\n            goto end;\n    }\n    if (mode == passwd_crypt)\n        pw_maxlen = 8;\n    if (passwds == NULL) {\n        passwd_malloc_size = pw_maxlen + 2;\n        passwd = passwd_malloc =\n            app_malloc(passwd_malloc_size, "password buffer");\n    }\n    if ((in == NULL) && (passwds == NULL)) {\n        if (1) {\n# ifndef OPENSSL_NO_UI_CONSOLE\n            static char *passwds_static[2] = { NULL, NULL };\n            passwds = passwds_static;\n            if (in == NULL) {\n                if (EVP_read_pw_string\n                    (passwd_malloc, passwd_malloc_size, "Password: ",\n                     !(passed_salt || in_noverify)) != 0)\n                    goto end;\n            }\n            passwds[0] = passwd_malloc;\n        } else {\n# endif\n            BIO_printf(bio_err, "password required\\n");\n            goto end;\n        }\n    }\n    if (in == NULL) {\n        assert(passwds != NULL);\n        assert(*passwds != NULL);\n        do {\n            passwd = *passwds++;\n            if (!do_passwd(passed_salt, &salt, &salt_malloc, passwd, bio_out,\n                           quiet, table, reverse, pw_maxlen, mode))\n                goto end;\n        } while (*passwds != NULL);\n    } else {\n        int done;\n        assert(passwd != NULL);\n        do {\n            int r = BIO_gets(in, passwd, pw_maxlen + 1);\n            if (r > 0) {\n                char *c = (strchr(passwd, \'\\n\'));\n                if (c != NULL) {\n                    *c = 0;\n                } else {\n                    char trash[BUFSIZ];\n                    do\n                        r = BIO_gets(in, trash, sizeof trash);\n                    while ((r > 0) && (!strchr(trash, \'\\n\')));\n                }\n                if (!do_passwd\n                    (passed_salt, &salt, &salt_malloc, passwd, bio_out, quiet,\n                     table, reverse, pw_maxlen, mode))\n                    goto end;\n            }\n            done = (r <= 0);\n        } while (!done);\n    }\n    ret = 0;\n end:\n    ERR_print_errors(bio_err);\n    OPENSSL_free(salt_malloc);\n    OPENSSL_free(passwd_malloc);\n    BIO_free(in);\n    return (ret);\n}', 'static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,\n                     char *passwd, BIO *out, int quiet, int table,\n                     int reverse, size_t pw_maxlen, passwd_modes mode)\n{\n    char *hash = NULL;\n    assert(salt_p != NULL);\n    assert(salt_malloc_p != NULL);\n    if (!passed_salt) {\n# ifndef OPENSSL_NO_DES\n        if (mode == passwd_crypt) {\n            if (*salt_malloc_p == NULL)\n                *salt_p = *salt_malloc_p = app_malloc(3, "salt buffer");\n            if (RAND_bytes((unsigned char *)*salt_p, 2) <= 0)\n                goto end;\n            (*salt_p)[0] = cov_2char[(*salt_p)[0] & 0x3f];\n            (*salt_p)[1] = cov_2char[(*salt_p)[1] & 0x3f];\n            (*salt_p)[2] = 0;\n#  ifdef CHARSET_EBCDIC\n            ascii2ebcdic(*salt_p, *salt_p, 2);\n#  endif\n        }\n# endif\n# ifndef NO_MD5CRYPT_1\n        if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5) {\n            int i;\n            if (*salt_malloc_p == NULL)\n                *salt_p = *salt_malloc_p = app_malloc(9, "salt buffer");\n            if (RAND_bytes((unsigned char *)*salt_p, 8) <= 0)\n                goto end;\n            for (i = 0; i < 8; i++)\n                (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f];\n            (*salt_p)[8] = 0;\n        }\n# endif\n# ifndef NO_SHACRYPT\n        if (mode == passwd_sha256 || mode == passwd_sha512) {\n            int i;\n            if (*salt_malloc_p == NULL)\n                *salt_p = *salt_malloc_p = app_malloc(17, "salt buffer");\n            if (RAND_bytes((unsigned char *)*salt_p, 16) <= 0)\n                goto end;\n            for (i = 0; i < 16; i++)\n                (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f];\n            (*salt_p)[16] = 0;\n        }\n# endif\n    }\n    assert(*salt_p != NULL);\n    if ((strlen(passwd) > pw_maxlen)) {\n        if (!quiet)\n            BIO_printf(bio_err,\n                       "Warning: truncating password to %u characters\\n",\n                       (unsigned)pw_maxlen);\n        passwd[pw_maxlen] = 0;\n    }\n    assert(strlen(passwd) <= pw_maxlen);\n# ifndef OPENSSL_NO_DES\n    if (mode == passwd_crypt)\n        hash = DES_crypt(passwd, *salt_p);\n# endif\n# ifndef NO_MD5CRYPT_1\n    if (mode == passwd_md5 || mode == passwd_apr1)\n        hash = md5crypt(passwd, (mode == passwd_md5 ? "1" : "apr1"), *salt_p);\n    if (mode == passwd_aixmd5)\n        hash = md5crypt(passwd, "", *salt_p);\n# endif\n# ifndef NO_SHACRYPT\n    if (mode == passwd_sha256 || mode == passwd_sha512)\n        hash = shacrypt(passwd, (mode == passwd_sha256 ? "5" : "6"), *salt_p);\n# endif\n    assert(hash != NULL);\n    if (table && !reverse)\n        BIO_printf(out, "%s\\t%s\\n", passwd, hash);\n    else if (table && reverse)\n        BIO_printf(out, "%s\\t%s\\n", hash, passwd);\n    else\n        BIO_printf(out, "%s\\n", hash);\n    return 1;\n end:\n    return 0;\n}']