Wed Aug 28 17:47:08 2013 UTC ()
Publish explicit_memset and consttime_memequal in userland libc.

Remove the double-underscore from the userland versions, and do the
weak alias dance instead, now that these are public parts of libc.

As discussed on tech-userlevel:

https://mail-index.netbsd.org/tech-userlevel/2013/06/24/msg007843.html
(option 3)


(riastradh)
diff -r1.2 -r1.3 src/common/lib/libc/string/consttime_memequal.c
diff -r1.2 -r1.3 src/common/lib/libc/string/explicit_memset.c
diff -r1.8 -r1.9 src/crypto/external/bsd/libsaslc/dist/src/dict.c
diff -r1.7 -r1.8 src/crypto/external/bsd/openssh/dist/dns.c
diff -r1.47 -r1.48 src/include/string.h
diff -r1.168 -r1.169 src/lib/libc/include/namespace.h
diff -r1.18 -r1.19 src/lib/libcrypt/bcrypt.c
diff -r1.7 -r1.8 src/lib/libcrypt/crypt-sha1.c
diff -r1.13 -r1.14 src/lib/libcrypt/md5crypt.c

cvs diff -r1.2 -r1.3 src/common/lib/libc/string/consttime_memequal.c (expand / switch to unified diff)

--- src/common/lib/libc/string/consttime_memequal.c 2013/08/28 15:24:41 1.2
+++ src/common/lib/libc/string/consttime_memequal.c 2013/08/28 17:47:07 1.3
@@ -1,18 +1,21 @@ @@ -1,18 +1,21 @@
1/* $NetBSD: consttime_memequal.c,v 1.2 2013/08/28 15:24:41 riastradh Exp $ */ 1/* $NetBSD: consttime_memequal.c,v 1.3 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3#if !defined(_KERNEL) && !defined(_STANDALONE) 3#if !defined(_KERNEL) && !defined(_STANDALONE)
 4#include "namespace.h"
4#include <string.h> 5#include <string.h>
5#define consttime_memequal __consttime_memequal 6#ifdef __weak_alias
 7__weak_alias(consttime_memequal,_consttime_memequal)
 8#endif
6#else 9#else
7#include <lib/libkern/libkern.h> 10#include <lib/libkern/libkern.h>
8#endif 11#endif
9 12
10int 13int
11consttime_memequal(const void *b1, const void *b2, size_t len) 14consttime_memequal(const void *b1, const void *b2, size_t len)
12{ 15{
13 const char *c1 = b1, *c2 = b2; 16 const char *c1 = b1, *c2 = b2;
14 int res = 0; 17 int res = 0;
15 18
16 while (len --) 19 while (len --)
17 res |= *c1++ ^ *c2++; 20 res |= *c1++ ^ *c2++;
18 return !res; 21 return !res;

cvs diff -r1.2 -r1.3 src/common/lib/libc/string/explicit_memset.c (expand / switch to unified diff)

--- src/common/lib/libc/string/explicit_memset.c 2013/08/28 15:46:23 1.2
+++ src/common/lib/libc/string/explicit_memset.c 2013/08/28 17:47:07 1.3
@@ -1,18 +1,21 @@ @@ -1,18 +1,21 @@
1/* $NetBSD: explicit_memset.c,v 1.2 2013/08/28 15:46:23 riastradh Exp $ */ 1/* $NetBSD: explicit_memset.c,v 1.3 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3#if !defined(_KERNEL) && !defined(_STANDALONE) 3#if !defined(_KERNEL) && !defined(_STANDALONE)
 4#include "namespace.h"
4#include <string.h> 5#include <string.h>
5#define explicit_memset __explicit_memset 6#ifdef __weak_alias
 7__weak_alias(explicit_memset,_explicit_memset)
 8#endif
6#define explicit_memset_impl __explicit_memset_impl 9#define explicit_memset_impl __explicit_memset_impl
7#else 10#else
8#include <lib/libkern/libkern.h> 11#include <lib/libkern/libkern.h>
9#endif 12#endif
10 13
11/* 14/*
12 * The use of a volatile pointer guarantees that the compiler 15 * The use of a volatile pointer guarantees that the compiler
13 * will not optimise the call away. 16 * will not optimise the call away.
14 */ 17 */
15void *(* volatile explicit_memset_impl)(void *, int, size_t) = memset; 18void *(* volatile explicit_memset_impl)(void *, int, size_t) = memset;
16 19
17void * 20void *
18explicit_memset(void *b, int c, size_t len) 21explicit_memset(void *b, int c, size_t len)

