summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguenther <>2015-09-13 15:33:48 +0000
committerguenther <>2015-09-13 15:33:48 +0000
commit529bd5d820f710a2d7db3cb00f91040cc7ace408 (patch)
treec414ecd25a90803da35ff2d69474317e840c62cd
parent5702f6374f537ac042891a95ce7bc5c3e24eb640 (diff)
downloadopenbsd-529bd5d820f710a2d7db3cb00f91040cc7ace408.tar.gz
openbsd-529bd5d820f710a2d7db3cb00f91040cc7ace408.tar.bz2
openbsd-529bd5d820f710a2d7db3cb00f91040cc7ace408.zip
Wrap <pwd.h> so that calls go direct and the symbols are all weak.
Hide bcrypt_autorounds(), prefixing with an underbar for static builds.
-rw-r--r--src/lib/libc/crypt/bcrypt.c7
-rw-r--r--src/lib/libc/crypt/cryptutil.c8
2 files changed, 8 insertions, 7 deletions
diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c
index 0e6b00f12d..a8c1b9e7c8 100644
--- a/src/lib/libc/crypt/bcrypt.c
+++ b/src/lib/libc/crypt/bcrypt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bcrypt.c,v 1.54 2015/09/13 12:42:39 millert Exp $ */ 1/* $OpenBSD: bcrypt.c,v 1.55 2015/09/13 15:33:48 guenther Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 4 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
@@ -215,6 +215,7 @@ bcrypt_newhash(const char *pass, int log_rounds, char *hash, size_t hashlen)
215 explicit_bzero(salt, sizeof(salt)); 215 explicit_bzero(salt, sizeof(salt));
216 return 0; 216 return 0;
217} 217}
218DEF_WEAK(bcrypt_newhash);
218 219
219int 220int
220bcrypt_checkpass(const char *pass, const char *goodhash) 221bcrypt_checkpass(const char *pass, const char *goodhash)
@@ -232,13 +233,14 @@ bcrypt_checkpass(const char *pass, const char *goodhash)
232 explicit_bzero(hash, sizeof(hash)); 233 explicit_bzero(hash, sizeof(hash));
233 return 0; 234 return 0;
234} 235}
236DEF_WEAK(bcrypt_checkpass);
235 237
236/* 238/*
237 * Measure this system's performance by measuring the time for 8 rounds. 239 * Measure this system's performance by measuring the time for 8 rounds.
238 * We are aiming for something that takes around 0.1s, but not too much over. 240 * We are aiming for something that takes around 0.1s, but not too much over.
239 */ 241 */
240int 242int
241bcrypt_autorounds(void) 243_bcrypt_autorounds(void)
242{ 244{
243 struct timespec before, after; 245 struct timespec before, after;
244 int r = 8; 246 int r = 8;
@@ -391,3 +393,4 @@ bcrypt(const char *pass, const char *salt)
391 393
392 return gencrypted; 394 return gencrypted;
393} 395}
396DEF_WEAK(bcrypt);
diff --git a/src/lib/libc/crypt/cryptutil.c b/src/lib/libc/crypt/cryptutil.c
index 20d68b3fd3..f48ba1af2c 100644
--- a/src/lib/libc/crypt/cryptutil.c
+++ b/src/lib/libc/crypt/cryptutil.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cryptutil.c,v 1.11 2015/09/12 14:56:50 guenther Exp $ */ 1/* $OpenBSD: cryptutil.c,v 1.12 2015/09/13 15:33:48 guenther Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4 * 4 *
@@ -21,8 +21,6 @@
21#include <login_cap.h> 21#include <login_cap.h>
22#include <errno.h> 22#include <errno.h>
23 23
24int bcrypt_autorounds(void);
25
26int 24int
27crypt_checkpass(const char *pass, const char *goodhash) 25crypt_checkpass(const char *pass, const char *goodhash)
28{ 26{
@@ -70,12 +68,12 @@ crypt_newhash(const char *pass, const char *pref, char *hash, size_t hashlen)
70 const char *choice = choices[i]; 68 const char *choice = choices[i];
71 size_t len = strlen(choice); 69 size_t len = strlen(choice);
72 if (strcmp(pref, choice) == 0) { 70 if (strcmp(pref, choice) == 0) {
73 rounds = bcrypt_autorounds(); 71 rounds = _bcrypt_autorounds();
74 break; 72 break;
75 } else if (strncmp(pref, choice, len) == 0 && 73 } else if (strncmp(pref, choice, len) == 0 &&
76 pref[len] == ',') { 74 pref[len] == ',') {
77 if (strcmp(pref + len + 1, "a") == 0) { 75 if (strcmp(pref + len + 1, "a") == 0) {
78 rounds = bcrypt_autorounds(); 76 rounds = _bcrypt_autorounds();
79 } else { 77 } else {
80 rounds = strtonum(pref + len + 1, 4, 31, &errstr); 78 rounds = strtonum(pref + len + 1, 4, 31, &errstr);
81 if (errstr) { 79 if (errstr) {