xref: /openbsd-src/lib/libc/crypt/crypt_checkpass.3 (revision 6fd1a043b0fc2ffda13c2dfad333c736260f60fe)
1*6fd1a043Sderaadt.\" $OpenBSD: crypt_checkpass.3,v 1.13 2021/10/29 10:54:33 deraadt Exp $
2608633c1Stedu.\"
36f0b0c90Sschwarze.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4608633c1Stedu.\"
5608633c1Stedu.\" Permission to use, copy, modify, and distribute this software for any
6608633c1Stedu.\" purpose with or without fee is hereby granted, provided that the above
7608633c1Stedu.\" copyright notice and this permission notice appear in all copies.
8608633c1Stedu.\"
9608633c1Stedu.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10608633c1Stedu.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11608633c1Stedu.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12608633c1Stedu.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13608633c1Stedu.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14608633c1Stedu.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15608633c1Stedu.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16608633c1Stedu.\"
17*6fd1a043Sderaadt.Dd $Mdocdate: October 29 2021 $
18608633c1Stedu.Dt CRYPT_CHECKPASS 3
19608633c1Stedu.Os
20608633c1Stedu.Sh NAME
21608633c1Stedu.Nm crypt_checkpass ,
22608633c1Stedu.Nm crypt_newhash
23608633c1Stedu.Nd password hashing
24608633c1Stedu.Sh SYNOPSIS
25*6fd1a043Sderaadt.In pwd.h
26608633c1Stedu.In unistd.h
27608633c1Stedu.Ft int
28608633c1Stedu.Fn crypt_checkpass "const char *password" "const char *hash"
29608633c1Stedu.Ft int
30817d1ee3Stedu.Fn crypt_newhash "const char *password" "const char *pref" "char *hash" "size_t hashsize"
31608633c1Stedu.Sh DESCRIPTION
32608633c1SteduThe
33608633c1Stedu.Fn crypt_checkpass
3453861158Stedufunction simplifies checking a user's password.
35cdaa683cSschwarzeIf both the
36cdaa683cSschwarze.Fa hash
37cdaa683cSschwarzeand the
38cdaa683cSschwarze.Fa password
39cdaa683cSschwarzeare the empty string, authentication
40608633c1Steduis a success.
41cdaa683cSschwarzeOtherwise, the
42cdaa683cSschwarze.Fa password
43cdaa683cSschwarzeis hashed and compared to the provided
44cdaa683cSschwarze.Fa hash .
45cdaa683cSschwarzeIf the
46cdaa683cSschwarze.Fa hash
47cdaa683cSschwarzeis
486f0b0c90Sschwarze.Dv NULL ,
496f0b0c90Sschwarzeauthentication will always fail, but a default
50608633c1Steduamount of work is performed to simulate the hashing operation.
51608633c1SteduA successful match will return 0.
526f0b0c90SschwarzeA failure will return \-1 and set
536f0b0c90Sschwarze.Xr errno 2 .
54608633c1Stedu.Pp
55608633c1SteduThe
56608633c1Stedu.Fn crypt_newhash
5753861158Stedufunction simplifies the creation of new password hashes.
58608633c1SteduThe provided
59608633c1Stedu.Fa password
60608633c1Steduis randomly salted and hashed and stored in
61608633c1Stedu.Fa hash .
6253861158SteduThe size of the available space is specified by
6353861158Stedu.Fa hashsize ,
6453861158Steduwhich should be
6553861158Stedu.Dv _PASSWORD_LEN .
66817d1ee3SteduThe
67817d1ee3Stedu.Fa pref
68817d1ee3Steduargument identifies the preferred hashing algorithm and parameters.
690ba5c1c8SteduPossible values are:
700fc8d908Sjmc.Bl -tag -width Ds
7113d08e56Stedu.It Dq bcrypt,<rounds>
720ba5c1c8SteduThe bcrypt algorithm, where the value of rounds can be between 4 and 31 and
730ba5c1c8Steduspecifies the base 2 logarithm of the number of rounds.
7453861158SteduIf rounds is omitted or the special value
7553861158Stedu.Sq a ,
7653861158Steduan appropriate number of rounds is automatically selected based on system
7753861158Steduperformance.
780ba5c1c8Stedu.El
79608633c1Stedu.Sh RETURN VALUES
806f0b0c90Sschwarze.Rv -std crypt_checkpass crypt_newhash
816f0b0c90Sschwarze.Sh ERRORS
826f0b0c90SschwarzeThe
836f0b0c90Sschwarze.Fn crypt_checkpass
846f0b0c90Sschwarzefunction sets
856f0b0c90Sschwarze.Va errno
866f0b0c90Sschwarzeto
87d704f08aSderaadt.Er EACCES
886f0b0c90Sschwarzewhen authentication fails.
896f0b0c90Sschwarze.Pp
906f0b0c90SschwarzeThe
916f0b0c90Sschwarze.Fn crypt_newhash
926f0b0c90Sschwarzefunction sets
936f0b0c90Sschwarze.Va errno
946f0b0c90Sschwarzeto
956f0b0c90Sschwarze.Er EINVAL
966f0b0c90Sschwarzeif
976f0b0c90Sschwarze.Fa pref
9853861158Steduis unsupported or insufficient space is provided.
99608633c1Stedu.Sh SEE ALSO
100608633c1Stedu.Xr crypt 3 ,
101608633c1Stedu.Xr login.conf 5 ,
102608633c1Stedu.Xr passwd 5
1036f0b0c90Sschwarze.Sh HISTORY
1046f0b0c90SschwarzeThe function
1056f0b0c90Sschwarze.Fn crypt_checkpass
1066f0b0c90Sschwarzefirst appeared in
1076f0b0c90Sschwarze.Ox 5.6 ,
1086f0b0c90Sschwarzeand
1096f0b0c90Sschwarze.Fn crypt_newhash
1106f0b0c90Sschwarzein
1116f0b0c90Sschwarze.Ox 5.7 .
1126f0b0c90Sschwarze.Sh AUTHORS
1136f0b0c90Sschwarze.An Ted Unangst Aq Mt tedu@openbsd.org
114