cvs diff -r1.8 -r1.9 src/crypto/external/bsd/libsaslc/dist/src/dict.c (expand / switch to unified diff)

--- src/crypto/external/bsd/libsaslc/dist/src/dict.c 2013/06/24 04:21:19 1.8
+++ src/crypto/external/bsd/libsaslc/dist/src/dict.c 2013/08/28 17:47:07 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dict.c,v 1.8 2013/06/24 04:21:19 riastradh Exp $ */ 1/* $NetBSD: dict.c,v 1.9 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3/* Copyright (c) 2010 The NetBSD Foundation, Inc. 3/* Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Mateusz Kocielski. 7 * by Mateusz Kocielski.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__RCSID("$NetBSD: dict.c,v 1.8 2013/06/24 04:21:19 riastradh Exp $"); 38__RCSID("$NetBSD: dict.c,v 1.9 2013/08/28 17:47:07 riastradh Exp $");
39 39
40#include <sys/queue.h> 40#include <sys/queue.h>
41 41
42#include <ctype.h> 42#include <ctype.h>
43#include <errno.h> 43#include <errno.h>
44#include <stdbool.h> 44#include <stdbool.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#include <string.h> 46#include <string.h>
47 47
48#include "dict.h" 48#include "dict.h"
49#include "msg.h" 49#include "msg.h"
50 50
51/** dictionary */ 51/** dictionary */
@@ -126,27 +126,27 @@ saslc__dict_valid_key(const char *key) @@ -126,27 +126,27 @@ saslc__dict_valid_key(const char *key)
126 return *key == '\0'; 126 return *key == '\0';
127} 127}
128 128
129/** 129/**
130 * @brief destroys and deallocates list node 130 * @brief destroys and deallocates list node
131 * @param node list node 131 * @param node list node
132 */ 132 */
133static void 133static void
134saslc__dict_list_node_destroy(saslc__dict_node_t *node) 134saslc__dict_list_node_destroy(saslc__dict_node_t *node)
135{ 135{
136 136
137 free(node->key); 137 free(node->key);
138 /* zero value, it may contain sensitive data */ 138 /* zero value, it may contain sensitive data */
139 __explicit_memset(node->value, 0, node->value_len); 139 explicit_memset(node->value, 0, node->value_len);
140 free(node->value); 140 free(node->value);
141 LIST_REMOVE(node, nodes); 141 LIST_REMOVE(node, nodes);
142 free(node); 142 free(node);
143} 143}
144 144
145/** 145/**
146 * @brief gets node from the dictionary using key 146 * @brief gets node from the dictionary using key
147 * @param dict dictionary 147 * @param dict dictionary
148 * @param key node key 148 * @param key node key
149 * @return pointer to node if key is in the dictionary, NULL otherwise 149 * @return pointer to node if key is in the dictionary, NULL otherwise
150 */ 150 */
151static saslc__dict_node_t * 151static saslc__dict_node_t *
152saslc__dict_get_node_by_key(saslc__dict_t *dict, const char *key) 152saslc__dict_get_node_by_key(saslc__dict_t *dict, const char *key)

cvs diff -r1.7 -r1.8 src/crypto/external/bsd/openssh/dist/dns.c (expand / switch to unified diff)

