-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update opensbi version to opensbi-1.2
- Loading branch information
Showing
69 changed files
with
19,071 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
#Build & install directories | ||
build/ | ||
build-oe/ | ||
install/ | ||
|
||
# Development friendly files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef __SBI_PMP_H__ | ||
#define __SBI_PMP_H__ | ||
|
||
#include <sm/pmp.h> | ||
#include <sbi/sbi_types.h> | ||
#include <sbi/sbi_hartmask.h> | ||
struct sbi_scratch; | ||
int sbi_pmp_init(struct sbi_scratch *scratch, bool cold_boot); | ||
int sbi_send_pmp(ulong hmask, ulong hbase, struct pmp_data_t* pmp_data); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef _ATTEST_H | ||
#define _ATTEST_H | ||
|
||
#include "sm/enclave.h" | ||
|
||
void attest_init(); | ||
|
||
void hash_enclave(struct enclave_t* enclave, void* hash, uintptr_t nonce); | ||
|
||
void update_enclave_hash(char *output, void* hash, uintptr_t nonce_arg); | ||
|
||
void sign_enclave(void* signature, unsigned char *message, int len); | ||
|
||
int verify_enclave(void* signature, unsigned char *message, int len); | ||
|
||
#endif /* _ATTEST_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#ifndef _ENCLAVE_H | ||
#define _ENCLAVE_H | ||
|
||
#include <sbi/riscv_asm.h> | ||
#include <sm/vm.h> | ||
#include <sbi/riscv_encoding.h> | ||
#include <sm/enclave_args.h> | ||
#include <sbi/riscv_atomic.h> | ||
#include <sm/thread.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
#define ENCLAVES_PER_METADATA_REGION 128 | ||
#define ENCLAVE_METADATA_REGION_SIZE ((sizeof(struct enclave_t)) * ENCLAVES_PER_METADATA_REGION) | ||
|
||
#define ENCLAVE_MODE 1 | ||
|
||
// define the time slice for an enclave | ||
#define ENCLAVE_TIME_CREDITS 100000 | ||
|
||
struct link_mem_t | ||
{ | ||
unsigned long mem_size; | ||
unsigned long slab_size; | ||
unsigned long slab_num; | ||
char* addr; | ||
struct link_mem_t* next_link_mem; | ||
}; | ||
|
||
typedef enum | ||
{ | ||
DESTROYED = -1, | ||
INVALID = 0, | ||
FRESH = 1, | ||
RUNNABLE, | ||
RUNNING, | ||
STOPPED, | ||
} enclave_state_t; | ||
|
||
/* | ||
* enclave memory [paddr, paddr + size] | ||
* free_mem @ unused memory address in enclave mem | ||
*/ | ||
struct enclave_t | ||
{ | ||
unsigned int eid; | ||
enclave_state_t state; | ||
|
||
//memory region of enclave | ||
unsigned long paddr; | ||
unsigned long size; | ||
|
||
//address of left available memory in memory region | ||
unsigned long free_mem; | ||
|
||
//TODO: dynamically allocated memory | ||
unsigned long* enclave_mem_metadata_page; | ||
|
||
//root page table of enclave | ||
unsigned long* root_page_table; | ||
//root page table register for host | ||
unsigned long host_ptbr; | ||
//entry point of enclave | ||
unsigned long entry_point; | ||
|
||
//shared mem with kernel | ||
unsigned long kbuffer; | ||
unsigned long kbuffer_size; | ||
|
||
unsigned long* ocall_func_id; | ||
unsigned long* ocall_arg0; | ||
unsigned long* ocall_arg1; | ||
unsigned long* ocall_syscall_num; | ||
|
||
//shared memory with host | ||
unsigned long untrusted_ptr; | ||
unsigned long untrusted_size; | ||
// enclave measurement | ||
unsigned char hash[HASH_SIZE]; | ||
// hash of enclave developer's public key | ||
unsigned char signer[HASH_SIZE]; | ||
|
||
//enclave thread context | ||
//TODO: support multiple threads | ||
struct thread_state_t thread_context; | ||
}; | ||
|
||
struct cpu_state_t | ||
{ | ||
int in_enclave; | ||
int eid; | ||
}; | ||
|
||
uintptr_t create_enclave(struct enclave_sbi_param_t create_args); | ||
uintptr_t run_enclave(uintptr_t* regs, unsigned int eid); | ||
uintptr_t stop_enclave(uintptr_t* regs, unsigned int eid); | ||
uintptr_t destroy_enclave(uintptr_t* regs, unsigned int eid); | ||
uintptr_t resume_enclave(uintptr_t* regs, unsigned int eid); | ||
uintptr_t resume_from_stop(uintptr_t* regs, unsigned int eid); | ||
uintptr_t attest_enclave(uintptr_t eid, uintptr_t report_ptr, uintptr_t nonce); | ||
uintptr_t exit_enclave(uintptr_t* regs, unsigned long retval); | ||
uintptr_t do_timer_irq(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc); | ||
|
||
uintptr_t resume_from_ocall(uintptr_t* regs, unsigned int eid); | ||
uintptr_t enclave_sys_write(uintptr_t *regs); | ||
uintptr_t enclave_user_defined_ocall(uintptr_t *regs, uintptr_t ocall_buf_size); | ||
uintptr_t enclave_derive_seal_key(uintptr_t* regs, uintptr_t salt_va, | ||
uintptr_t salt_len, uintptr_t key_buf_va, uintptr_t key_buf_len); | ||
|
||
int check_in_enclave_world(); | ||
|
||
#endif /* _ENCLAVE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef _ENCLAVE_ARGS_H | ||
#define _ENCLAVE_ARGS_H | ||
#include "thread.h" | ||
#define HASH_SIZE 32 | ||
#define PRIVATE_KEY_SIZE 32 | ||
#define PUBLIC_KEY_SIZE 64 | ||
#define SIGNATURE_SIZE 64 | ||
|
||
#define MANU_PUB_KEY (void*)((unsigned long)0x801ff000) | ||
#define DEV_PUB_KEY (MANU_PUB_KEY + PUBLIC_KEY_SIZE) | ||
#define DEV_PRI_KEY (DEV_PUB_KEY + PUBLIC_KEY_SIZE) | ||
#define SM_PUB_KEY (DEV_PRI_KEY + PRIVATE_KEY_SIZE) | ||
#define SM_PRI_KEY (SM_PUB_KEY + PUBLIC_KEY_SIZE) | ||
#define SM_HASH (SM_PRI_KEY + PRIVATE_KEY_SIZE) | ||
#define SM_SIGNATURE (SM_HASH + HASH_SIZE) | ||
|
||
struct mm_alloc_arg_t | ||
{ | ||
unsigned long req_size; | ||
uintptr_t resp_addr; | ||
unsigned long resp_size; | ||
}; | ||
|
||
// Attestation-related report | ||
struct sm_report_t | ||
{ | ||
unsigned char hash[HASH_SIZE]; | ||
unsigned char signature[SIGNATURE_SIZE]; | ||
unsigned char sm_pub_key[PUBLIC_KEY_SIZE]; | ||
}; | ||
|
||
struct enclave_report_t | ||
{ | ||
unsigned char hash[HASH_SIZE]; | ||
unsigned char signature[SIGNATURE_SIZE]; | ||
uintptr_t nonce; | ||
}; | ||
|
||
struct report_t | ||
{ | ||
struct sm_report_t sm; | ||
struct enclave_report_t enclave; | ||
unsigned char dev_pub_key[PUBLIC_KEY_SIZE]; | ||
}; | ||
|
||
struct prikey_t | ||
{ | ||
unsigned char dA[PRIVATE_KEY_SIZE]; | ||
}; | ||
|
||
struct pubkey_t | ||
{ | ||
unsigned char xA[PUBLIC_KEY_SIZE/2]; | ||
unsigned char yA[PUBLIC_KEY_SIZE/2]; | ||
}; | ||
|
||
struct signature_t | ||
{ | ||
unsigned char r[PUBLIC_KEY_SIZE/2]; | ||
unsigned char s[PUBLIC_KEY_SIZE/2]; | ||
}; | ||
|
||
/* | ||
* enclave memory [paddr, paddr + size] | ||
* free_mem @ unused memory address in enclave mem | ||
*/ | ||
struct enclave_sbi_param_t | ||
{ | ||
unsigned int *eid_ptr; | ||
unsigned long paddr; | ||
unsigned long size; | ||
unsigned long entry_point; | ||
unsigned long untrusted_ptr; | ||
unsigned long untrusted_size; | ||
unsigned long free_mem; | ||
//enclave shared mem with kernel | ||
unsigned long kbuffer; | ||
unsigned long kbuffer_size; | ||
unsigned long *ecall_arg0; | ||
unsigned long *ecall_arg1; | ||
unsigned long *ecall_arg2; | ||
unsigned long *ecall_arg3; | ||
}; | ||
|
||
#endif /* _ENCLAVE_ARGS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/************************************************************************ | ||
Copyright (c) IPADS@SJTU 2021. Modification to support Penglai (RISC-V TEE) | ||
This file contains GM/T SM2 standard implementation, provided by the Commercial | ||
Cryptography Testing Center, see <http://www.scctc.org.cn> for more infomation. | ||
File name: SM2_sv.c | ||
Version: SM2_sv_V1.0 | ||
Date: Sep 27,2016 | ||
Description: implementation of SM2 signature algorithm and verification algorithm | ||
Function List: | ||
1.SM2_Init //initiate SM2 curve | ||
2.Test_Point //test if the given point is on SM2 curve | ||
3.Test_PubKey //test if the given public key is valid | ||
4.Test_Zero //test if the big x equals zero | ||
5.Test_n //test if the big x equals n | ||
6.Test_Range //test if the big x belong to the range[1,n-1] | ||
7.SM2_KeyGeneration //generate SM2 key pair | ||
8.SM2_Sign //SM2 signature algorithm | ||
9.SM2_Verify //SM2 verification | ||
10.SM2_SelfCheck() //SM2 self-check | ||
11.SM3_256() //this function can be found in SM3.c and SM3.h | ||
Additional Functions Added By PENGLAI Enclave: | ||
1.MIRACL_Init //init miracl system | ||
2.SM2_make_prikey //generate a SM2 private key | ||
3.SM2_make_pubkey //generate a SM2 public Key out of a private Key | ||
4.SM2_gen_random //generate a random number K lies in [1,n-1] | ||
5.SM2_compute_ZA //compute ZA out of a given pubkey | ||
**************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "sm/gm/miracl/miracl.h" | ||
|
||
#define SM2_WORDSIZE 8 | ||
#define SM2_NUMBITS 256 | ||
#define SM2_NUMWORD (SM2_NUMBITS / SM2_WORDSIZE) | ||
|
||
#define ERR_ECURVE_INIT 0x00000001 | ||
#define ERR_INFINITY_POINT 0x00000002 | ||
#define ERR_NOT_VALID_POINT 0x00000003 | ||
#define ERR_ORDER 0x00000004 | ||
#define ERR_NOT_VALID_ELEMENT 0x00000005 | ||
#define ERR_GENERATE_R 0x00000006 | ||
#define ERR_GENERATE_S 0x00000007 | ||
#define ERR_OUTRANGE_R 0x00000008 | ||
#define ERR_OUTRANGE_S 0x00000009 | ||
#define ERR_GENERATE_T 0x0000000A | ||
#define ERR_PUBKEY_INIT 0x0000000B | ||
#define ERR_DATA_MEMCMP 0x0000000C | ||
|
||
int SM2_Init(); | ||
int Test_Point(epoint *point); | ||
int Test_PubKey(epoint *pubKey); | ||
int Test_Zero(big x); | ||
int Test_n(big x); | ||
int Test_Range(big x); | ||
int SM2_KeyGeneration(unsigned char PriKey[], unsigned char Px[], unsigned char Py[]); | ||
int SM2_Sign(unsigned char *message, int len, unsigned char d[], unsigned char R[], unsigned char S[]); | ||
int SM2_Verify(unsigned char *message, int len, unsigned char Px[], unsigned char Py[], unsigned char R[], unsigned char S[]); | ||
int SM2_SelfCheck(); |
Oops, something went wrong.