{
    "content": [
        {
            "type": "text",
            "text": "# crypt (man)\n\n## NAME\n\ncrypt, cryptr, cryptrn, cryptra — passphrase hashing\n\n## DESCRIPTION\n\nThe  crypt,  cryptr, cryptrn, and cryptra functions irreversibly “hash” phrase for storage\nin the system password database (shadow(5)) using a cryptographic “hashing method.”  The  re‐\nsult  of this operation is called a “hashed passphrase” or just a “hash.” Hashing methods are\ndescribed in crypt(5).\n\n## Sections\n\n- **NAME**\n- **LIBRARY**\n- **SYNOPSIS** (1 subsections)\n- **DESCRIPTION**\n- **RETURN VALUES**\n- **ERRORS**\n- **PORTABILITY NOTES**\n- **BUGS**\n- **ATTRIBUTES**\n- **HISTORY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "crypt",
        "section": "",
        "mode": "man",
        "summary": "crypt, cryptr, cryptrn, cryptra — passphrase hashing",
        "synopsis": "",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "cryptgensalt",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/cryptgensalt/3/json"
            },
            {
                "name": "getpass",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/getpass/3/json"
            },
            {
                "name": "getpwent",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/getpwent/3/json"
            },
            {
                "name": "shadow",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/shadow/3/json"
            },
            {
                "name": "login",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/login/1/json"
            },
            {
                "name": "passwd",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/passwd/1/json"
            },
            {
                "name": "passwd",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/passwd/5/json"
            },
            {
                "name": "shadow",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/shadow/5/json"
            },
            {
                "name": "pam",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/pam/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "LIBRARY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "#include <crypt.h>",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "DESCRIPTION",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "RETURN VALUES",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "ERRORS",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "PORTABILITY NOTES",
                "lines": 28,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "ATTRIBUTES",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "HISTORY",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "crypt, cryptr, cryptrn, cryptra — passphrase hashing\n",
                "subsections": []
            },
            "LIBRARY": {
                "content": "Crypt Library (libcrypt, -lcrypt)\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "",
                "subsections": [
                    {
                        "name": "#include <crypt.h>",
                        "content": "char *\ncrypt(const char *phrase, const char *setting);\n\nchar *\ncryptr(const char *phrase, const char *setting, struct cryptdata *data);\n\nchar *\ncryptrn(const char *phrase, const char *setting, struct cryptdata *data, int size);\n\nchar *\ncryptra(const char *phrase, const char *setting, void data, int *size);\n"
                    }
                ]
            },
            "DESCRIPTION": {
                "content": "The  crypt,  cryptr, cryptrn, and cryptra functions irreversibly “hash” phrase for storage\nin the system password database (shadow(5)) using a cryptographic “hashing method.”  The  re‐\nsult  of this operation is called a “hashed passphrase” or just a “hash.” Hashing methods are\ndescribed in crypt(5).\n\nsetting controls which hashing method to use, and also supplies  various  parameters  to  the\nchosen  method,  most importantly a random “salt” which ensures that no two stored hashes are\nthe same, even if the phrase strings are the same.\n\nThe data argument to cryptr is a structure of type struct cryptdata.  It has at least these\nfields:\n\nstruct cryptdata {\nchar output[CRYPTOUTPUTSIZE];\nchar setting[CRYPTOUTPUTSIZE];\nchar input[CRYPTMAXPASSPHRASESIZE];\nchar initialized;\n};\n\nUpon a successful return from cryptr, the hashed passphrase will be stored in  output.   Ap‐\nplications are encouraged, but not required, to use the input and setting fields to store the\nstrings that they will pass as input phrase and setting to cryptr.  This will make it easier\nto erase all sensitive data after it is no longer needed.\n\nThe initialized field must be set to zero before the first time a struct cryptdata object is\nfirst  used  in  a  call  to  cryptr().   We  recommend  zeroing the entire object, not just\ninitialized and not just the documented fields, before the first use.  (Of  course,  do  this\nbefore storing anything in setting and input.)\n\nThe  data  argument  to  cryptrn  should  also point to a struct cryptdata object, and size\nshould be the size of that object, cast to int.  When used with cryptrn, the entire data ob‐\nject (except for the input and setting fields) must be zeroed before its first use;  this  is\nnot  just  a  recommendation, as it is for cryptr.  Otherwise, the fields of the object have\nthe same uses that they do for cryptr.\n\nOn the first call to cryptra, data should be the address of a void * variable set  to  NULL,\nand  size  should  be the address of an int variable set to zero.  cryptra will allocate and\ninitialize a struct cryptdata object, using malloc(3), and write its address and  size  into\nthe  variables  pointed to by data and size.  These can be reused in subsequent calls.  After\nthe application is done hashing passphrases, it should deallocate the struct  cryptdata  ob‐\nject using free(3).\n",
                "subsections": []
            },
            "RETURN VALUES": {
                "content": "Upon  successful  completion,  crypt,  cryptr,  cryptrn, and cryptra return a pointer to a\nstring which encodes both the hashed passphrase, and the settings that were  used  to  encode\nit.   This  string  is directly usable as setting in other calls to crypt, cryptr, cryptrn,\nand  cryptra,  and  as   prefix   in   calls   to   cryptgensalt,   cryptgensaltrn,   and\ncryptgensaltra.   It  will  be entirely printable ASCII, and will not contain whitespace or\nthe characters ‘:’, ‘;’, ‘*’, ‘!’, or ‘\\’.  See crypt(5) for more detail  on  the  format  of\nhashed passphrases.\n\ncrypt  places  its  result  in a static storage area, which will be overwritten by subsequent\ncalls to crypt.  It is not safe to call crypt from multiple threads simultaneously.\n\ncryptr, cryptrn, and cryptra place their result in the output field of  their  data  argu‐\nment.   It  is  safe to call them from multiple threads simultaneously, as long as a separate\ndata object is used for each thread.\n\nUpon error, cryptr, cryptrn, and cryptra write an invalid hashed passphrase to the  output\nfield  of  their  data argument, and crypt writes an invalid hash to its static storage area.\nThis string will be shorter than 13 characters, will begin with a ‘*’, and will  not  compare\nequal to setting.\n\nUpon error, cryptrn and cryptra return a null pointer.  cryptr and crypt may also return a\nnull pointer, or they may return a pointer to the invalid hash, depending on how libcrypt was\nconfigured.   (The  option  to return the invalid hash is for compatibility with old applica‐\ntions that assume that crypt cannot return a null pointer.  See “PORTABILITY NOTES” below.)\n\nAll four functions set errno when they fail.\n",
                "subsections": []
            },
            "ERRORS": {
                "content": "EINVAL             setting is invalid, or requests a hashing method that is not supported.\n\nERANGE             phrase is too long (more than CRYPTMAXPASSPHRASESIZE  characters;  some\nhashing methods may have lower limits).\ncryptrn  only:  size  is  too  small  for the hashing method requested by\nsetting.\n\nENOMEM             Failed to allocate internal scratch memory.\ncryptra only: failed to allocate memory for data.\n\nENOSYS or EOPNOTSUPP\nHashing passphrases is not supported at all on this installation,  or  the\nhashing  method  requested by setting is not supported.  These error codes\nare not used by this version of libcrypt, but may be encountered on  other\nsystems.\n",
                "subsections": []
            },
            "PORTABILITY NOTES": {
                "content": "crypt is included in POSIX, but cryptr, cryptrn, and cryptra are not part of any standard.\n\nPOSIX  does  not  specify  any hashing methods, and does not require hashed passphrases to be\nportable between systems.  In practice, hashed passphrases are portable as long as both  sys‐\ntems support the hashing method that was used.  However, the set of supported hashing methods\nvaries considerably from system to system.\n\nThe  behavior  of crypt on errors isn't well standardized.  Some implementations simply can't\nfail (except by crashing the program), others return a null pointer or a fixed string.   Most\nimplementations  don't  set errno, but some do.  POSIX specifies returning a null pointer and\nsetting errno, but it defines only one possible error, ENOSYS, in the case where crypt is not\nsupported at all.  Some older applications are not prepared to handle null pointers  returned\nby  crypt.  The behavior described above for this implementation, setting errno and returning\nan invalid hashed passphrase different from setting, is chosen  to  make  these  applications\nfail closed when an error occurs.\n\nDue to historical restrictions on the export of cryptographic software from the USA, crypt is\nan  optional  POSIX component.  Applications should therefore be prepared for crypt not to be\navailable, or to always fail (setting errno to ENOSYS) at runtime.\n\nPOSIX specifies that crypt is declared in <unistd.h>, but only if the macro  XOPENCRYPT  is\ndefined  and  has  a  value  greater  than or equal to zero.  Since libcrypt does not provide\n<unistd.h>, it declares crypt, cryptr, cryptrn, and cryptra in <crypt.h> instead.\n\nOn a minority of systems (notably recent versions of Solaris), crypt uses  a  thread-specific\nstatic  storage buffer, which makes it safe to call from multiple threads simultaneously, but\ndoes not prevent each call within a thread from overwriting the results of the previous one.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Some implementations of crypt, upon error, return an invalid hash that is stored in  a  read-\nonly  location or only initialized once, which means that it is only safe to erase the buffer\npointed to by the crypt return value if an error did not occur.\n\nstruct cryptdata may be quite large (32kB in this implementation of libcrypt; over 128kB  in\nsome  other  implementations).   This is large enough that it may be unwise to allocate it on\nthe stack.\n\nSome recently designed hashing methods need even more scratch memory, but the cryptr  inter‐\nface makes it impossible to change the size of struct cryptdata without breaking binary com‐\npatibility.  The cryptrn interface could accommodate larger allocations for specific hashing\nmethods,  but  the  caller  of  cryptrn  has  no way of knowing how much memory to allocate.\ncryptra does the allocation itself, but can only make a single call to malloc(3).\n",
                "subsections": []
            },
            "ATTRIBUTES": {
                "content": "For an explanation of the terms used in this section, see attributes(7).\n┌───────────────────────────┬───────────────┬──────────────────────┐\n│ Interface                 │ Attribute     │ Value                │\n├───────────────────────────┼───────────────┼──────────────────────┤\n│ crypt                     │ Thread safety │ MT-Unsafe race:crypt │\n├───────────────────────────┼───────────────┼──────────────────────┤\n│ cryptr,        cryptrn, │ Thread safety │ MT-Safe              │\n│ cryptra                  │               │                      │\n└───────────────────────────┴───────────────┴──────────────────────┘\n\n",
                "subsections": []
            },
            "HISTORY": {
                "content": "A  rotor-based  crypt  function appeared in Version 6 AT&T UNIX.  The “traditional” DES-based\ncrypt first appeared in Version 7 AT&T UNIX.\n\ncryptr originates with the GNU C Library.  There's also a cryptr function on HP-UX and  MKS\nToolkit, but the prototypes and semantics differ.\n\ncryptrn and cryptra originate with the Openwall project.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "cryptgensalt(3),   getpass(3),   getpwent(3),   shadow(3),  login(1),  passwd(1),  crypt(5),\npasswd(5), shadow(5), pam(8)\n\nOpenwall Project                          October 11, 2017                                  CRYPT(3)",
                "subsections": []
            }
        }
    }
}