--- src/crypto/external/bsd/openssh/dist/dns.c 2013/08/28 15:24:41 1.7
+++ src/crypto/external/bsd/openssh/dist/dns.c 2013/08/28 17:47:07 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dns.c,v 1.7 2013/08/28 15:24:41 riastradh Exp $ */ 1/* $NetBSD: dns.c,v 1.8 2013/08/28 17:47:07 riastradh Exp $ */
2/* $OpenBSD: dns.c,v 1.28 2012/05/23 03:28:28 djm Exp $ */ 2/* $OpenBSD: dns.c,v 1.28 2012/05/23 03:28:28 djm Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2003 Wesley Griffin. All rights reserved. 5 * Copyright (c) 2003 Wesley Griffin. All rights reserved.
6 * Copyright (c) 2003 Jakob Schlyter. All rights reserved. 6 * Copyright (c) 2003 Jakob Schlyter. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include "includes.h" 29#include "includes.h"
30__RCSID("$NetBSD: dns.c,v 1.7 2013/08/28 15:24:41 riastradh Exp $"); 30__RCSID("$NetBSD: dns.c,v 1.8 2013/08/28 17:47:07 riastradh Exp $");
31#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/socket.h> 32#include <sys/socket.h>
33 33
34#include <netdb.h> 34#include <netdb.h>
35#include <stdio.h> 35#include <stdio.h>
36#include <string.h> 36#include <string.h>
37 37
38#include "xmalloc.h" 38#include "xmalloc.h"
39#include "key.h" 39#include "key.h"
40#include "dns.h" 40#include "dns.h"
41#include "log.h" 41#include "log.h"
42#include "getrrsetbyname.h" 42#include "getrrsetbyname.h"
43 43
@@ -268,27 +268,27 @@ verify_host_key_dns(const char *hostname @@ -268,27 +268,27 @@ verify_host_key_dns(const char *hostname
268 if (!dns_read_key(&hostkey_algorithm, 268 if (!dns_read_key(&hostkey_algorithm,
269 &hostkey_digest_type, &hostkey_digest, 269 &hostkey_digest_type, &hostkey_digest,
270 &hostkey_digest_len, hostkey)) { 270 &hostkey_digest_len, hostkey)) {
271 error("Error calculating key fingerprint."); 271 error("Error calculating key fingerprint.");
272 freerrset(fingerprints); 272 freerrset(fingerprints);
273 return -1; 273 return -1;
274 } 274 }
275 } 275 }
276 276
277 /* Check if the current key is the same as the given key */ 277 /* Check if the current key is the same as the given key */
278 if (hostkey_algorithm == dnskey_algorithm && 278 if (hostkey_algorithm == dnskey_algorithm &&
279 hostkey_digest_type == dnskey_digest_type) { 279 hostkey_digest_type == dnskey_digest_type) {
280 if (hostkey_digest_len == dnskey_digest_len && 280 if (hostkey_digest_len == dnskey_digest_len &&
281 __consttime_memequal(hostkey_digest, dnskey_digest, 281 consttime_memequal(hostkey_digest, dnskey_digest,
282 hostkey_digest_len)) 282 hostkey_digest_len))
283 *flags |= DNS_VERIFY_MATCH; 283 *flags |= DNS_VERIFY_MATCH;
284 } 284 }
285 xfree(dnskey_digest); 285 xfree(dnskey_digest);
286 } 286 }
287 287
288 xfree(hostkey_digest); /* from key_fingerprint_raw() */ 288 xfree(hostkey_digest); /* from key_fingerprint_raw() */
289 freerrset(fingerprints); 289 freerrset(fingerprints);
290 290
291 if (*flags & DNS_VERIFY_FOUND) 291 if (*flags & DNS_VERIFY_FOUND)
292 if (*flags & DNS_VERIFY_MATCH) 292 if (*flags & DNS_VERIFY_MATCH)
293 debug("matching host key fingerprint found in DNS"); 293 debug("matching host key fingerprint found in DNS");
294 else 294 else

