-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds two depending parts: _PASSWORD_LEN for Linux and timingsafe_bcmp for others. The compat embeds bcrypt() and the bcrypt_newhash() functions, but does not expose them. It also fixes the strndup regression not to raise a warning on Linux and an incorrect definition of _GNU_SOURCE instead of _XOPEN_SOURCE to expose crypt() from unistd instead of crypt.h on Linux.
- Loading branch information
1 parent
fb6ec89
commit be17364
Showing
16 changed files
with
296 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
/* $OpenBSD: timingsafe_bcmp.c,v 1.3 2015/08/31 02:53:57 guenther Exp $ */ | ||
/* | ||
* Copyright (c) 2010 Damien Miller. All rights reserved. | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
int | ||
timingsafe_bcmp(const void *b1, const void *b2, size_t n) | ||
{ | ||
const unsigned char *p1 = b1, *p2 = b2; | ||
int ret = 0; | ||
|
||
for (; n > 0; n--) | ||
ret |= *p1++ ^ *p2++; | ||
return (ret != 0); | ||
} | ||
|
||
/* $OpenBSD: timingsafe_memcmp.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */ | ||
/* | ||
* Copyright (c) 2014 Google Inc. | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
#include <limits.h> | ||
|
||
int | ||
timingsafe_memcmp(const void *b1, const void *b2, size_t len) | ||
{ | ||
const unsigned char *p1 = b1, *p2 = b2; | ||
size_t i; | ||
int res = 0, done = 0; | ||
|
||
for (i = 0; i < len; i++) { | ||
/* lt is -1 if p1[i] < p2[i]; else 0. */ | ||
int lt = (p1[i] - p2[i]) >> CHAR_BIT; | ||
|
||
/* gt is -1 if p1[i] > p2[i]; else 0. */ | ||
int gt = (p2[i] - p1[i]) >> CHAR_BIT; | ||
|
||
/* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */ | ||
int cmp = lt - gt; | ||
|
||
/* set res = cmp if !done. */ | ||
res |= cmp & ~done; | ||
|
||
/* set done if p1[i] != p2[i]. */ | ||
done |= lt | gt; | ||
} | ||
|
||
return (res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.