1*f0e1d484Sjsg.\" $OpenBSD: crypt.3,v 1.46 2025/01/09 23:18:08 jsg Exp $ 2ee815117Sniklas.\" 382cd5483Sderaadt.\" FreeSec: libcrypt 482cd5483Sderaadt.\" 582cd5483Sderaadt.\" Copyright (c) 1994 David Burren 682cd5483Sderaadt.\" All rights reserved. 782cd5483Sderaadt.\" 882cd5483Sderaadt.\" Redistribution and use in source and binary forms, with or without 982cd5483Sderaadt.\" modification, are permitted provided that the following conditions 1082cd5483Sderaadt.\" are met: 1182cd5483Sderaadt.\" 1. Redistributions of source code must retain the above copyright 1282cd5483Sderaadt.\" notice, this list of conditions and the following disclaimer. 1382cd5483Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright 1482cd5483Sderaadt.\" notice, this list of conditions and the following disclaimer in the 1582cd5483Sderaadt.\" documentation and/or other materials provided with the distribution. 1682cd5483Sderaadt.\" 4. Neither the name of the author nor the names of other contributors 1782cd5483Sderaadt.\" may be used to endorse or promote products derived from this software 1882cd5483Sderaadt.\" without specific prior written permission. 1982cd5483Sderaadt.\" 2082cd5483Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2182cd5483Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2282cd5483Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2382cd5483Sderaadt.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2482cd5483Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2582cd5483Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2682cd5483Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2782cd5483Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2882cd5483Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2982cd5483Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3082cd5483Sderaadt.\" SUCH DAMAGE. 3182cd5483Sderaadt.\" 3282cd5483Sderaadt.\" Manual page, using -mandoc macros 3382cd5483Sderaadt.\" 34*f0e1d484Sjsg.Dd $Mdocdate: January 9 2025 $ 3582cd5483Sderaadt.Dt CRYPT 3 36c294bf55Sderaadt.Os 3782cd5483Sderaadt.Sh NAME 3882cd5483Sderaadt.Nm crypt , 397dfe0c51Sjmc.Nm bcrypt_gensalt , 4005fedc11Stedu.Nm bcrypt 41f1c2634aStedu.Nd password hashing 4282cd5483Sderaadt.Sh SYNOPSIS 4364d4e987Stedu.In stdlib.h 44e17cce25Sguenther.Pp 4564d4e987Stedu.In unistd.h 460bf05fe6Sderaadt.Ft char * 470bf05fe6Sderaadt.Fn crypt "const char *key" "const char *setting" 48dccb3d59Stedu.In pwd.h 49fc5f064aSderaadt.Ft char * 50fc5f064aSderaadt.Fn bcrypt_gensalt "u_int8_t log_rounds" 51fc5f064aSderaadt.Ft char * 52fc5f064aSderaadt.Fn bcrypt "const char *key" "const char *salt" 5382cd5483Sderaadt.Sh DESCRIPTION 54608633c1SteduThese functions are deprecated in favor of 55608633c1Stedu.Xr crypt_checkpass 3 56608633c1Steduand 57608633c1Stedu.Xr crypt_newhash 3 . 58608633c1Stedu.Pp 5982cd5483SderaadtThe 6082cd5483Sderaadt.Fn crypt 614c974c3fStedufunction performs password hashing. 6200fa1d58SprovosAdditional code has been added to deter key search attempts and to use 6300fa1d58Sprovosstronger hashing algorithms. 6483332665Saaron.Pp 6582cd5483SderaadtThe first argument to 667ec1ed9eSderaadt.Fn crypt 67cdaa683cSschwarzeis a NUL-terminated 68cdaa683cSschwarzestring 69cdaa683cSschwarze.Fa key , 70cdaa683cSschwarzetypically a user's typed password. 71cdaa683cSschwarzeThe second, 72cdaa683cSschwarze.Fa setting , 734c974c3fSteducurrently supports a single form. 7483332665SaaronIf it begins 7583332665Saaronwith a string character 7683332665Saaron.Pq Ql $ 7783332665Saaronand a number then a different algorithm is used depending on the number. 7805fedc11SteduAt the moment 7983332665Saaron.Ql $2 8083332665Saaronchooses Blowfish hashing; see below for more information. 81cdaa683cSschwarze.Ss Blowfish crypt 82cdaa683cSschwarzeThe Blowfish version of crypt has 128 bits of 8300fa1d58Sprovos.Fa salt 8483332665Saaronin order to make building dictionaries of common passwords space consuming. 8583332665SaaronThe initial state of the 86cdaa683cSschwarzeBlowfish cipher is expanded using the 8700fa1d58Sprovos.Fa salt 8800fa1d58Sprovosand the 8900fa1d58Sprovos.Fa password 9000fa1d58Sprovosrepeating the process a variable number of rounds, which is encoded in 9183332665Saaronthe password string. 9283332665SaaronThe maximum password length is 72. 9383332665SaaronThe final Blowfish password entry is created by encrypting the string 9483332665Saaron.Pp 9583332665Saaron.Dq OrpheanBeholderScryDoubt 9683332665Saaron.Pp 97cdaa683cSschwarzewith the Blowfish state 64 times. 9800fa1d58Sprovos.Pp 9900fa1d58SprovosThe version number, the logarithm of the number of rounds and 10083332665Saaronthe concatenation of salt and hashed password are separated by the 10183332665Saaron.Ql $ 10283332665Saaroncharacter. 10383332665SaaronAn encoded 10483332665Saaron.Sq 8 105dc215dd9Sprovoswould specify 256 rounds. 106792152b0SprovosA valid Blowfish password looks like this: 10700fa1d58Sprovos.Pp 1081b320b9cSsthen.Dq $2b$12$FPWWO2RJ3CK4FINTw0Hi8OiPKJcX653gzSS.jqltHFMxyDmmQ0Hqq . 10900fa1d58Sprovos.Pp 110792152b0SprovosThe whole Blowfish password string is passed as 11100fa1d58Sprovos.Fa setting 11200fa1d58Sprovosfor interpretation. 1135b551360Spyr.Sh RETURN VALUES 11482cd5483SderaadtThe function 11582cd5483Sderaadt.Fn crypt 11683332665Saaronreturns a pointer to the encrypted value on success, and 11783332665Saaron.Dv NULL 11883332665Saaronon failure. 11982cd5483Sderaadt.Sh SEE ALSO 120adc9b693Stedu.Xr encrypt 1 , 12182cd5483Sderaadt.Xr login 1 , 12282cd5483Sderaadt.Xr passwd 1 , 12300fa1d58Sprovos.Xr blowfish 3 , 124608633c1Stedu.Xr crypt_checkpass 3 , 12582cd5483Sderaadt.Xr getpass 3 , 12682cd5483Sderaadt.Xr passwd 5 12782cd5483Sderaadt.Sh HISTORY 128*f0e1d484SjsgAn M-209 based 12982cd5483Sderaadt.Fn crypt 13082cd5483Sderaadtfunction appeared in 131bf0f8e2cSmickey.At v3 . 1324c974c3fSteduA DES-based 13382cd5483Sderaadt.Fn crypt 13482cd5483Sderaadtfirst appeared in 13582cd5483Sderaadt.At v7 . 1364c974c3fStedu.Fn bcrypt 1374c974c3fStedufirst appeared in 1384c974c3fStedu.Ox 2.1 . 13983332665Saaron.Sh BUGS 14083332665SaaronThe 14183332665Saaron.Fn crypt 14283332665Saaronfunction returns a pointer to static data, and subsequent calls to 14383332665Saaron.Fn crypt 14483332665Saaronwill modify the same object. 145