cvs diff -r1.47 -r1.48 src/include/string.h (expand / switch to unified diff)

--- src/include/string.h 2013/08/28 15:46:23 1.47
+++ src/include/string.h 2013/08/28 17:47:07 1.48
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: string.h,v 1.47 2013/08/28 15:46:23 riastradh Exp $ */ 1/* $NetBSD: string.h,v 1.48 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -93,28 +93,28 @@ __aconst char *strsignal(int); @@ -93,28 +93,28 @@ __aconst char *strsignal(int);
93__END_DECLS 93__END_DECLS
94 94
95#if defined(_NETBSD_SOURCE) 95#if defined(_NETBSD_SOURCE)
96#include <strings.h> /* for backwards-compatibilty */ 96#include <strings.h> /* for backwards-compatibilty */
97__BEGIN_DECLS 97__BEGIN_DECLS
98void *memmem(const void *, size_t, const void *, size_t); 98void *memmem(const void *, size_t, const void *, size_t);
99char *strcasestr(const char *, const char *); 99char *strcasestr(const char *, const char *);
100size_t strlcat(char *, const char *, size_t); 100size_t strlcat(char *, const char *, size_t);
101size_t strlcpy(char *, const char *, size_t); 101size_t strlcpy(char *, const char *, size_t);
102char *strsep(char **, const char *); 102char *strsep(char **, const char *);
103char *stresep(char **, const char *, int); 103char *stresep(char **, const char *, int);
104char *strndup(const char *, size_t); 104char *strndup(const char *, size_t);
105void *memrchr(const void *, int, size_t); 105void *memrchr(const void *, int, size_t);
106void *__explicit_memset(void *, int, size_t); 106void *explicit_memset(void *, int, size_t);
107int __consttime_memequal(const void *, const void *, size_t); 107int consttime_memequal(const void *, const void *, size_t);
108__END_DECLS 108__END_DECLS
109#endif 109#endif
110 110
111#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE) 111#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
112# ifndef __LOCALE_T_DECLARED 112# ifndef __LOCALE_T_DECLARED
113typedef struct _locale *locale_t; 113typedef struct _locale *locale_t;
114# define __LOCALE_T_DECLARED 114# define __LOCALE_T_DECLARED
115# endif 115# endif
116__BEGIN_DECLS 116__BEGIN_DECLS
117int strcoll_l(const char *, const char *, locale_t); 117int strcoll_l(const char *, const char *, locale_t);
118size_t strxfrm_l(char * __restrict, const char * __restrict, size_t, locale_t); 118size_t strxfrm_l(char * __restrict, const char * __restrict, size_t, locale_t);
119__aconst char *strerror_l(int, locale_t); 119__aconst char *strerror_l(int, locale_t);
120__END_DECLS 120__END_DECLS

cvs diff -r1.168 -r1.169 src/lib/libc/include/namespace.h (expand / switch to unified diff)

