summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/bcrypt_pbkdf.c18
-rw-r--r--openbsd-compat/blowfish.c2
-rw-r--r--openbsd-compat/bsd-cygwin_util.c2
-rw-r--r--openbsd-compat/bsd-misc.h4
-rw-r--r--openbsd-compat/openbsd-compat.h2
-rw-r--r--openbsd-compat/rmd160.c2
6 files changed, 18 insertions, 12 deletions
diff --git a/openbsd-compat/bcrypt_pbkdf.c b/openbsd-compat/bcrypt_pbkdf.c
index 16912575a..0a07f9a0f 100644
--- a/openbsd-compat/bcrypt_pbkdf.c
+++ b/openbsd-compat/bcrypt_pbkdf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bcrypt_pbkdf.c,v 1.9 2014/07/13 21:21:25 tedu Exp $ */ 1/* $OpenBSD: bcrypt_pbkdf.c,v 1.13 2015/01/12 03:20:04 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org> 3 * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
4 * 4 *
@@ -37,6 +37,8 @@
37#endif 37#endif
38#define SHA512_DIGEST_LENGTH crypto_hash_sha512_BYTES 38#define SHA512_DIGEST_LENGTH crypto_hash_sha512_BYTES
39 39
40#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
41
40/* 42/*
41 * pkcs #5 pbkdf2 implementation using the "bcrypt" hash 43 * pkcs #5 pbkdf2 implementation using the "bcrypt" hash
42 * 44 *
@@ -61,8 +63,8 @@
61 * wise caller could do; we just do it for you. 63 * wise caller could do; we just do it for you.
62 */ 64 */
63 65
64#define BCRYPT_BLOCKS 8 66#define BCRYPT_WORDS 8
65#define BCRYPT_HASHSIZE (BCRYPT_BLOCKS * 4) 67#define BCRYPT_HASHSIZE (BCRYPT_WORDS * 4)
66 68
67static void 69static void
68bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out) 70bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out)
@@ -70,7 +72,7 @@ bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out)
70 blf_ctx state; 72 blf_ctx state;
71 u_int8_t ciphertext[BCRYPT_HASHSIZE] = 73 u_int8_t ciphertext[BCRYPT_HASHSIZE] =
72 "OxychromaticBlowfishSwatDynamite"; 74 "OxychromaticBlowfishSwatDynamite";
73 uint32_t cdata[BCRYPT_BLOCKS]; 75 uint32_t cdata[BCRYPT_WORDS];
74 int i; 76 int i;
75 uint16_t j; 77 uint16_t j;
76 size_t shalen = SHA512_DIGEST_LENGTH; 78 size_t shalen = SHA512_DIGEST_LENGTH;
@@ -85,14 +87,14 @@ bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out)
85 87
86 /* encryption */ 88 /* encryption */
87 j = 0; 89 j = 0;
88 for (i = 0; i < BCRYPT_BLOCKS; i++) 90 for (i = 0; i < BCRYPT_WORDS; i++)
89 cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext), 91 cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext),
90 &j); 92 &j);
91 for (i = 0; i < 64; i++) 93 for (i = 0; i < 64; i++)
92 blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t)); 94 blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
93 95
94 /* copy out */ 96 /* copy out */
95 for (i = 0; i < BCRYPT_BLOCKS; i++) { 97 for (i = 0; i < BCRYPT_WORDS; i++) {
96 out[4 * i + 3] = (cdata[i] >> 24) & 0xff; 98 out[4 * i + 3] = (cdata[i] >> 24) & 0xff;
97 out[4 * i + 2] = (cdata[i] >> 16) & 0xff; 99 out[4 * i + 2] = (cdata[i] >> 16) & 0xff;
98 out[4 * i + 1] = (cdata[i] >> 8) & 0xff; 100 out[4 * i + 1] = (cdata[i] >> 8) & 0xff;
@@ -156,9 +158,9 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t salt
156 } 158 }
157 159
158 /* 160 /*
159 * pbkdf2 deviation: ouput the key material non-linearly. 161 * pbkdf2 deviation: output the key material non-linearly.
160 */ 162 */
161 amt = MIN(amt, keylen); 163 amt = MINIMUM(amt, keylen);
162 for (i = 0; i < amt; i++) { 164 for (i = 0; i < amt; i++) {
163 size_t dest = i * stride + (count - 1); 165 size_t dest = i * stride + (count - 1);
164 if (dest >= origkeylen) 166 if (dest >= origkeylen)
diff --git a/openbsd-compat/blowfish.c b/openbsd-compat/blowfish.c
index 6c419549e..e10f7e7d9 100644
--- a/openbsd-compat/blowfish.c
+++ b/openbsd-compat/blowfish.c
@@ -50,7 +50,9 @@
50#endif 50#endif
51 51
52#include <sys/types.h> 52#include <sys/types.h>
53#ifdef HAVE_BLF_H
53#include <blf.h> 54#include <blf.h>
55#endif
54 56
55#undef inline 57#undef inline
56#ifdef __GNUC__ 58#ifdef __GNUC__
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index a2d82126d..8672ccf7f 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -68,7 +68,7 @@ cygwin_ssh_privsep_user()
68 if (cygwin_internal (CW_CYGNAME_FROM_WINNAME, "sshd", cyg_privsep_user, 68 if (cygwin_internal (CW_CYGNAME_FROM_WINNAME, "sshd", cyg_privsep_user,
69 sizeof cyg_privsep_user) != 0) 69 sizeof cyg_privsep_user) != 0)
70#endif 70#endif
71 strcpy (cyg_privsep_user, "sshd"); 71 strlcpy(cyg_privsep_user, "sshd", sizeof(cyg_privsep_user));
72 } 72 }
73 return cyg_privsep_user; 73 return cyg_privsep_user;
74} 74}
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 65c18ec2f..ff347a24b 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -111,7 +111,7 @@ pid_t getpgid(pid_t);
111#endif 111#endif
112 112
113#ifndef HAVE_ENDGRENT 113#ifndef HAVE_ENDGRENT
114# define endgrent() {} 114# define endgrent() do { } while(0)
115#endif 115#endif
116 116
117#ifndef HAVE_KRB5_GET_ERROR_MESSAGE 117#ifndef HAVE_KRB5_GET_ERROR_MESSAGE
@@ -119,7 +119,7 @@ pid_t getpgid(pid_t);
119#endif 119#endif
120 120
121#ifndef HAVE_KRB5_FREE_ERROR_MESSAGE 121#ifndef HAVE_KRB5_FREE_ERROR_MESSAGE
122# define krb5_free_error_message(a,b) while(0) 122# define krb5_free_error_message(a,b) do { } while(0)
123#endif 123#endif
124 124
125#endif /* _BSD_MISC_H */ 125#endif /* _BSD_MISC_H */
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 1cffefe06..cb59ccd57 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -221,7 +221,7 @@ long long strtonum(const char *, long long, long long, const char **);
221 221
222/* multibyte character support */ 222/* multibyte character support */
223#ifndef HAVE_MBLEN 223#ifndef HAVE_MBLEN
224# define mblen(x, y) 1 224# define mblen(x, y) (1)
225#endif 225#endif
226 226
227#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) 227#if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
diff --git a/openbsd-compat/rmd160.c b/openbsd-compat/rmd160.c
index 2a14dd7b0..e915141a5 100644
--- a/openbsd-compat/rmd160.c
+++ b/openbsd-compat/rmd160.c
@@ -32,7 +32,9 @@
32#ifndef WITH_OPENSSL 32#ifndef WITH_OPENSSL
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#ifdef HAVE_ENDIAN_H
35#include <endian.h> 36#include <endian.h>
37#endif
36#include <string.h> 38#include <string.h>
37#include <rmd160.h> 39#include <rmd160.h>
38 40