diff options
author | mrezai <mhd.rezai@gmail.com> | 2016-04-10 17:48:59 +0430 |
---|---|---|
committer | mrezai <mhd.rezai@gmail.com> | 2016-04-10 17:48:59 +0430 |
commit | c860574d8ba246b5e2c59578f24accd2ace5e9bc (patch) | |
tree | 5c8f90fc94bc49da9b35c2f532f186aa0817e6bc /drivers/builtin_openssl2/crypto/engine/eng_rdrand.c | |
parent | d454e64f429affb89de036eed6daa5c6e5278492 (diff) |
Update OpenSSL to version 1.0.1s
Diffstat (limited to 'drivers/builtin_openssl2/crypto/engine/eng_rdrand.c')
-rw-r--r-- | drivers/builtin_openssl2/crypto/engine/eng_rdrand.c | 142 |
1 files changed, 74 insertions, 68 deletions
diff --git a/drivers/builtin_openssl2/crypto/engine/eng_rdrand.c b/drivers/builtin_openssl2/crypto/engine/eng_rdrand.c index 4e9e91d54b..9316d6fe21 100644 --- a/drivers/builtin_openssl2/crypto/engine/eng_rdrand.c +++ b/drivers/builtin_openssl2/crypto/engine/eng_rdrand.c @@ -61,83 +61,89 @@ size_t OPENSSL_ia32_rdrand(void); -static int get_random_bytes (unsigned char *buf, int num) - { - size_t rnd; - - while (num>=(int)sizeof(size_t)) { - if ((rnd = OPENSSL_ia32_rdrand()) == 0) return 0; - - *((size_t *)buf) = rnd; - buf += sizeof(size_t); - num -= sizeof(size_t); - } - if (num) { - if ((rnd = OPENSSL_ia32_rdrand()) == 0) return 0; - - memcpy (buf,&rnd,num); - } - - return 1; - } - -static int random_status (void) -{ return 1; } - -static RAND_METHOD rdrand_meth = - { - NULL, /* seed */ - get_random_bytes, - NULL, /* cleanup */ - NULL, /* add */ - get_random_bytes, - random_status, - }; +static int get_random_bytes(unsigned char *buf, int num) +{ + size_t rnd; + + while (num >= (int)sizeof(size_t)) { + if ((rnd = OPENSSL_ia32_rdrand()) == 0) + return 0; + + *((size_t *)buf) = rnd; + buf += sizeof(size_t); + num -= sizeof(size_t); + } + if (num) { + if ((rnd = OPENSSL_ia32_rdrand()) == 0) + return 0; + + memcpy(buf, &rnd, num); + } + + return 1; +} + +static int random_status(void) +{ + return 1; +} + +static RAND_METHOD rdrand_meth = { + NULL, /* seed */ + get_random_bytes, + NULL, /* cleanup */ + NULL, /* add */ + get_random_bytes, + random_status, +}; static int rdrand_init(ENGINE *e) -{ return 1; } +{ + return 1; +} static const char *engine_e_rdrand_id = "rdrand"; static const char *engine_e_rdrand_name = "Intel RDRAND engine"; static int bind_helper(ENGINE *e) - { - if (!ENGINE_set_id(e, engine_e_rdrand_id) || - !ENGINE_set_name(e, engine_e_rdrand_name) || - !ENGINE_set_flags(e, ENGINE_FLAGS_NO_REGISTER_ALL) || - !ENGINE_set_init_function(e, rdrand_init) || - !ENGINE_set_RAND(e, &rdrand_meth) ) - return 0; +{ + if (!ENGINE_set_id(e, engine_e_rdrand_id) || + !ENGINE_set_name(e, engine_e_rdrand_name) || + !ENGINE_set_flags(e, ENGINE_FLAGS_NO_REGISTER_ALL) || + !ENGINE_set_init_function(e, rdrand_init) || + !ENGINE_set_RAND(e, &rdrand_meth)) + return 0; - return 1; - } + return 1; +} static ENGINE *ENGINE_rdrand(void) - { - ENGINE *ret = ENGINE_new(); - if(!ret) - return NULL; - if(!bind_helper(ret)) - { - ENGINE_free(ret); - return NULL; - } - return ret; - } - -void ENGINE_load_rdrand (void) - { - extern unsigned int OPENSSL_ia32cap_P[]; - - if (OPENSSL_ia32cap_P[1] & (1<<(62-32))) - { - ENGINE *toadd = ENGINE_rdrand(); - if(!toadd) return; - ENGINE_add(toadd); - ENGINE_free(toadd); - ERR_clear_error(); - } - } +{ + ENGINE *ret = ENGINE_new(); + if (!ret) + return NULL; + if (!bind_helper(ret)) { + ENGINE_free(ret); + return NULL; + } + return ret; +} + +void ENGINE_load_rdrand(void) +{ + extern unsigned int OPENSSL_ia32cap_P[]; + + if (OPENSSL_ia32cap_P[1] & (1 << (62 - 32))) { + ENGINE *toadd = ENGINE_rdrand(); + if (!toadd) + return; + ENGINE_add(toadd); + ENGINE_free(toadd); + ERR_clear_error(); + } +} #else -void ENGINE_load_rdrand (void) {} +void ENGINE_load_rdrand(void) +{ +} #endif |