--- src/lib/libc/include/namespace.h 2013/08/19 13:03:12 1.168
+++ src/lib/libc/include/namespace.h 2013/08/28 17:47:07 1.169
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: namespace.h,v 1.168 2013/08/19 13:03:12 joerg Exp $ */ 1/* $NetBSD: namespace.h,v 1.169 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -223,26 +223,27 @@ @@ -223,26 +223,27 @@
223#define clnt_sperror _clnt_sperror 223#define clnt_sperror _clnt_sperror
224#define clnt_vc_create _clnt_vc_create 224#define clnt_vc_create _clnt_vc_create
225#define clntraw_create _clntraw_create 225#define clntraw_create _clntraw_create
226#define clnttcp_create _clnttcp_create 226#define clnttcp_create _clnttcp_create
227#define clntudp_bufcreate _clntudp_bufcreate 227#define clntudp_bufcreate _clntudp_bufcreate
228#define clntudp_create _clntudp_create 228#define clntudp_create _clntudp_create
229#define clock_gettime _clock_gettime 229#define clock_gettime _clock_gettime
230#define clock_getres _clock_getres 230#define clock_getres _clock_getres
231#define clock_settime _clock_settime 231#define clock_settime _clock_settime
232#define closedir _closedir 232#define closedir _closedir
233#define closelog _closelog 233#define closelog _closelog
234#define closelog_r _closelog_r 234#define closelog_r _closelog_r
235#define confstr _confstr 235#define confstr _confstr
 236#define consttime_memequal _consttime_memequal
236#define csetexpandtc _csetexpandtc 237#define csetexpandtc _csetexpandtc
237#define ctermid _ctermid 238#define ctermid _ctermid
238#define ctime_r _ctime_r 239#define ctime_r _ctime_r
239#define ctime_rz _ctime_rz 240#define ctime_rz _ctime_rz
240#define daemon _daemon 241#define daemon _daemon
241#define dbopen _dbopen 242#define dbopen _dbopen
242#define devname _devname 243#define devname _devname
243#define difftime _difftime 244#define difftime _difftime
244#define dirname _dirname 245#define dirname _dirname
245#define dn_expand _dn_expand 246#define dn_expand _dn_expand
246#define dprintf_l _dprintf_l 247#define dprintf_l _dprintf_l
247#define drand48 _drand48 248#define drand48 _drand48
248#define duplocale _duplocale 249#define duplocale _duplocale
@@ -262,26 +263,27 @@ @@ -262,26 +263,27 @@
262#define endttyent _endttyent 263#define endttyent _endttyent
263#define endusershell _endusershell 264#define endusershell _endusershell
264#define erand48 _erand48 265#define erand48 _erand48
265#define ether_aton _ether_aton 266#define ether_aton _ether_aton
266#define ether_hostton _ether_hostton 267#define ether_hostton _ether_hostton
267#define ether_line _ether_line 268#define ether_line _ether_line
268#define ether_ntoa _ether_ntoa 269#define ether_ntoa _ether_ntoa
269#define ether_ntohost _ether_ntohost 270#define ether_ntohost _ether_ntohost
270#define execl _execl 271#define execl _execl
271#define execle _execle 272#define execle _execle
272#define execlp _execlp 273#define execlp _execlp
273#define execv _execv 274#define execv _execv
274#define execvp _execvp 275#define execvp _execvp
 276#define explicit_memset _explicit_memset
275#define fdopen _fdopen 277#define fdopen _fdopen
276#define fgetln _fgetln 278#define fgetln _fgetln
277#define fgetwln _fgetwln 279#define fgetwln _fgetwln
278#define fhstatvfs _fhstatvfs 280#define fhstatvfs _fhstatvfs
279#define flockfile _flockfile 281#define flockfile _flockfile
280#define ftrylockfile _ftrylockfile 282#define ftrylockfile _ftrylockfile
281#define funlockfile _funlockfile 283#define funlockfile _funlockfile
282#define fnmatch _fnmatch 284#define fnmatch _fnmatch
283#define fparseln _fparseln 285#define fparseln _fparseln
284#define fprintf_l _fprintf_l 286#define fprintf_l _fprintf_l
285#define fpgetmask _fpgetmask 287#define fpgetmask _fpgetmask
286#define fpgetprec _fpgetprec 288#define fpgetprec _fpgetprec
287#define fpgetround _fpgetround 289#define fpgetround _fpgetround

cvs diff -r1.18 -r1.19 src/lib/libcrypt/bcrypt.c (expand / switch to unified diff)

--- src/lib/libcrypt/bcrypt.c 2013/06/24 04:21:20 1.18
+++ src/lib/libcrypt/bcrypt.c 2013/08/28 17:47:07 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bcrypt.c,v 1.18 2013/06/24 04:21:20 riastradh Exp $ */ 1/* $NetBSD: bcrypt.c,v 1.19 2013/08/28 17:47:07 riastradh Exp $ */
2/* $OpenBSD: bcrypt.c,v 1.16 2002/02/19 19:39:36 millert Exp $ */ 2/* $OpenBSD: bcrypt.c,v 1.16 2002/02/19 19:39:36 millert Exp $ */
3 3
4/* 4/*
5 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> 5 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -36,27 +36,27 @@ @@ -36,27 +36,27 @@
36 * 36 *
37 * 1. state := InitState () 37 * 1. state := InitState ()
38 * 2. state := ExpandKey (state, salt, password) 3. 38 * 2. state := ExpandKey (state, salt, password) 3.
39 * REPEAT rounds: 39 * REPEAT rounds:
40 * state := ExpandKey (state, 0, salt) 40 * state := ExpandKey (state, 0, salt)
41 * state := ExpandKey(state, 0, password) 41 * state := ExpandKey(state, 0, password)
42 * 4. ctext := "OrpheanBeholderScryDoubt" 42 * 4. ctext := "OrpheanBeholderScryDoubt"
43 * 5. REPEAT 64: 43 * 5. REPEAT 64:
44 * ctext := Encrypt_ECB (state, ctext); 44 * ctext := Encrypt_ECB (state, ctext);
45 * 6. RETURN Concatenate (salt, ctext); 45 * 6. RETURN Concatenate (salt, ctext);
46 * 46 *
47 */ 47 */
48#include <sys/cdefs.h> 48#include <sys/cdefs.h>
49__RCSID("$NetBSD: bcrypt.c,v 1.18 2013/06/24 04:21:20 riastradh Exp $"); 49__RCSID("$NetBSD: bcrypt.c,v 1.19 2013/08/28 17:47:07 riastradh Exp $");
50 50
51#include <stdio.h> 51#include <stdio.h>
52#include <stdlib.h> 52#include <stdlib.h>
53#include <sys/types.h> 53#include <sys/types.h>
54#include <string.h> 54#include <string.h>
55#include <pwd.h> 55#include <pwd.h>
56#include <errno.h> 56#include <errno.h>
57#include <limits.h> 57#include <limits.h>
58 58
59#include "crypt.h" 59#include "crypt.h"
60#include "blowfish.c" 60#include "blowfish.c"
61 61
62/* This implementation is adaptable to current computing power. 62/* This implementation is adaptable to current computing power.
@@ -304,27 +304,27 @@ __bcrypt(const char *key, const char *sa @@ -304,27 +304,27 @@ __bcrypt(const char *key, const char *sa
304 304
305 i = 0; 305 i = 0;
306 encrypted[i++] = '$'; 306 encrypted[i++] = '$';
307 encrypted[i++] = BCRYPT_VERSION; 307 encrypted[i++] = BCRYPT_VERSION;
308 if (minor) 308 if (minor)
309 encrypted[i++] = minor; 309 encrypted[i++] = minor;
310 encrypted[i++] = '$'; 310 encrypted[i++] = '$';
311 311
312 snprintf(encrypted + i, 4, "%2.2u$", logr); 312 snprintf(encrypted + i, 4, "%2.2u$", logr);
313 313
314 encode_base64((u_int8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); 314 encode_base64((u_int8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT);
315 encode_base64((u_int8_t *) encrypted + strlen(encrypted), ciphertext, 315 encode_base64((u_int8_t *) encrypted + strlen(encrypted), ciphertext,
316 4 * BCRYPT_BLOCKS - 1); 316 4 * BCRYPT_BLOCKS - 1);
317 __explicit_memset(&state, 0, sizeof(state)); 317 explicit_memset(&state, 0, sizeof(state));
318 return encrypted; 318 return encrypted;
319} 319}
320 320
321static void 321static void
322encode_base64(u_int8_t *buffer, u_int8_t *data, u_int16_t len) 322encode_base64(u_int8_t *buffer, u_int8_t *data, u_int16_t len)
323{ 323{
324 u_int8_t *bp = buffer; 324 u_int8_t *bp = buffer;
325 u_int8_t *p = data; 325 u_int8_t *p = data;
326 u_int8_t c1, c2; 326 u_int8_t c1, c2;
327 while (p < data + len) { 327 while (p < data + len) {
328 c1 = *p++; 328 c1 = *p++;
329 *bp++ = Base64Code[((u_int32_t)c1 >> 2)]; 329 *bp++ = Base64Code[((u_int32_t)c1 >> 2)];
330 c1 = (c1 & 0x03) << 4; 330 c1 = (c1 & 0x03) << 4;

cvs diff -r1.7 -r1.8 src/lib/libcrypt/crypt-sha1.c (expand / switch to unified diff)

--- src/lib/libcrypt/crypt-sha1.c 2013/08/10 18:42:29 1.7
+++ src/lib/libcrypt/crypt-sha1.c 2013/08/28 17:47:07 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: crypt-sha1.c,v 1.7 2013/08/10 18:42:29 dholland Exp $ */ 1/* $NetBSD: crypt-sha1.c,v 1.8 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004, Juniper Networks, Inc. 4 * Copyright (c) 2004, Juniper Networks, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 *  6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions  8 * modification, are permitted provided that the following conditions
9 * are met:  9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.  11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.  14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if !defined(lint) 33#if !defined(lint)
34__RCSID("$NetBSD: crypt-sha1.c,v 1.7 2013/08/10 18:42:29 dholland Exp $"); 34__RCSID("$NetBSD: crypt-sha1.c,v 1.8 2013/08/28 17:47:07 riastradh Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#include <stdlib.h> 37#include <stdlib.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <stdio.h> 39#include <stdio.h>
40#include <string.h> 40#include <string.h>
41#include <time.h> 41#include <time.h>
42 42
43#include <err.h> 43#include <err.h>
44#include "crypt.h" 44#include "crypt.h"
45 45
46/* 46/*
47 * The default iterations - should take >0s on a fast CPU 47 * The default iterations - should take >0s on a fast CPU
@@ -182,17 +182,17 @@ __crypt_sha1 (const char *pw, const char @@ -182,17 +182,17 @@ __crypt_sha1 (const char *pw, const char
182 ul = (hmac_buf[i+0] << 16) | 182 ul = (hmac_buf[i+0] << 16) |
183 (hmac_buf[i+1] << 8) | 183 (hmac_buf[i+1] << 8) |
184 hmac_buf[i+2]; 184 hmac_buf[i+2];
185 __crypt_to64(ep, ul, 4); ep += 4; 185 __crypt_to64(ep, ul, 4); ep += 4;
186 } 186 }
187 /* Only 2 bytes left, so we pad with byte0 */ 187 /* Only 2 bytes left, so we pad with byte0 */
188 ul = (hmac_buf[SHA1_SIZE - 2] << 16) | 188 ul = (hmac_buf[SHA1_SIZE - 2] << 16) |
189 (hmac_buf[SHA1_SIZE - 1] << 8) | 189 (hmac_buf[SHA1_SIZE - 1] << 8) |
190 hmac_buf[0]; 190 hmac_buf[0];
191 __crypt_to64(ep, ul, 4); ep += 4; 191 __crypt_to64(ep, ul, 4); ep += 4;
192 *ep = '\0'; 192 *ep = '\0';
193 193
194 /* Don't leave anything around in vm they could use. */ 194 /* Don't leave anything around in vm they could use. */
195 __explicit_memset(hmac_buf, 0, sizeof hmac_buf); 195 explicit_memset(hmac_buf, 0, sizeof hmac_buf);
196 196
197 return passwd; 197 return passwd;
198}  198}

