The introduced SHA1_NOFINAL hasher was not sufficient for EAP-AKA,
[strongswan.git] / src / libstrongswan / fips / fips_canister_end.c
1 /* ====================================================================
2 * Copyright (c) 2005 The OpenSSL Project. Rights for redistribution
3 * and usage in source and binary forms are granted according to the
4 * OpenSSL license.
5 *
6 * $Id$
7 */
8
9 #include <stdio.h>
10 #if defined(__DECC)
11 # include <c_asm.h>
12 # pragma __nostandard
13 #endif
14
15 #if !defined(POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION)
16 # if (defined(__sun) && (defined(__sparc) || defined(__sparcv9))) || \
17 (defined(__sgi) && (defined(__mips) || defined(mips))) || \
18 (defined(__osf__) && defined(__alpha)) || \
19 (defined(__linux) && (defined(__arm) || defined(__arm__))) || \
20 (defined(__i386) || defined(__i386__)) || \
21 (defined(__x86_64) || defined(__x86_64__)) || \
22 (defined(vax) || defined(__vax__))
23 # define POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION
24 # endif
25 #endif
26
27 #define FIPS_ref_point FIPS_text_end
28 /* Some compilers put string literals into a separate segment. As we
29 * are mostly interested to hash AES tables in .rodata, we declare
30 * reference points accordingly. In case you wonder, the values are
31 * big-endian encoded variable names, just to prevent these arrays
32 * from being merged by linker. */
33 const unsigned int FIPS_rodata_end[]=
34 { 0x46495053, 0x5f726f64, 0x6174615f, 0x656e645b };
35
36
37 /*
38 * I declare reference function as static in order to avoid certain
39 * pitfalls in -dynamic linker behaviour...
40 */
41 static void *instruction_pointer(void)
42 {
43 void *ret = NULL;
44
45 /* These are ABI-neutral CPU-specific snippets. ABI-neutrality means
46 * that they are designed to work under any OS running on particular
47 * CPU, which is why you don't find any #ifdef THIS_OR_THAT_OS in
48 * this function. */
49 #if defined(INSTRUCTION_POINTER_IMPLEMENTED)
50 INSTRUCTION_POINTER_IMPLEMENTED(ret);
51 #elif defined(__GNUC__) && __GNUC__>=2
52 # if defined(__alpha) || defined(__alpha__)
53 # define INSTRUCTION_POINTER_IMPLEMENTED
54 __asm __volatile ( "br %0,1f\n1:" : "=r"(ret) );
55 # elif defined(__i386) || defined(__i386__)
56 # define INSTRUCTION_POINTER_IMPLEMENTED
57 __asm __volatile ( "call 1f\n1: popl %0" : "=r"(ret) );
58 ret = (void *)((size_t)ret&~3UL); /* align for better performance */
59 # elif defined(__ia64) || defined(__ia64__)
60 # define INSTRUCTION_POINTER_IMPLEMENTED
61 __asm __volatile ( "mov %0=ip" : "=r"(ret) );
62 # elif defined(__hppa) || defined(__hppa__) || defined(__pa_risc)
63 # define INSTRUCTION_POINTER_IMPLEMENTED
64 __asm __volatile ( "blr %%r0,%0\n\tnop" : "=r"(ret) );
65 ret = (void *)((size_t)ret&~3UL); /* mask privilege level */
66 # elif defined(__mips) || defined(__mips__)
67 # define INSTRUCTION_POINTER_IMPLEMENTED
68 void *scratch;
69 __asm __volatile ( "move %1,$31\n\t" /* save ra */
70 "bal .+8; nop\n\t"
71 "move %0,$31\n\t"
72 "move $31,%1" /* restore ra */
73 : "=r"(ret),"=r"(scratch) );
74 # elif defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || \
75 defined(__POWERPC__) || defined(_POWER) || defined(__PPC__) || \
76 defined(__PPC64__) || defined(__powerpc64__)
77 # define INSTRUCTION_POINTER_IMPLEMENTED
78 void *scratch;
79 __asm __volatile ( "mfspr %1,8\n\t" /* save lr */
80 "bl .+4\n\t"
81 "mfspr %0,8\n\t" /* mflr ret */
82 "mtspr 8,%1" /* restore lr */
83 : "=r"(ret),"=r"(scratch) );
84 # elif defined(__sparc) || defined(__sparc__) || defined(__sparcv9)
85 # define INSTRUCTION_POINTER_IMPLEMENTED
86 void *scratch;
87 __asm __volatile ( "mov %%o7,%1\n\t"
88 "call .+8; nop\n\t"
89 "mov %%o7,%0\n\t"
90 "mov %1,%%o7"
91 : "=r"(ret),"=r"(scratch) );
92 # elif defined(__x86_64) || defined(__x86_64__)
93 # define INSTRUCTION_POINTER_IMPLEMENTED
94 __asm __volatile ( "leaq 0(%%rip),%0" : "=r"(ret) );
95 ret = (void *)((size_t)ret&~3UL); /* align for better performance */
96 # endif
97 #elif defined(__DECC) && defined(__alpha)
98 # define INSTRUCTION_POINTER_IMPLEMENTED
99 ret = (void *)(size_t)asm("br %v0,1f\n1:");
100 #elif defined(_MSC_VER) && defined(_M_IX86)
101 # undef INSTRUCTION_POINTER_IMPLEMENTED
102 void *scratch;
103 _asm {
104 call self
105 self: pop eax
106 mov scratch,eax
107 }
108 ret = (void *)((size_t)scratch&~3UL);
109 #endif
110 return ret;
111 }
112
113 /*
114 * This function returns pointer to an instruction in the vicinity of
115 * its entry point, but not outside this object module. This guarantees
116 * that sequestered code is covered...
117 */
118 void *FIPS_ref_point()
119 {
120 #if defined(INSTRUCTION_POINTER_IMPLEMENTED)
121 return instruction_pointer();
122 /* Below we essentially cover vendor compilers which do not support
123 * inline assembler... */
124 #elif defined(_AIX)
125 struct { void *ip,*gp,*env; } *p = (void *)instruction_pointer;
126 return p->ip;
127 #elif defined(_HPUX_SOURCE)
128 # if defined(__hppa) || defined(__hppa__)
129 struct { void *i[4]; } *p = (void *)FIPS_ref_point;
130
131 if (sizeof(p) == 8) /* 64-bit */
132 return p->i[2];
133 else if ((size_t)p & 2)
134 { p = (void *)((size_t)p&~3UL);
135 return p->i[0];
136 }
137 else
138 return (void *)p;
139 # elif defined(__ia64) || defined(__ia64__)
140 struct { unsigned long long ip,gp; } *p=(void *)instruction_pointer;
141 return (void *)(size_t)p->ip;
142 # endif
143 #elif (defined(__VMS) || defined(VMS)) && !(defined(vax) || defined(__vax__))
144 /* applies to both alpha and ia64 */
145 struct { unsigned __int64 opaque,ip; } *p=(void *)instruction_pointer;
146 return (void *)(size_t)p->ip;
147 #elif defined(__VOS__)
148 /* applies to both pa-risc and ia32 */
149 struct { void *dp,*ip,*gp; } *p = (void *)instruction_pointer;
150 return p->ip;
151 #elif defined(_WIN32)
152 # if defined(_WIN64) && defined(_M_IA64)
153 struct { void *ip,*gp; } *p = (void *)FIPS_ref_point;
154 return p->ip;
155 # else
156 return (void *)FIPS_ref_point;
157 # endif
158 /*
159 * In case you wonder why there is no #ifdef __linux. All Linux targets
160 * are GCC-based and therefore are covered by instruction_pointer above
161 * [well, some are covered by by the one below]...
162 */
163 #elif defined(POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION)
164 return (void *)instruction_pointer;
165 #else
166 return NULL;
167 #endif
168 }