logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

crypt.3p (4555B)


  1. '\" et
  2. .TH CRYPT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. crypt
  12. \(em string encoding function
  13. (\fBCRYPT\fP)
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. #include <unistd.h>
  18. .P
  19. char *crypt(const char *\fIkey\fP, const char *\fIsalt\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fIcrypt\fR()
  24. function is a string encoding function. The algorithm is
  25. implementation-defined.
  26. .P
  27. The
  28. .IR key
  29. argument points to a string to be encoded. The
  30. .IR salt
  31. argument shall be a string of at least two bytes in length not
  32. including the null character chosen from the set:
  33. .sp
  34. .RS 4
  35. .nf
  36. a b c d e f g h i j k l m n o p q r s t u v w x y z
  37. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  38. 0 1 2 3 4 5 6 7 8 9 . /
  39. .fi
  40. .P
  41. .RE
  42. .P
  43. The first two bytes of this string may be used to perturb the
  44. encoding algorithm.
  45. .P
  46. The return value of
  47. \fIcrypt\fR()
  48. points to static data that is overwritten by each call.
  49. .P
  50. The
  51. \fIcrypt\fR()
  52. function need not be thread-safe.
  53. .SH "RETURN VALUE"
  54. Upon successful completion,
  55. \fIcrypt\fR()
  56. shall return a pointer to the encoded string. The first two bytes
  57. of the returned value shall be those of the
  58. .IR salt
  59. argument. Otherwise, it shall return a null pointer and set
  60. .IR errno
  61. to indicate the error.
  62. .SH ERRORS
  63. The
  64. \fIcrypt\fR()
  65. function shall fail if:
  66. .TP
  67. .BR ENOSYS
  68. The functionality is not supported on this implementation.
  69. .LP
  70. .IR "The following sections are informative."
  71. .SH EXAMPLES
  72. .SS "Encoding Passwords"
  73. .P
  74. The following example finds a user database entry matching a particular
  75. user name and changes the current password to a new password. The
  76. \fIcrypt\fR()
  77. function generates an encoded version of each password. The
  78. first call to
  79. \fIcrypt\fR()
  80. produces an encoded version of the old password; that encoded password
  81. is then compared to the password stored in the user database. The
  82. second call to
  83. \fIcrypt\fR()
  84. encodes the new password before it is stored.
  85. .P
  86. The
  87. \fIputpwent\fR()
  88. function, used in the following example, is not part of POSIX.1\(hy2008.
  89. .sp
  90. .RS 4
  91. .nf
  92. #include <unistd.h>
  93. #include <pwd.h>
  94. #include <string.h>
  95. #include <stdio.h>
  96. \&...
  97. int valid_change;
  98. int pfd; /* Integer for file descriptor returned by open(). */
  99. FILE *fpfd; /* File pointer for use in putpwent(). */
  100. struct passwd *p;
  101. char user[100];
  102. char oldpasswd[100];
  103. char newpasswd[100];
  104. char savepasswd[100];
  105. \&...
  106. valid_change = 0;
  107. while ((p = getpwent()) != NULL) {
  108. /* Change entry if found. */
  109. if (strcmp(p->pw_name, user) == 0) {
  110. if (strcmp(p->pw_passwd, crypt(oldpasswd, p->pw_passwd)) == 0) {
  111. strcpy(savepasswd, crypt(newpasswd, user));
  112. p->pw_passwd = savepasswd;
  113. valid_change = 1;
  114. }
  115. else {
  116. fprintf(stderr, "Old password is not valid\en");
  117. }
  118. }
  119. /* Put passwd entry into ptmp. */
  120. putpwent(p, fpfd);
  121. }
  122. .fi
  123. .P
  124. .RE
  125. .SH "APPLICATION USAGE"
  126. The values returned by this function need not be portable among
  127. XSI-conformant systems.
  128. .P
  129. Several implementations offer extensions via characters outside
  130. of the set specified for the
  131. .IR salt
  132. argument for specifying alternative algorithms; while not portable, these
  133. extensions may offer better security. The use of
  134. \fIcrypt\fR()
  135. for anything other than password hashing is not recommended.
  136. .SH RATIONALE
  137. None.
  138. .SH "FUTURE DIRECTIONS"
  139. None.
  140. .SH "SEE ALSO"
  141. .IR "\fIencrypt\fR\^(\|)",
  142. .IR "\fIsetkey\fR\^(\|)"
  143. .P
  144. The Base Definitions volume of POSIX.1\(hy2017,
  145. .IR "\fB<unistd.h>\fP"
  146. .\"
  147. .SH COPYRIGHT
  148. Portions of this text are reprinted and reproduced in electronic form
  149. from IEEE Std 1003.1-2017, Standard for Information Technology
  150. -- Portable Operating System Interface (POSIX), The Open Group Base
  151. Specifications Issue 7, 2018 Edition,
  152. Copyright (C) 2018 by the Institute of
  153. Electrical and Electronics Engineers, Inc and The Open Group.
  154. In the event of any discrepancy between this version and the original IEEE and
  155. The Open Group Standard, the original IEEE and The Open Group Standard
  156. is the referee document. The original Standard can be obtained online at
  157. http://www.opengroup.org/unix/online.html .
  158. .PP
  159. Any typographical or formatting errors that appear
  160. in this page are most likely
  161. to have been introduced during the conversion of the source files to
  162. man page format. To report such errors, see
  163. https://www.kernel.org/doc/man-pages/reporting_bugs.html .