|
||||
File indexing completed on 2025-01-17 09:55:13
0001 /* High-level libcrypt interfaces. 0002 0003 Copyright (C) 1991-2017 Free Software Foundation, Inc. 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Lesser General Public License 0007 as published by the Free Software Foundation; either version 2.1 of 0008 the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public 0016 License along with this library; if not, see 0017 <https://www.gnu.org/licenses/>. */ 0018 0019 #ifndef _CRYPT_H 0020 #define _CRYPT_H 1 0021 0022 #include <sys/cdefs.h> 0023 0024 __BEGIN_DECLS 0025 0026 /* The strings returned by crypt, crypt_r, crypt_rn, and crypt_ra will 0027 be no longer than this, counting the terminating NUL. (Existing 0028 algorithms all produce much shorter strings, but we have reserved 0029 generous space for future expansion.) This is NOT the appropriate 0030 size to use in allocating the buffer supplied to crypt_rn; use 0031 sizeof (struct crypt_data) instead. */ 0032 #define CRYPT_OUTPUT_SIZE 384 0033 0034 /* Passphrases longer than this (counting the terminating NUL) are not 0035 supported. Note that some hash algorithms have lower limits. */ 0036 #define CRYPT_MAX_PASSPHRASE_SIZE 512 0037 0038 /* The strings returned by crypt_gensalt, crypt_gensalt_rn, and 0039 crypt_gensalt_ra will be no longer than this. This IS the 0040 appropriate size to use when allocating the buffer supplied to 0041 crypt_gensalt_rn. (Again, existing algorithms all produce 0042 much shorter strings, but we have reserved generous space for 0043 future expansion.) */ 0044 #define CRYPT_GENSALT_OUTPUT_SIZE 192 0045 0046 /* One-way hash the passphrase PHRASE as specified by SETTING, and 0047 return a string suitable for storage in a Unix-style "passwd" file. 0048 0049 If SETTING is a previously hashed passphrase, the string returned 0050 will be equal to SETTING if and only if PHRASE is the same as the 0051 passphrase that was previously hashed. See the documentation for 0052 other ways to use this function. 0053 0054 The string returned by this function is stored in a statically- 0055 allocated buffer, and will be overwritten if the function is called 0056 again. It is not safe to call this function from multiple threads 0057 concurrently. 0058 0059 If an error occurs (such as SETTING being nonsense or unsupported) 0060 the string returned will begin with '*', and will not be equal to 0061 SETTING nor to any valid hashed passphrase. Otherwise, the string 0062 will not begin with '*'. */ 0063 extern char *crypt (const char *__phrase, const char *__setting) 0064 __THROW; 0065 0066 /* These sizes are chosen to make sizeof (struct crypt_data) add up to 0067 exactly 32768 bytes. */ 0068 #define CRYPT_DATA_RESERVED_SIZE 767 0069 #define CRYPT_DATA_INTERNAL_SIZE 30720 0070 0071 /* Memory area used by crypt_r. */ 0072 struct crypt_data 0073 { 0074 /* crypt_r writes the hashed password to this field of its 'data' 0075 argument. crypt_rn and crypt_ra do the same, treating the 0076 untyped data area they are supplied with as this struct. */ 0077 char output[CRYPT_OUTPUT_SIZE]; 0078 0079 /* Applications are encouraged, but not required, to use this field 0080 to store the "setting" string that must be passed to crypt_*. 0081 Future extensions to the API may make this more ergonomic. 0082 0083 A valid "setting" is either previously hashed password or the 0084 string produced by one of the crypt_gensalt functions; see the 0085 crypt_gensalt documentation for further details. */ 0086 char setting[CRYPT_OUTPUT_SIZE]; 0087 0088 /* Applications are encouraged, but not required, to use this field 0089 to store the unhashed passphrase they will pass to crypt_*. 0090 Future extensions to the API may make this more ergonomic. */ 0091 char input[CRYPT_MAX_PASSPHRASE_SIZE]; 0092 0093 /* Reserved for future application-visible fields. For maximum 0094 forward compatibility, applications should set this field to all 0095 bytes zero before calling crypt_r, crypt_rn, or crypt_ra for the 0096 first time with a just-allocated 'struct crypt_data'. Future 0097 extensions to the API may make this more ergonomic. */ 0098 char reserved[CRYPT_DATA_RESERVED_SIZE]; 0099 0100 /* This field should be set to 0 before calling crypt_r, crypt_rn, 0101 or crypt_ra for the first time with a just-allocated 0102 'struct crypt_data'. This is not required if crypt_ra is allowed 0103 to do the allocation itself (i.e. if the *DATA argument is a null 0104 pointer). Future extensions to the API may make this more ergonomic. */ 0105 char initialized; 0106 0107 /* Scratch space used internally. Applications should not read or 0108 write this field. All data written to this area is erased before 0109 returning from the library. */ 0110 char internal[CRYPT_DATA_INTERNAL_SIZE]; 0111 }; 0112 0113 /* Thread-safe version of crypt. Instead of writing to a static 0114 storage area, the string returned by this function will be within 0115 DATA->output. Otherwise, behaves exactly the same as crypt. */ 0116 extern char *crypt_r (const char *__phrase, const char *__setting, 0117 struct crypt_data *__restrict __data) 0118 __THROW; 0119 0120 /* Another thread-safe version of crypt. Instead of writing to a 0121 static storage area, the string returned by this function will be 0122 somewhere within the space provided at DATA, which is of length SIZE 0123 bytes. SIZE must be at least sizeof (struct crypt_data). 0124 0125 Also, if an error occurs, this function returns a null pointer, 0126 not a special string. (However, the string returned on success 0127 still will never begin with '*'.) */ 0128 extern char *crypt_rn (const char *__phrase, const char *__setting, 0129 void *__data, int __size) 0130 __THROW; 0131 0132 /* Yet a third thread-safe version of crypt; this one works like 0133 getline(3). *DATA must be either 0 or a pointer to memory 0134 allocated by malloc, and *SIZE must be the size of the allocation. 0135 This space will be allocated or reallocated as necessary and the 0136 values updated. The string returned by this function will be 0137 somewhere within the space at *DATA. It is safe to deallocate 0138 this space with free when it is no longer needed. 0139 0140 Like crypt_rn, this function returns a null pointer on failure, not 0141 a special string. */ 0142 extern char *crypt_ra (const char *__phrase, const char *__setting, 0143 void **__data, int *__size) 0144 __THROW; 0145 0146 0147 /* Generate a string suitable for use as the setting when hashing a 0148 new passphrase. PREFIX controls which hash function will be used, 0149 COUNT controls the computational cost of the hash (for functions 0150 where this is tunable), and RBYTES should point to NRBYTES bytes of 0151 random data. If PREFIX is a null pointer, the current best default 0152 is used; if RBYTES is a null pointer, random data will be retrieved 0153 from the operating system if possible. (Caution: setting PREFIX to 0154 an *empty string* selects the use of the oldest and least secure 0155 hash in the library. Don't do that.) 0156 0157 The string returned is stored in a statically-allocated buffer, and 0158 will be overwritten if the function is called again. It is not 0159 safe to call this function from multiple threads concurrently. 0160 However, within a single thread, it is safe to pass the string as 0161 the SETTING argument to crypt without copying it first; the two 0162 functions use separate buffers. 0163 0164 If an error occurs (e.g. a prefix that does not correspond to a 0165 supported hash function, or an inadequate amount of random data), 0166 this function returns a null pointer. */ 0167 extern char *crypt_gensalt (const char *__prefix, unsigned long __count, 0168 const char *__rbytes, int __nrbytes) 0169 __THROW; 0170 0171 /* Thread-safe version of crypt_gensalt; instead of a 0172 statically-allocated buffer, the generated setting string is 0173 written to OUTPUT, which is OUTPUT_SIZE bytes long. OUTPUT_SIZE 0174 must be at least CRYPT_GENSALT_OUTPUT_SIZE (see above). 0175 0176 If an error occurs, this function returns a null pointer and writes 0177 a string that does not correspond to any valid setting into OUTPUT. */ 0178 extern char *crypt_gensalt_rn (const char *__prefix, unsigned long __count, 0179 const char *__rbytes, int __nrbytes, 0180 char *__output, int __output_size) 0181 __THROW; 0182 0183 /* Kept for code compatibility with libxcrypt (v3.1.1 and earlier). 0184 We intentionally declare the function using a macro here, since 0185 we actually want to link compiled applications against the 0186 identical crypt_gensalt_rn function. */ 0187 #ifndef IN_LIBCRYPT /* Defined when building libxcrypt. */ 0188 # ifdef __REDIRECT_NTH 0189 extern char * __REDIRECT_NTH (crypt_gensalt_r, (const char *__prefix, 0190 unsigned long __count, const char *__rbytes, 0191 int __nrbytes, char *__output, 0192 int __output_size), crypt_gensalt_rn); 0193 # else 0194 # define crypt_gensalt_r crypt_gensalt_rn 0195 # endif 0196 #endif 0197 0198 /* Another thread-safe version of crypt_gensalt; the generated setting 0199 string is in storage allocated by malloc, and should be deallocated 0200 with free when it is no longer needed. */ 0201 extern char *crypt_gensalt_ra (const char *__prefix, unsigned long __count, 0202 const char *__rbytes, int __nrbytes) 0203 __THROW; 0204 0205 /* Checks whether the given setting is a supported method. 0206 0207 The return value is 0 if there is nothing wrong with this setting. 0208 Otherwise, it is one of the following constants. */ 0209 extern int crypt_checksalt (const char *__setting); 0210 0211 /* Constants for checking the return value of the 0212 crypt_checksalt function. */ 0213 #define CRYPT_SALT_OK 0 0214 #define CRYPT_SALT_INVALID 1 0215 #define CRYPT_SALT_METHOD_DISABLED 2 /* NOT implemented, yet. */ 0216 #define CRYPT_SALT_METHOD_LEGACY 3 0217 #define CRYPT_SALT_TOO_CHEAP 4 /* NOT implemented, yet. */ 0218 0219 /* Convenience function to get the prefix of the preferred hash method, 0220 which is also used by the crypt_gensalt functions, if their given 0221 prefix parameter is NULL. 0222 0223 The return value is string that equals the prefix of the preferred 0224 hash method. Otherwise, it is NULL. */ 0225 extern const char *crypt_preferred_method (void); 0226 0227 /* These macros could be checked by portable users of crypt_gensalt* 0228 functions to find out whether null pointers could be specified 0229 as PREFIX and RBYTES arguments. */ 0230 #define CRYPT_GENSALT_IMPLEMENTS_DEFAULT_PREFIX 1 0231 #define CRYPT_GENSALT_IMPLEMENTS_AUTO_ENTROPY 1 0232 0233 /* These macros can be checked by portable users of libxcrypt 0234 to find out whether the function is implemented. */ 0235 #define CRYPT_CHECKSALT_AVAILABLE 1 0236 #define CRYPT_PREFERRED_METHOD_AVAILABLE 1 0237 0238 /* Version number split in single integers. */ 0239 #define XCRYPT_VERSION_MAJOR 4 0240 #define XCRYPT_VERSION_MINOR 4 0241 0242 /* Version number coded into an integer. */ 0243 #define XCRYPT_VERSION_NUM ((XCRYPT_VERSION_MAJOR << 16) | \ 0244 XCRYPT_VERSION_MINOR) 0245 0246 /* Version number as a string constant. */ 0247 #define XCRYPT_VERSION_STR "4.4.35" 0248 0249 __END_DECLS 0250 0251 #endif /* crypt.h */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |