Secure Monitor: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
= Secure Monitor | = Secure Monitor Calls = | ||
The secure monitor provides two top level handlers of which each provides a range of sub handlers. | The secure monitor provides two top level handlers of which each provides a range of sub handlers. | ||
Secure Monitor calls follow the ARM SMC calling convention | Secure Monitor calls follow the ARM SMC calling convention with a small change: | ||
{| class=wikitable | {| class=wikitable | ||
! | ! Bits || Description | ||
|- | |- | ||
| | | 0-7 || Function Number | ||
|- | |- | ||
| | | 8-15 || Argument Type | ||
|- | |- | ||
| | | 16-23 || Reserved | ||
|- | |- | ||
| | | 24-29 || Call Range | ||
|- | |- | ||
| | | 30 || Call Convention (0 = SMC32, 1 = SMC64) | ||
|- | |- | ||
| | | 31 || Call Type (0 = Yielding Call, 1 = Fast Call) | ||
|} | |} | ||
Line 37: | Line 37: | ||
| 0xC3000404 || GetResultData | | 0xC3000404 || GetResultData | ||
|- | |- | ||
| 0xC3000E05 || | | 0xC3000E05 || ModularExponentiate | ||
|- | |- | ||
| 0xC3000006 || [[#GenerateRandomBytes]] (same as in [[#FunctionId1]]) | | 0xC3000006 || [[#GenerateRandomBytes]] (same as in [[#FunctionId1]]) | ||
Line 51: | Line 51: | ||
| 0xC300040B || [[#ComputeCmac]] | | 0xC300040B || [[#ComputeCmac]] | ||
|- | |- | ||
| [1.0.0-4.1.0] 0xC300100C || [[# | | [1.0.0-4.1.0] 0xC300100C || [[#DecryptAndImportEsDeviceKey]] | ||
|- | |- | ||
| [5.0.0+] 0xC300D60C || [[# | | [5.0.0+] 0xC300D60C || [[#ReencryptDeviceUniqueData]] | ||
|- | |- | ||
| | | 0xC300100D || [[#DecryptDeviceUniqueData]] | ||
|- | |- | ||
| [ | | [1.0.0-4.1.0] 0xC300100E || [[#DecryptAndImportLotusKey]] | ||
|- | |- | ||
| | | 0xC300060F || [[#ModularExponentiateByStorageKey]] | ||
|- | |- | ||
| | | 0xC3000610 || [[#PrepareEsDeviceUniqueKey]] | ||
|- | |- | ||
| | | 0xC3000011 || [[#LoadPreparedAesKey]] | ||
|- | |- | ||
| 0xC3000012 || [2.0.0+] [[#PrepareEsCommonKey]] | |||
| 0xC3000012 || [2.0.0+] [[# | |||
|} | |} | ||
Line 101: | Line 99: | ||
Calculates CMAC over input data. | Calculates CMAC over input data. | ||
=== | === DecryptAndImportEsDeviceKey === | ||
Takes a session kek created with [[#GenerateAesKek]], a wrapped AES key, and a wrapped RSA private key. | Takes a session kek created with [[#GenerateAesKek]], a wrapped AES key, and a wrapped RSA private key. | ||
The session kek must have been created with [[#CryptoUsecase|CryptoUsecase TitleKey]]. | The session kek must have been created with [[#CryptoUsecase|CryptoUsecase TitleKey]]. | ||
[5.0.0] This function was removed and replaced with [[# | [5.0.0] This function was removed and replaced with [[#ReencryptDeviceUniqueData]]. | ||
=== | === ReencryptDeviceUniqueData === | ||
Takes in two session keks created with [[#GenerateAesKek]], two wrapped AES keys, an enum member, and a wrapped RSA private key. | Takes in two session keks created with [[#GenerateAesKek]], two wrapped AES keys, an enum member, and a wrapped RSA private key. | ||
Decrypts and validates the wrapped RSA private key with the first kek/wrapped key, and re-encrypts it with the second if valid. | Decrypts and validates the wrapped RSA private key with the first kek/wrapped key, and re-encrypts it with the second if valid. | ||
The re-encrypted key is then passed to the user, for use with [[# | The re-encrypted key is then passed to the user, for use with [[#DecryptDeviceUniqueData]]. | ||
=== | === DecryptDeviceUniqueData === | ||
Takes a session kek created with [[#GenerateAesKek]], a wrapped AES key, an enum member, and a wrapped RSA private key. | Takes a session kek created with [[#GenerateAesKek]], a wrapped AES key, an enum member, and a wrapped RSA private key. | ||
Line 122: | Line 120: | ||
[4.0.0+] The SMC handler when certain conditions pass and FunctionId0==0xC300100D now returns error 0x6 instead of calling the handler funcptr. | [4.0.0+] The SMC handler when certain conditions pass and FunctionId0==0xC300100D now returns error 0x6 instead of calling the handler funcptr. | ||
[5.0.0+] This function | [5.0.0+] This function now takes an additional input [[#DecryptOrImportMode]]. This extends the original functionality to enable importing private keys into the security engine instead of decrypting them. | ||
This | |||
=== | === DecryptAndImportLotusKey === | ||
Takes a session kek created with [[#GenerateAesKek]], and a wrapped RSA key. | Takes a session kek created with [[#GenerateAesKek]], and a wrapped RSA key. | ||
Line 136: | Line 129: | ||
[5.0.0] This function was removed. | [5.0.0] This function was removed. | ||
=== | === ModularExponentiateByStorageKey === | ||
Performs an ExpMod operation using an exponent previously loaded with the [[# | Performs an ExpMod operation using an exponent previously loaded with the [[#DecryptAndImportLotusKey]] command. | ||
[5.0.0+] This now uses any exponent previously loaded with [[# | [5.0.0+] This now uses any exponent previously loaded with [[#DecryptDeviceUniqueData]] and takes an [[#SecureExpModMode]]. | ||
=== | === PrepareEsDeviceUniqueKey === | ||
Takes an Rsa-Oaep-wrapped TitleKey, an RSA Public Key, and a label hash. | Takes an Rsa-Oaep-wrapped TitleKey, an RSA Public Key, and a label hash. | ||
Performs an ExpMod operation using an exponent previously loaded with the [[# | Performs an ExpMod operation using an exponent previously loaded with the [[#DecryptAndImportEsDeviceKey]] command, and then validates/extracts a Titlekey from the resulting message. | ||
Returns a session-unique AES key especially for use in [[#LoadTitleKey]]. | Returns a session-unique AES key especially for use in [[#LoadTitleKey]]. | ||
[5.0.0+] This now uses any exponent previously loaded with [[# | [5.0.0+] This now uses any exponent previously loaded with [[#DecryptDeviceUniqueData]]. | ||
=== | === LoadPreparedAesKey === | ||
Takes a session-unique AES key from [[# | Takes a session-unique AES key from [[#PrepareEsCommonKey]] or [[#PrepareEsDeviceUniqueKey]]. | ||
=== | === PrepareEsCommonKey === | ||
Takes an AES-wrapped TitleKey and returns a sealed AES key. | Takes an AES-wrapped common TitleKey and returns a sealed AES key. | ||
== FunctionId1 == | == FunctionId1 == | ||
Line 162: | Line 155: | ||
! Value || Name | ! Value || Name | ||
|- | |- | ||
| 0xC4000001 || [[# | | 0xC4000001 || [[#SuspendCpu]] | ||
|- | |- | ||
| 0x84000002 || [[# | | 0x84000002 || [[#PowerOffCpu]] | ||
|- | |- | ||
| 0xC4000003 || [[# | | 0xC4000003 || [[#PowerOnCpu]] | ||
|- | |- | ||
| 0xC3000004 || [[#GetConfig]] (same as in [[#FunctionId0]]) | | 0xC3000004 || [[#GetConfig]] (same as in [[#FunctionId0]]) | ||
Line 172: | Line 165: | ||
| 0xC3000005 || [[#GenerateRandomBytes]] (same as in [[#FunctionId0]]) | | 0xC3000005 || [[#GenerateRandomBytes]] (same as in [[#FunctionId0]]) | ||
|- | |- | ||
| 0xC3000006 || [[# | | 0xC3000006 || [[#ShowError]] | ||
|- | |- | ||
| 0xC3000007 || [2.0.0+] [[# | | 0xC3000007 || [2.0.0+] [[#SetKernelCarveoutRegion]] | ||
|- | |- | ||
| 0xC3000008 || [2.0.0+] [[#ReadWriteRegister]] | | 0xC3000008 || [2.0.0+] [[#ReadWriteRegister]] | ||
|} | |} | ||
=== | === SuspendCpu === | ||
Takes an u64 '''PowerState''', an u64 '''EntrypointAddress''' and an u64 '''ContextId'''. No output. | Takes an u64 '''PowerState''', an u64 '''EntrypointAddress''' and an u64 '''ContextId'''. No output. | ||
Line 186: | Line 179: | ||
The kernel calls this SMC on shutdown with '''PowerState''' set to 0x0201001B (power level: 0x02==system; power type: 0x01==powerdown; ID: 0x1B). | The kernel calls this SMC on shutdown with '''PowerState''' set to 0x0201001B (power level: 0x02==system; power type: 0x01==powerdown; ID: 0x1B). | ||
=== | === PowerOffCpu === | ||
No input/output. | No input/output. | ||
Turns off the CPU (CPU1, CPU2 or CPU3). | Turns off the CPU (CPU1, CPU2 or CPU3). | ||
=== | === PowerOnCpu === | ||
Takes an u64 '''TargetCpu''', an u64 '''EntrypointAddress''' and an u64 '''ContextId'''. Returns [[#Result]]. | Takes an u64 '''TargetCpu''', an u64 '''EntrypointAddress''' and an u64 '''ContextId'''. Returns [[#Result]]. | ||
Line 785: | Line 778: | ||
The kernel limits '''Size''' to 0x38 (for fitting in return registers). | The kernel limits '''Size''' to 0x38 (for fitting in return registers). | ||
=== | === ShowError === | ||
Takes an u32 '''Color''' and issues a system panic. | Takes an u32 '''Color''' and issues a system panic. | ||
The kernel always calls this with '''Color''' set to 0xF00. | The kernel always calls this with '''Color''' set to 0xF00. | ||
=== | === SetKernelCarveoutRegion === | ||
Takes an u64 '''Index''', an u64 '''Address''' and an u64 '''Size'''. Returns [[#Result]]. | Takes an u64 '''Index''', an u64 '''Address''' and an u64 '''Size'''. Returns [[#Result]]. | ||