|
| 1 | +#ifndef SECP256K1_ECDSA_ANTI_COVERT_CHANNEL_H |
| 2 | +#define SECP256K1_ECDSA_ANTI_COVERT_CHANNEL_H |
| 3 | + |
| 4 | +#include "secp256k1.h" |
| 5 | + |
| 6 | +#ifdef __cplusplus |
| 7 | +extern "C" { |
| 8 | +#endif |
| 9 | + |
| 10 | +/** Same as secp256k1_ecdsa_sign, but s2c_data32 is committed to by adding `hash(R1, s2c_data32)` to |
| 11 | + * the nonce generated by noncefp, with `ndata=hash(s2c_data32, ndata)`. |
| 12 | + * In: |
| 13 | + * s2c_opening: pointer to an secp256k1_s2c_opening structure which can be |
| 14 | + * NULL but is required to be not NULL if this signature creates |
| 15 | + * a sign-to-contract commitment (i.e. the `s2c_data` argument |
| 16 | + * is not NULL). nonce_is_negated is always 0 for ecdsa. |
| 17 | + */ |
| 18 | +SECP256K1_API int secp256k1_ecdsa_s2c_sign( |
| 19 | + const secp256k1_context* ctx, |
| 20 | + secp256k1_ecdsa_signature *sig, |
| 21 | + secp256k1_s2c_opening *s2c_opening, |
| 22 | + const unsigned char *msg32, |
| 23 | + const unsigned char *seckey, |
| 24 | + secp256k1_nonce_function noncefp, |
| 25 | + const void *ndata, |
| 26 | + const unsigned char* s2c_data32 |
| 27 | +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); |
| 28 | + |
| 29 | +/** Verify a sign-to-contract commitment. |
| 30 | + * |
| 31 | + * Returns: 1: the signature contains a commitment to data32 |
| 32 | + * 0: incorrect opening |
| 33 | + * Args: ctx: a secp256k1 context object, initialized for verification. |
| 34 | + * In: sig: the signature containing the sign-to-contract commitment (cannot be NULL) |
| 35 | + * data32: the 32-byte data that was committed to (cannot be NULL) |
| 36 | + * opening: pointer to the opening created during signing (cannot be NULL) |
| 37 | + */ |
| 38 | +SECP256K1_API int secp256k1_ecdsa_s2c_verify_commit( |
| 39 | + const secp256k1_context* ctx, |
| 40 | + const secp256k1_ecdsa_signature *sig, |
| 41 | + const unsigned char *data32, |
| 42 | + const secp256k1_s2c_opening *opening |
| 43 | +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); |
| 44 | + |
| 45 | +/** Compute commitment on the client as part of the ECDSA Anti Nonce Covert Channel Protocol. |
| 46 | + * |
| 47 | + * ECDSA Anti Nonce Covert Channel Protocol: |
| 48 | + * 1. The host draws randomness `k2`, commits to it with sha256 and sends the commitment to the client. |
| 49 | + * 2. The client commits to its original nonce `k1` using the host commitment by calling |
| 50 | + * `secp256k1_ecdsa_anti_covert_channel_client_commit`. The client sends the resulting commitment |
| 51 | + * `R1` to the host. |
| 52 | + * 3. The host replies with `k2` generated in step 1. |
| 53 | + * 4. The client signs with `secp256k1_ecdsa_s2c_sign`, using the `k2` as `s2c_data` and |
| 54 | + * sends the signature and opening to the host. |
| 55 | + * 5. The host verifies that `R_x = (R1 + H(R1, k2)*G)_x`, where R_x is the `r` part of the signature by using |
| 56 | + * `secp256k1_ecdsa_s2c_anti_nonce_covert_channel_host_verify` with the client's |
| 57 | + * commitment from step 2 and the signature and opening received in step 4. If verification does |
| 58 | + * not succeed, the protocol failed and can be restarted. |
| 59 | + * |
| 60 | + * Returns 1 on success, 0 on failure. |
| 61 | + * Args: ctx: pointer to a context object (cannot be NULL) |
| 62 | + * Out: client_commit: pointer to a pubkey where the clients public nonce will be |
| 63 | + * placed. (cannot be NULL) |
| 64 | + * In: msg32: the 32-byte message hash to be signed (cannot be NULL) |
| 65 | + * seckey32: the 32-byte secret key used for signing (cannot be NULL) |
| 66 | + * noncefp: pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used |
| 67 | + * rand_commitment32: the 32-byte randomness commitment from the host (cannot be NULL) |
| 68 | + */ |
| 69 | +SECP256K1_API int secp256k1_ecdsa_s2c_anti_nonce_covert_channel_client_commit( |
| 70 | + const secp256k1_context* ctx, |
| 71 | + secp256k1_pubkey *client_commit, |
| 72 | + const unsigned char *msg32, |
| 73 | + const unsigned char *seckey32, |
| 74 | + unsigned char *rand_commitment32 |
| 75 | +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); |
| 76 | + |
| 77 | +/** Create a randomness commitment on the host as part of the ECDSA Anti Nonce Covert Channel Protocol. |
| 78 | + * |
| 79 | + * Returns 1 on success, 0 on failure. |
| 80 | + * Args: ctx: pointer to a context object (cannot be NULL) |
| 81 | + * Out: rand_commitment32: pointer to 32-byte array to store the returned commitment (cannot be NULL) |
| 82 | + * In: rand32: the 32-byte randomness to commit to (cannot be NULL) |
| 83 | + */ |
| 84 | +SECP256K1_API int secp256k1_ecdsa_s2c_anti_nonce_covert_channel_host_commit( |
| 85 | + secp256k1_context *ctx, |
| 86 | + unsigned char *rand_commitment32, |
| 87 | + const unsigned char *rand32 |
| 88 | +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); |
| 89 | + |
| 90 | +/** Verify that a clients signature contains the hosts randomness as part of the Anti |
| 91 | + * Nonce Covert Channel Protocol. Does not verify the signature itself. |
| 92 | + * |
| 93 | + * Returns 1 on success, 0 on failure. |
| 94 | + * Args: ctx: pointer to a context object (cannot be NULL) |
| 95 | + * In: sig: pointer to the signature whose randomness should be verified |
| 96 | + * (cannot be NULL) |
| 97 | + * rand32: pointer to the 32-byte randomness from the host which should |
| 98 | + * be included by the signature (cannot be NULL) |
| 99 | + * opening: pointer to the opening produced by the client when signing |
| 100 | + * with `rand32` as `s2c_data` (cannot be NULL) |
| 101 | + * client_commit: pointer to the client's commitment created in |
| 102 | + * `secp256k1_ecdsa_s2c_anti_nonce_covert_channel_client_commit` |
| 103 | + * (cannot be NULL) |
| 104 | + */ |
| 105 | +SECP256K1_API int secp256k1_ecdsa_s2c_anti_nonce_covert_channel_host_verify( |
| 106 | + secp256k1_context *ctx, |
| 107 | + const secp256k1_ecdsa_signature *sig, |
| 108 | + const unsigned char *rand32, |
| 109 | + const secp256k1_s2c_opening *opening, |
| 110 | + const secp256k1_pubkey *client_commit |
| 111 | +) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5); |
| 112 | + |
| 113 | +#ifdef __cplusplus |
| 114 | +} |
| 115 | +#endif |
| 116 | + |
| 117 | +#endif /* SECP256K1_RECOVERY_H */ |
0 commit comments