source: EcnlProtoTool/trunk/openssl-1.1.0e/crypto/engine/eng_rdrand.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.5 KB
Line 
1/*
2 * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include <openssl/opensslconf.h>
11
12#include <stdio.h>
13#include <string.h>
14#include <internal/engine.h>
15#include <openssl/rand.h>
16#include <openssl/err.h>
17#include <openssl/crypto.h>
18
19#if (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
20 defined(__x86_64) || defined(__x86_64__) || \
21 defined(_M_AMD64) || defined (_M_X64)) && defined(OPENSSL_CPUID_OBJ)
22
23size_t OPENSSL_ia32_rdrand(void);
24
25static int get_random_bytes(unsigned char *buf, int num)
26{
27 size_t rnd;
28
29 while (num >= (int)sizeof(size_t)) {
30 if ((rnd = OPENSSL_ia32_rdrand()) == 0)
31 return 0;
32
33 *((size_t *)buf) = rnd;
34 buf += sizeof(size_t);
35 num -= sizeof(size_t);
36 }
37 if (num) {
38 if ((rnd = OPENSSL_ia32_rdrand()) == 0)
39 return 0;
40
41 memcpy(buf, &rnd, num);
42 }
43
44 return 1;
45}
46
47static int random_status(void)
48{
49 return 1;
50}
51
52static RAND_METHOD rdrand_meth = {
53 NULL, /* seed */
54 get_random_bytes,
55 NULL, /* cleanup */
56 NULL, /* add */
57 get_random_bytes,
58 random_status,
59};
60
61static int rdrand_init(ENGINE *e)
62{
63 return 1;
64}
65
66static const char *engine_e_rdrand_id = "rdrand";
67static const char *engine_e_rdrand_name = "Intel RDRAND engine";
68
69static int bind_helper(ENGINE *e)
70{
71 if (!ENGINE_set_id(e, engine_e_rdrand_id) ||
72 !ENGINE_set_name(e, engine_e_rdrand_name) ||
73 !ENGINE_set_flags(e, ENGINE_FLAGS_NO_REGISTER_ALL) ||
74 !ENGINE_set_init_function(e, rdrand_init) ||
75 !ENGINE_set_RAND(e, &rdrand_meth))
76 return 0;
77
78 return 1;
79}
80
81static ENGINE *ENGINE_rdrand(void)
82{
83 ENGINE *ret = ENGINE_new();
84 if (ret == NULL)
85 return NULL;
86 if (!bind_helper(ret)) {
87 ENGINE_free(ret);
88 return NULL;
89 }
90 return ret;
91}
92
93void engine_load_rdrand_int(void)
94{
95 extern unsigned int OPENSSL_ia32cap_P[];
96
97 if (OPENSSL_ia32cap_P[1] & (1 << (62 - 32))) {
98 ENGINE *toadd = ENGINE_rdrand();
99 if (!toadd)
100 return;
101 ENGINE_add(toadd);
102 ENGINE_free(toadd);
103 ERR_clear_error();
104 }
105}
106#else
107void engine_load_rdrand_int(void)
108{
109}
110#endif
Note: See TracBrowser for help on using the repository browser.