<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 7 Jul 2023, 18:11 1one1 via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div><br></div><div>**Document number**: PXXXXR0  </div><div>**Date**: 2023-07-07  </div><div>**Project**: Programming Language C++  </div><div>**Reply to**: ahshabazz</div><div><br></div><div># Proposal to introduce a Hardware Security Namespace to the C++ Standard Library</div><div><br></div><div>## Introduction</div><div><br></div><div>This paper proposes the addition of a new hardware security namespace to the C++ Standard Library to allow developers to better leverage hardware-level security features in a platform-independent manner. This proposal is intended as a high level architecture agnostic secure compute model because as of today both Intel, AMD, and many other vendors have introduced various security measures in their hardware, such as Intel&#39;s Software Guard Extensions (SGX). An API in the C++ standard for these features could provide developers with the tools to ensure secure computation and data protection. </div><div><br></div><div>## Motivation and Scope</div><div><br></div><div>Modern processors from vendors such as Intel and AMD provide various hardware-level security features, such as Intel&#39;s Software Guard Extensions (SGX). And yet currently, there is no standard way in C++ to utilize these features, and developers must rely on vendor-specific APIs and tools, leading to non-portable code.</div><div><br></div><div>By introducing a standard hardware security namespace, we can provide developers with a more consistent, abstracted way to use these features and improve the security of their applications without sacrificing portability.</div><div><br></div><div>The API call and management would be similar to the std::thread API in C++11 and later versions, because it is a suitable example of an API which uses a similar design pattern, ie.:</div><div><br></div><div>    Creation: A std::thread object is created by constructing an instance of the std::thread class, passing the function to be executed in a new thread as a constructor argument. This is in much the same way [[secure::enclave]] would work.</div><div><br></div><div>    Execution: With std::thread, the execution of std::thread starts after its creation. However with [[secure::enclave]] there is an explicit .execute() call, because the new executing context may immediately be used and reused after creation.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Does the execution happen in a new thread of execution? Is it detached? Does it need to be joined? What happens if you call execute twice in a row? Does it block?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br></div><div>    Destruction: Before a std::thread object is destroyed, you must either join it (with std::thread::join()) or detach it (with std::thread::detach()), or the program will terminate. [[secure::enclave]] would employ a similar .destroy() call.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Why is that restriction suitable here?</div><div dir="auto"><br></div><div dir="auto">If the API is so similar to std::thread, why not use the same API? The changes don&#39;t seem sufficiently motivated.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br></div><div>## Impact on the C++ Standard</div><div><br></div><div>This proposal is purely additive and does not modify any existing parts of the C++ Standard. It does not require any changes to the core language.</div><div><br></div><div>## Design Decisions</div><div><br></div><div>The proposed namespace, tentatively named `hwsec`, will initially contain an attribute to denote functions that should run in a secure context, and a class that manages secure contexts. The proposed design is similar to how `std::thread` manages threads, but separates resource acquisition and execution into separate methods to provide more control to the user.</div><div><br></div><div>The API signature could look as follows:</div><div><br></div><div>```</div><div>[[hwsec::enclave]]</div><div>void secureFunction() {</div><div>    // Code here runs in a secure enclave //</div><div>    std::cout &lt;&lt; &quot;Running in a secure enclave.&quot; &lt;&lt; std::endl;</div><div>}</div><div><br></div><div>int main() {</div><div>    hwsec::Enclave myEnclave;</div><div><br></div><div>    try {</div><div>        // Create a new enclave //</div><div>        myEnclave.create();</div><div><br></div><div>        // Run a function inside the enclave //</div><div>        myEnclave.execute(secureFunction);</div><div><br></div><div>        // Destroy the enclave //</div><div>        myEnclave.destroy();</div><div>    }</div><div>    catch (const hwsec::Exception&amp; e) {</div><div>        std::cerr &lt;&lt; &quot;HWSEC error: &quot; &lt;&lt; e.what() &lt;&lt; std::endl;</div><div>    }</div><div><br></div><div>    return 0;</div><div>}</div><div>```</div><div><br></div><div>## Future Directions</div><div><br></div><div>If accepted, future extensions to the `hwsec` namespace could include additional attributes, classes, and functions to support other hardware-level security features.</div><div><br></div><div>## Acknowledgments</div><div><br></div><div>Thanks to the members of the C++ community for their valuable insights and discussions that helped shape this proposal.</div><div><br></div><div>## References</div><div><br></div><div>[To be added]</div><br><br><div><br></div>
</div>-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" target="_blank" rel="noreferrer">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div></div></div>

