forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_generic.c
142 lines (116 loc) · 3.63 KB
/
env_generic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// env_generic.c
// Platform-specific code for a generic environment
// This is suitable for many embedded environments.
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvGeneric(void)
{
#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
// Avoid all CPU features except RDRAND and RDSEED
return (SYMCRYPT_CPU_FEATURES) ~(SYMCRYPT_CPU_FEATURE_RDRAND | SYMCRYPT_CPU_FEATURE_RDSEED );
#elif SYMCRYPT_CPU_ARM | SYMCRYPT_CPU_ARM64
return (SYMCRYPT_CPU_FEATURES) ~(0); // Disable all features
#elif SYMCRYPT_CPU_UNKNOWN
return (SYMCRYPT_CPU_FEATURES) ~(0); // Disable all features
#endif
}
VOID
SYMCRYPT_CALL
SymCryptInitEnvGeneric( UINT32 version )
{
if( g_SymCryptFlags & SYMCRYPT_FLAG_LIB_INITIALIZED )
{
return;
}
#if SYMCRYPT_CPU_X86 | SYMCRYPT_CPU_AMD64
// We only need to detect RDRAND and RDSEED, the other features are locked out from the NeverPresent value.
// Do not detect OS support for YMM registers; we have disabled them in this environment anyway
SymCryptDetectCpuFeaturesByCpuid( 0 );
//
// All extended registers are locked out by the g_SymCryptCpuFeaturesNeverPresent
//
#elif SYMCRYPT_CPU_ARM | SYMCRYPT_CPU_ARM64
// All Neon operations are locked out by the static NeverPresent value.
#endif
SymCryptInitEnvCommon( version );
}
_Analysis_noreturn_
VOID
SYMCRYPT_CALL
SymCryptFatalEnvGeneric( UINT32 fatalCode )
{
UINT32 fatalCodeVar;
SymCryptFatalIntercept( fatalCode );
//
// Put the fatal code in a location where it shows up in the dump
//
SYMCRYPT_FORCE_WRITE32( &fatalCodeVar, fatalCode );
//
// Our first preference is to fastfail,
// the second to create an AV, which triggers a Watson report so that we get to
// see what is going wrong.
//
__fastfail( FAST_FAIL_CRYPTO_LIBRARY );
//
// Next we write to the NULL pointer, this causes an AV
//
SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode );
SymCryptFatalHang( fatalCode );
}
#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86
//
// These functions should never be called in the generic environment.
//
SYMCRYPT_ERROR
SYMCRYPT_CALL
SymCryptSaveXmmEnvGeneric( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
UNREFERENCED_PARAMETER( pSaveArea );
SymCryptFatal( 'mmxs' );
return SYMCRYPT_NO_ERROR;
}
VOID
SYMCRYPT_CALL
SymCryptRestoreXmmEnvGeneric( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
UNREFERENCED_PARAMETER( pSaveArea );
SymCryptFatal( 'mmxs' );
}
SYMCRYPT_ERROR
SYMCRYPT_CALL
SymCryptSaveYmmEnvGeneric( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
UNREFERENCED_PARAMETER( pSaveArea );
SymCryptFatal( 'mmys' );
return SYMCRYPT_NO_ERROR;
}
VOID
SYMCRYPT_CALL
SymCryptRestoreYmmEnvGeneric( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveArea )
{
SymCryptFatal( 'mmxs' );
UNREFERENCED_PARAMETER( pSaveArea );
}
#endif
VOID
SYMCRYPT_CALL
SymCryptTestInjectErrorEnvGeneric( PBYTE pbBuf, SIZE_T cbBuf )
{
//
// This feature is only used during testing. In production it is always
// an empty function that the compiler can optimize away.
//
UNREFERENCED_PARAMETER( pbBuf );
UNREFERENCED_PARAMETER( cbBuf );
}
#if SYMCRYPT_CPU_AMD64 | SYMCRYPT_CPU_X86
VOID
SYMCRYPT_CALL
SymCryptCpuidExFuncEnvGeneric( int cpuInfo[4], int function_id, int subfunction_id )
{
__cpuidex( cpuInfo, function_id, subfunction_id );
}
#endif