summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sparcv9cap.c
diff options
context:
space:
mode:
authormiod <>2014-04-17 18:49:35 +0000
committermiod <>2014-04-17 18:49:35 +0000
commit9f3c2d2afb228715c20193c6a3d1dcf4076161e2 (patch)
tree9b300ff5f2f5884420887d8f593434c1547a5934 /src/lib/libcrypto/sparcv9cap.c
parent87dc5ba7fdbe9aad46f68ad25457c433066ca01b (diff)
downloadopenbsd-9f3c2d2afb228715c20193c6a3d1dcf4076161e2.tar.gz
openbsd-9f3c2d2afb228715c20193c6a3d1dcf4076161e2.tar.bz2
openbsd-9f3c2d2afb228715c20193c6a3d1dcf4076161e2.zip
Remove oh-so-important-from-a-security-pov OpenSSL_rtdsc() function.
Diffstat (limited to 'src/lib/libcrypto/sparcv9cap.c')
-rw-r--r--src/lib/libcrypto/sparcv9cap.c147
1 files changed, 2 insertions, 145 deletions
diff --git a/src/lib/libcrypto/sparcv9cap.c b/src/lib/libcrypto/sparcv9cap.c
index 05c084807a..f49e71ec93 100644
--- a/src/lib/libcrypto/sparcv9cap.c
+++ b/src/lib/libcrypto/sparcv9cap.c
@@ -6,13 +6,12 @@
6#include <sys/time.h> 6#include <sys/time.h>
7#include <openssl/bn.h> 7#include <openssl/bn.h>
8 8
9#define SPARCV9_TICK_PRIVILEGED (1<<0)
10#define SPARCV9_PREFER_FPU (1<<1) 9#define SPARCV9_PREFER_FPU (1<<1)
11#define SPARCV9_VIS1 (1<<2) 10#define SPARCV9_VIS1 (1<<2)
12#define SPARCV9_VIS2 (1<<3) /* reserved */ 11#define SPARCV9_VIS2 (1<<3) /* reserved */
13#define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */ 12#define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */
14 13
15static int OPENSSL_sparcv9cap_P = SPARCV9_TICK_PRIVILEGED; 14static int OPENSSL_sparcv9cap_P = 0;
16 15
17int 16int
18bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, 17bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
@@ -29,146 +28,11 @@ bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
29 return bn_mul_mont_int(rp, ap, bp, np, n0, num); 28 return bn_mul_mont_int(rp, ap, bp, np, n0, num);
30} 29}
31 30
32unsigned long _sparcv9_rdtick(void);
33void _sparcv9_vis1_probe(void); 31void _sparcv9_vis1_probe(void);
34unsigned long _sparcv9_vis1_instrument(void); 32unsigned long _sparcv9_vis1_instrument(void);
35void _sparcv9_vis2_probe(void); 33void _sparcv9_vis2_probe(void);
36void _sparcv9_fmadd_probe(void); 34void _sparcv9_fmadd_probe(void);
37 35
38unsigned long
39OPENSSL_rdtsc(void)
40{
41 if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED)
42#if defined(__sun) && defined(__SVR4)
43 return gethrtime();
44#else
45 return 0;
46#endif
47 else
48 return _sparcv9_rdtick();
49}
50
51#if 0 && defined(__sun) && defined(__SVR4)
52/* This code path is disabled, because of incompatibility of
53 * libdevinfo.so.1 and libmalloc.so.1 (see below for details)
54 */
55#include <malloc.h>
56#include <dlfcn.h>
57#include <libdevinfo.h>
58#include <sys/systeminfo.h>
59
60typedef di_node_t (*di_init_t)(const char *, uint_t);
61typedef void (*di_fini_t)(di_node_t);
62typedef char * (*di_node_name_t)(di_node_t);
63typedef int (*di_walk_node_t)(di_node_t, uint_t, di_node_name_t, int (*)(di_node_t, di_node_name_t));
64
65#define DLLINK(h,name) (name=(name##_t)dlsym((h),#name))
66
67static int
68walk_nodename(di_node_t node, di_node_name_t di_node_name)
69{
70 char *name = (*di_node_name)(node);
71
72 /* This is expected to catch all UltraSPARC flavors prior T1 */
73 if (!strcmp (name, "SUNW,UltraSPARC") ||
74 !strncmp(name,"SUNW,UltraSPARC-I",17)) /* covers II,III,IV */
75 {
76 OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU|SPARCV9_VIS1;
77
78 /* %tick is privileged only on UltraSPARC-I/II, but not IIe */
79 if (name[14]!='\0' && name[17]!='\0' && name[18]!='\0')
80 OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
81
82 return DI_WALK_TERMINATE;
83 }
84 /* This is expected to catch remaining UltraSPARCs, such as T1 */
85 else if (!strncmp(name, "SUNW,UltraSPARC", 15)) {
86 OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
87
88 return DI_WALK_TERMINATE;
89 }
90
91 return DI_WALK_CONTINUE;
92}
93
94void
95OPENSSL_cpuid_setup(void)
96{
97 void *h;
98 char *e, si[256];
99 static int trigger = 0;
100
101 if (trigger)
102 return;
103 trigger = 1;
104
105 if ((e = getenv("OPENSSL_sparcv9cap"))) {
106 OPENSSL_sparcv9cap_P = strtoul(e, NULL, 0);
107 return;
108 }
109
110 if (sysinfo(SI_MACHINE, si, sizeof(si)) > 0) {
111 if (strcmp(si, "sun4v"))
112 /* FPU is preferred for all CPUs, but US-T1/2 */
113 OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU;
114 }
115
116 if (sysinfo(SI_ISALIST, si, sizeof(si)) > 0) {
117 if (strstr(si, "+vis"))
118 OPENSSL_sparcv9cap_P |= SPARCV9_VIS1;
119 if (strstr(si, "+vis2")) {
120 OPENSSL_sparcv9cap_P |= SPARCV9_VIS2;
121 OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
122 return;
123 }
124 }
125#ifdef M_KEEP
126 /*
127 * Solaris libdevinfo.so.1 is effectively incomatible with
128 * libmalloc.so.1. Specifically, if application is linked with
129 * -lmalloc, it crashes upon startup with SIGSEGV in
130 * free(3LIBMALLOC) called by di_fini. Prior call to
131 * mallopt(M_KEEP,0) somehow helps... But not always...
132 */
133 if ((h = dlopen(NULL, RTLD_LAZY))) {
134 union { void *p;
135 int (*f)(int, int);
136 } sym;
137 if ((sym.p = dlsym(h, "mallopt"))) (*sym.f)(M_KEEP, 0);
138 dlclose(h);
139 }
140#endif
141 if ((h = dlopen("libdevinfo.so.1", RTLD_LAZY)))
142 do {
143 di_init_t di_init;
144 di_fini_t di_fini;
145 di_walk_node_t di_walk_node;
146 di_node_name_t di_node_name;
147 di_node_t root_node;
148
149 if (!DLLINK(h, di_init))
150 break;
151 if (!DLLINK(h, di_fini))
152 break;
153 if (!DLLINK(h, di_walk_node))
154 break;
155 if (!DLLINK(h, di_node_name))
156 break;
157
158 if ((root_node = (*di_init)("/", DINFOSUBTREE)) !=
159 DI_NODE_NIL) {
160 (*di_walk_node)(root_node, DI_WALK_SIBFIRST,
161 di_node_name, walk_nodename);
162 (*di_fini)(root_node);
163 }
164 } while (0);
165
166 if (h)
167 dlclose(h);
168}
169
170#else
171
172static sigjmp_buf common_jmp; 36static sigjmp_buf common_jmp;
173static void common_handler(int sig) 37static void common_handler(int sig)
174{ 38{
@@ -193,7 +57,7 @@ OPENSSL_cpuid_setup(void)
193 } 57 }
194 58
195 /* Initial value, fits UltraSPARC-I&II... */ 59 /* Initial value, fits UltraSPARC-I&II... */
196 OPENSSL_sparcv9cap_P = SPARCV9_PREFER_FPU|SPARCV9_TICK_PRIVILEGED; 60 OPENSSL_sparcv9cap_P = SPARCV9_PREFER_FPU;
197 61
198 sigfillset(&all_masked); 62 sigfillset(&all_masked);
199 sigdelset(&all_masked, SIGILL); 63 sigdelset(&all_masked, SIGILL);
@@ -214,11 +78,6 @@ OPENSSL_cpuid_setup(void)
214 sigaction(SIGBUS,&common_act,&bus_oact);/* T1 fails 16-bit ldda [on Linux] */ 78 sigaction(SIGBUS,&common_act,&bus_oact);/* T1 fails 16-bit ldda [on Linux] */
215 79
216 if (sigsetjmp(common_jmp, 1) == 0) { 80 if (sigsetjmp(common_jmp, 1) == 0) {
217 _sparcv9_rdtick();
218 OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
219 }
220
221 if (sigsetjmp(common_jmp, 1) == 0) {
222 _sparcv9_vis1_probe(); 81 _sparcv9_vis1_probe();
223 OPENSSL_sparcv9cap_P |= SPARCV9_VIS1; 82 OPENSSL_sparcv9cap_P |= SPARCV9_VIS1;
224 /* detect UltraSPARC-Tx, see sparccpud.S for details... */ 83 /* detect UltraSPARC-Tx, see sparccpud.S for details... */
@@ -240,5 +99,3 @@ OPENSSL_cpuid_setup(void)
240 99
241 sigprocmask(SIG_SETMASK, &oset, NULL); 100 sigprocmask(SIG_SETMASK, &oset, NULL);
242} 101}
243
244#endif