Skip to content

Commit

Permalink
Made crypto_tr_lift_x and crypto_tr_tagged_hash functions public
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Feb 29, 2024
1 parent 88ae13c commit 6a4df54
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void crypto_tr_tapleaf_hash_init(cx_sha256_t *hash_context) {
crypto_tr_tagged_hash_init(hash_context, BIP0341_tapleaf_tag, sizeof(BIP0341_tapleaf_tag));
}

static int crypto_tr_lift_x(const uint8_t x[static 32], uint8_t out[static 65]) {
int crypto_tr_lift_x(const uint8_t x[static 32], uint8_t out[static 65]) {
// save memory by reusing output buffer for intermediate results
uint8_t *y = out + 1 + 32;
// we use the memory for the x-coordinate of the output as a temporary variable
Expand Down Expand Up @@ -424,13 +424,13 @@ static int crypto_tr_lift_x(const uint8_t x[static 32], uint8_t out[static 65])

// Computes a tagged hash according to BIP-340.
// If data2_len > 0, then data2 must be non-NULL and the `data` and `data2` arrays are concatenated.
static void crypto_tr_tagged_hash(const uint8_t *tag,
uint16_t tag_len,
const uint8_t *data,
uint16_t data_len,
const uint8_t *data2,
uint16_t data2_len,
uint8_t out[static CX_SHA256_SIZE]) {
void crypto_tr_tagged_hash(const uint8_t *tag,
uint16_t tag_len,
const uint8_t *data,
uint16_t data_len,
const uint8_t *data2,
uint16_t data2_len,
uint8_t out[static CX_SHA256_SIZE]) {
// First compute hashtag, reuse out buffer for that
cx_sha256_hash(tag, tag_len, out);

Expand Down
37 changes: 37 additions & 0 deletions src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,43 @@ int crypto_ecdsa_sign_sha256_hash_with_key(const uint32_t bip32_path[],
*/
void crypto_tr_tagged_hash_init(cx_sha256_t *hash_context, const uint8_t *tag, uint16_t tag_len);

/**
* Implementation of the lift_x procedure as defined by BIP-0340.
*
* @param[in] x
* Pointer to a 32-byte array.
* @param[out] out
* Pointer to an array that will received the output as an uncompressed 65-bytes pubkey.
*/
int crypto_tr_lift_x(const uint8_t x[static 32], uint8_t out[static 65]);

/**
* A tagged hash as defined in BIP-0340.
*
* @param[in] tag
* Pointer to an array containing the tag of the tagged hash.
* @param[in] tag_len
* Length of the tag.
* @param[in] data
* Pointer to an array of data.
* @param[in] data_len
* Length of the array pointed by `data`.
* @param[in] data2
* If NULL, ignored. If not null, a pointer to an array of data; the tagged hash for the
* concatenation of `data` and `data2` is computed.
* @param[in] data2_len
* If `data2` is NULL, ignored. Otherwise, the length the array pointed by `data2`.
* @param[out] out
* Pointer to a 32-byte array that will receive the result.
*/
void crypto_tr_tagged_hash(const uint8_t *tag,
uint16_t tag_len,
const uint8_t *data,
uint16_t data_len,
const uint8_t *data2,
uint16_t data2_len,
uint8_t out[static CX_SHA256_SIZE]);

/**
* Initializes the "tagged" SHA256 hash with tag "TapLeaf", used for tapscript leaves.
*
Expand Down

0 comments on commit 6a4df54

Please sign in to comment.