Skip to content

Commit

Permalink
Fixes related to Alex's recent review.
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran committed Dec 6, 2016
1 parent f6bc160 commit 8575fb2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ found in LICENSE.APACHE or LICENSE.BSD. Contributions to cryptography are made
under the terms of *both* these licenses.

The code used in the OpenSSL locking callback and OS random engine is derived
from the same in Python itself, and is licensed under the terms of the PSF
from the same in CPython itself, and is licensed under the terms of the PSF
License Agreement.
23 changes: 8 additions & 15 deletions src/_cffi_src/openssl/src/osrandom_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ static int osrandom_finish(ENGINE *e) {
}

static int osrandom_rand_status(void) {
if (hCryptProv == 0) {
return 0;
} else {
return 1;
}
return hCryptProv != 0;
}

static const char* osurandom_get_implementation(void) {
static const char *osurandom_get_implementation(void) {
return "CryptGenRandom";
}

Expand All @@ -84,7 +80,7 @@ static int osrandom_rand_bytes(unsigned char *buffer, int size) {
int len, res;
while (size > 0) {
/* OpenBSD and macOS restrict maximum buffer size to 256. */
len = size > 256 ? 256: size;
len = size > 256 ? 256 : size;
res = getentropy(buffer, len);
if (res < 0) {
CRYPTOGRAPHY_OSRANDOM_put_error(
Expand All @@ -105,7 +101,7 @@ static int osrandom_rand_status(void) {
return 1;
}

static const char* osurandom_get_implementation(void) {
static const char *osurandom_get_implementation(void) {
return "getentropy";
}
#endif /* CRYPTOGRAPHY_OSRANDOM_ENGINE_GETENTROPY */
Expand Down Expand Up @@ -289,7 +285,7 @@ static int osrandom_rand_status(void) {
return 1;
}

static const char* osurandom_get_implementation(void) {
static const char *osurandom_get_implementation(void) {
if (getrandom_works == 1) {
return "getrandom";
}
Expand Down Expand Up @@ -322,13 +318,10 @@ static int osrandom_finish(ENGINE *e) {
}

static int osrandom_rand_status(void) {
if (urandom_cache.fd < 0) {
return 0;
}
return 1;
return urandom_cache.fd >= 0;
}

static const char* osurandom_get_implementation(void) {
static const char *osurandom_get_implementation(void) {
return "/dev/urandom";
}
#endif /* CRYPTOGRAPHY_OSRANDOM_ENGINE_DEV_URANDOM */
Expand Down Expand Up @@ -366,7 +359,7 @@ static const ENGINE_CMD_DEFN osrandom_cmd_defns[] = {
};

static int osrandom_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) {
const char* name;
const char *name;
size_t len;

switch (cmd) {
Expand Down
2 changes: 1 addition & 1 deletion src/_cffi_src/openssl/src/osrandom_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef GRND_NONBLOCK
#define GRND_NONBLOCK 0x0001
#endif /* GRND_NONBLOCK */
#endif /* _linux__ */
#endif /* __linux__ */
#endif /* _WIN32 */

#define CRYPTOGRAPHY_OSRANDOM_ENGINE_CRYPTGENRANDOM 1
Expand Down
4 changes: 2 additions & 2 deletions tests/hazmat/backends/test_openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ def test_activate_builtin_random_already_active(self):

def test_osrandom_engine_implementation(self):
name = backend.osrandom_engine_implementation()
assert name in ['/dev/urandom', 'CCRandomGenerateBytes',
'CryptGenRandom', 'getentropy', 'getrandom']
assert name in ['/dev/urandom', 'CryptGenRandom', 'getentropy',
'getrandom']
if sys.platform.startswith('linux'):
assert name in ['getrandom', '/dev/urandom']
if sys.platform == 'darwin':
Expand Down

0 comments on commit 8575fb2

Please sign in to comment.