cvs diff -r1.13 -r1.14 src/lib/libcrypt/md5crypt.c (expand / switch to unified diff)

--- src/lib/libcrypt/md5crypt.c 2013/06/24 04:21:20 1.13
+++ src/lib/libcrypt/md5crypt.c 2013/08/28 17:47:07 1.14
@@ -1,31 +1,31 @@ @@ -1,31 +1,31 @@
1/* $NetBSD: md5crypt.c,v 1.13 2013/06/24 04:21:20 riastradh Exp $ */ 1/* $NetBSD: md5crypt.c,v 1.14 2013/08/28 17:47:07 riastradh Exp $ */
2 2
3/* 3/*
4 * ---------------------------------------------------------------------------- 4 * ----------------------------------------------------------------------------
5 * "THE BEER-WARE LICENSE" (Revision 42): 5 * "THE BEER-WARE LICENSE" (Revision 42):
6 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you 6 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
7 * can do whatever you want with this stuff. If we meet some day, and you think 7 * can do whatever you want with this stuff. If we meet some day, and you think
8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp 8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
9 * ---------------------------------------------------------------------------- 9 * ----------------------------------------------------------------------------
10 * 10 *
11 * from FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp 11 * from FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp
12 * via OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp 12 * via OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp
13 * 13 *
14 */ 14 */
15 15
16#include <sys/cdefs.h> 16#include <sys/cdefs.h>
17#if !defined(lint) 17#if !defined(lint)
18__RCSID("$NetBSD: md5crypt.c,v 1.13 2013/06/24 04:21:20 riastradh Exp $"); 18__RCSID("$NetBSD: md5crypt.c,v 1.14 2013/08/28 17:47:07 riastradh Exp $");
19#endif /* not lint */ 19#endif /* not lint */
20 20
21#include <unistd.h> 21#include <unistd.h>
22#include <stdio.h> 22#include <stdio.h>
23#include <string.h> 23#include <string.h>
24#include <md5.h> 24#include <md5.h>
25 25
26#include "crypt.h" 26#include "crypt.h"
27 27
28#define MD5_MAGIC "$1$" 28#define MD5_MAGIC "$1$"
29#define MD5_MAGIC_LEN 3 29#define MD5_MAGIC_LEN 3
30 30
31#define INIT(x) MD5Init((x)) 31#define INIT(x) MD5Init((x))
@@ -133,16 +133,16 @@ __md5crypt(const char *pw, const char *s @@ -133,16 +133,16 @@ __md5crypt(const char *pw, const char *s
133 /* memset(&ctx1, 0, sizeof(ctx1)); done by MD5Final() */ 133 /* memset(&ctx1, 0, sizeof(ctx1)); done by MD5Final() */
134 134
135 p = passwd + sl + MD5_MAGIC_LEN + 1; 135 p = passwd + sl + MD5_MAGIC_LEN + 1;
136 136
137 l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; __crypt_to64(p,l,4); p += 4; 137 l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; __crypt_to64(p,l,4); p += 4;
138 l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; __crypt_to64(p,l,4); p += 4; 138 l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; __crypt_to64(p,l,4); p += 4;
139 l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; __crypt_to64(p,l,4); p += 4; 139 l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; __crypt_to64(p,l,4); p += 4;
140 l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; __crypt_to64(p,l,4); p += 4; 140 l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; __crypt_to64(p,l,4); p += 4;
141 l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; __crypt_to64(p,l,4); p += 4; 141 l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; __crypt_to64(p,l,4); p += 4;
142 l = final[11] ; __crypt_to64(p,l,2); p += 2; 142 l = final[11] ; __crypt_to64(p,l,2); p += 2;
143 *p = '\0'; 143 *p = '\0';
144 144
145 /* Don't leave anything around in vm they could use. */ 145 /* Don't leave anything around in vm they could use. */
146 __explicit_memset(final, 0, sizeof(final)); 146 explicit_memset(final, 0, sizeof(final));
147 return (passwd); 147 return (passwd);
148} 148}