forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_opteeTa.c
80 lines (62 loc) · 1.91 KB
/
env_opteeTa.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
//
// env_opteeTa.c
// Platform-specific code for OPTEE TA.
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
// OPTEE TA specific data
#define TEE_ERROR_BAD_STATE 0xFFFF0007
typedef uint32_t TEE_Result;
void TEE_Panic(TEE_Result panicCode);
SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvOpteeTa(void)
{
return 0;
}
VOID
SYMCRYPT_CALL
SymCryptInitEnvOpteeTa( UINT32 version )
{
if( g_SymCryptFlags & SYMCRYPT_FLAG_LIB_INITIALIZED )
{
return;
}
// Optee module relies on the unconditional availability of certain CPU features (ASIMD, AES, PMULL, SHA256)
g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) ~(SYMCRYPT_CPU_FEATURE_NEON|SYMCRYPT_CPU_FEATURE_NEON_AES|SYMCRYPT_CPU_FEATURE_NEON_PMULL|SYMCRYPT_CPU_FEATURE_NEON_SHA256);
SymCryptInitEnvCommon( version );
}
_Analysis_noreturn_
VOID
SYMCRYPT_CALL
SymCryptFatalEnvOpteeTa( ULONG 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 can trigger a core dump so that we get to
// see what is going wrong.
//
__fastfail( FAST_FAIL_CRYPTO_LIBRARY );
TEE_Panic(TEE_ERROR_BAD_STATE);
//
// Next we write to the NULL pointer, this causes an AV
//
SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode );
SymCryptFatalHang( fatalCode );
}
VOID
SYMCRYPT_CALL
SymCryptTestInjectErrorEnvOpteeTa( 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 );
}