-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Note
If this proposal is accepted, the changes will need to be implemented in both Clevis and José, not here, but since this pertains to Tang, I think it makes sense to discuss it here first. Feel free to transfer this issue to another repository if appropriate.
Background
I'm currently working on implementing a Tang-compatible server whose private key is secured on Apple's Secure Enclave. The idea is that Tang will run on an iOS device, and you won't be able to extract the private keys from it. But the platform is not really relevant here, and everything I'll say below applies to a VM that uses AWS KMS to store the private keys or a bare-metal server with a YubiKey connected to it.
Problem
I hit a roadblock where most, if not all, APIs of secure elements only allow you to perform ECDH with compact output (i.e. only the X coordinate is returned and the Y coordinate is discarded), but ECMR needs both coordinates to work. No API for elliptic curve arithmetic exists to get the raw result of the multiplication of the remote public key by the local private key. And you clearly can't do the multiplication yourself since you don't have access to the key material.
Solution
Disclaimer, I'm no math expert and Copilot was the one who came up with the idea. But I validated it and it seems like a really good solution. It definitely works.
Since the compact output of ECDH is the X coordinate, and we know the elliptic curve, we can calculate the two possible values of Y that, together with X, result in a point on the curve by solving y² = x³ + ax + b (mod p). But since the value of Y matters for the ECMR algorithm, we need to know which one to return to the client on the recovery request.
The solution proposed was to add a hint to the payload sent to Tang by Clevis that will tell the server to either return the value of Y that is odd or the one that is even. Apparently, it is a property of elliptic curves with odd moduli, which all cryptographic curves are because their modulus is prime, that both possible values of Y for some X in the curve have different parity.
So, José would check if the Y value obtained during the ECMR provisioning process in the ECDH key exchange is odd or even, and return that to Clevis along with the encrypted data. Clevis would store that value, which would later be sent to Tang. Finally, Tang would compute the value of X and determine the two values of Y, returning the correct one based on the hint provided in the request.
This perfectly addresses the issue and is 100% retrocompatible with the existing implementation. Tang code wouldn't even need to change, as the extra JSON field will simply be ignored. José and Clevis will require patches, but small ones.
TL;DR
I'm proposing that José tell Clevis whether the Y coordinate of the point resulting from the ECHD key exchange during provisioning is odd or even, and that Clevis store that information and later forward it to Tang so it can perform all cryptographic operations of ECMR on a secure element, such as a Smart Card.