For bad example 2, please check if the panic info is: `thread '<unnamed>' 
panicked at 'TLS access error: AccessError { msg: "If TLS data needs to be 
destructed, TCS policy must be Bound." }'`. If so, the problem is:

1. the enclave is signed with TCSPOLICY=UNBOUNT, which means there's no 
reliable thread local storage slots.
2. the enclave is using thread local storage, which often relates to 
`thread_rng`

Two ways to fix:
- Edit TCSPolicy in `Enclave.config.xml`. make TCSPolicy = 0
- or use `SgxRng` in `sgx_rand`, or `OsRng` in ported `rand`

```toml
rand = { git = "https://github.com/mesalock-linux/rand-sgx";, tag = 
"v0.6.5_sgx1.1.1" }
```

```rust
use std::string::ToString;
let threshold = 128;
let secret = "abcdefg".to_string();
let mut rand_container = vec![0u8; (threshold - 1) as usize];
let mut coefficients= vec![];

for c in secret.as_bytes() {

    // fixme: randomise the bytes

    let mut rng = SgxRng::new().unwrap();
    rng.fill_bytes(&mut rand_container);
    let mut coef: Vec<u8> = vec![*c];
    for r in rand_container.iter() {
        coef.push(*r);
    }
    coefficients.push(coef);
}

{
    use rand::rngs::OsRng;
    use rand::RngCore;
    OsRng.fill_bytes(&mut rand_container);
}
168     }
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/218#issuecomment-609957812

Reply via email to