Skip to content

Commit 7e3952a

Browse files
committed
Clarify documentation of tweak functions.
In particular, mention that the functions return 0 if seckey or tweak are invalid (as opposed to saying "should" or "must" be valid).
1 parent 89853a0 commit 7e3952a

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

include/secp256k1.h

+46-41
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,12 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(
586586
*
587587
* Returns: 0 if the given secret key is invalid according to
588588
* secp256k1_ec_seckey_verify. 1 otherwise
589-
* Args: ctx: pointer to a context object
590-
* In/Out: seckey: pointer to the 32-byte secret key to be negated. The secret
591-
* key should be valid according to secp256k1_ec_seckey_verify.
592-
* If this function returns 0, seckey will be some
593-
* unspecified value. (cannot be NULL)
589+
* Args: ctx: pointer to a context object
590+
* In/Out: seckey: pointer to the 32-byte secret key to be negated. If the
591+
* secret key is invalid according to
592+
* secp256k1_ec_seckey_verify, this function returns 0 and
593+
* seckey will be set to some unspecified value. (cannot be
594+
* NULL)
594595
*/
595596
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_negate(
596597
const secp256k1_context* ctx,
@@ -617,17 +618,18 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_negate(
617618

618619
/** Tweak a secret key by adding tweak to it.
619620
*
620-
* Returns: 0 if the resulting secret key would be invalid (only when the tweak
621-
* is the negation of the secret key). 1 otherwise.
622-
* Args: ctx: pointer to a context object (cannot be NULL).
623-
* In/Out: seckey: pointer to a 32-byte secret key. The secret key should be
624-
* valid according to secp256k1_ec_seckey_verify. If this
625-
* function returns 0, seckey will be some unspecified
626-
* value. (cannot be NULL)
627-
* In: tweak: pointer to a 32-byte tweak. Must be in the same range as secret
628-
* keys (see secp256k1_ec_seckey_verify). For uniformly random
629-
* 32-byte arrays the chance of being out of range is
630-
* negligible (around 1 in 2^128). (cannot be NULL)
621+
* Returns: 0 if the arguments are invalid or the resulting secret key would be
622+
* invalid (only when the tweak is the negation of the secret key). 1
623+
* otherwise.
624+
* Args: ctx: pointer to a context object (cannot be NULL).
625+
* In/Out: seckey: pointer to a 32-byte secret key. If the secret key is
626+
* invalid according to secp256k1_ec_seckey_verify, this
627+
* function returns 0. seckey will be set to some unspecified
628+
* value if this function returns 0. (cannot be NULL)
629+
* In: tweak: pointer to a 32-byte tweak. If the tweak is invalid according to
630+
* secp256k1_ec_seckey_verify, this function returns 0. For
631+
* uniformly random 32-byte arrays the chance of being invalid
632+
* is negligible (around 1 in 2^128) (cannot be NULL).
631633
*/
632634
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_add(
633635
const secp256k1_context* ctx,
@@ -645,16 +647,17 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_add(
645647

646648
/** Tweak a public key by adding tweak times the generator to it.
647649
*
648-
* Returns: 0 if the resulting public key would be invalid (only when the tweak
649-
* is the negation of the corresponding secret key). 1 otherwise.
650-
* Args: ctx: pointer to a context object initialized for validation
651-
* (cannot be NULL).
652-
* In/Out: pubkey: pointer to a public key object. If this function returns 0,
653-
* pubkey will be invalid. (cannot be NULL).
654-
* In: tweak: pointer to a 32-byte tweak. Must be in the same range as secret
655-
* keys (see secp256k1_ec_seckey_verify). For uniformly random
656-
* 32-byte arrays the chance of being out of range is
657-
* negligible (around 1 in 2^128). (cannot be NULL)
650+
* Returns: 0 if the arguments are invalid or the resulting public key would be
651+
* invalid (only when the tweak is the negation of the corresponding
652+
* secret key). 1 otherwise.
653+
* Args: ctx: pointer to a context object initialized for validation
654+
* (cannot be NULL).
655+
* In/Out: pubkey: pointer to a public key object. pubkey will be set to an
656+
* invalid value if this function returns 0 (cannot be NULL).
657+
* In: tweak: pointer to a 32-byte tweak. If the tweak is invalid according to
658+
* secp256k1_ec_seckey_verify, this function returns 0. For
659+
* uniformly random 32-byte arrays the chance of being invalid
660+
* is negligible (around 1 in 2^128) (cannot be NULL).
658661
*/
659662
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
660663
const secp256k1_context* ctx,
@@ -664,14 +667,16 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_add(
664667

665668
/** Tweak a secret key by multiplying it by a tweak.
666669
*
667-
* Returns: 0 if the arguments are invalid.. 1 otherwise.
670+
* Returns: 0 if the arguments are invalid. 1 otherwise.
668671
* Args: ctx: pointer to a context object (cannot be NULL).
669-
* In/Out: seckey: pointer to a 32-byte secret key. If this function returns 0,
670-
* seckey will be some unspecified value. (cannot be NULL).
671-
* In: tweak: pointer to a 32-byte tweak. Must be in the same range as secret
672-
* keys (see secp256k1_ec_seckey_verify). For uniformly random
673-
* 32-byte arrays the chance of being out of range is
674-
* negligible (around 1 in 2^128). (cannot be NULL)
672+
* In/Out: seckey: pointer to a 32-byte secret key. If the secret key is
673+
* invalid according to secp256k1_ec_seckey_verify, this
674+
* function returns 0. seckey will be set to some unspecified
675+
* value if this function returns 0. (cannot be NULL)
676+
* In: tweak: pointer to a 32-byte tweak. If the tweak is invalid according to
677+
* secp256k1_ec_seckey_verify, this function returns 0. For
678+
* uniformly random 32-byte arrays the chance of being invalid
679+
* is negligible (around 1 in 2^128) (cannot be NULL).
675680
*/
676681
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_tweak_mul(
677682
const secp256k1_context* ctx,
@@ -690,14 +695,14 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_privkey_tweak_mul(
690695
/** Tweak a public key by multiplying it by a tweak value.
691696
*
692697
* Returns: 0 if the arguments are invalid. 1 otherwise.
693-
* Args: ctx: pointer to a context object initialized for validation
694-
* (cannot be NULL).
695-
* In/Out: pubkey: pointer to a public key object. If this function returns 0,
696-
* pubkey will be invalid. (cannot be NULL).
697-
* In: tweak: pointer to a 32-byte tweak. Must be in the same range as secret
698-
* keys (see secp256k1_ec_seckey_verify). For uniformly random
699-
* 32-byte arrays the chance of being out of range is
700-
* negligible (around 1 in 2^128). (cannot be NULL)
698+
* Args: ctx: pointer to a context object initialized for validation
699+
* (cannot be NULL).
700+
* In/Out: pubkey: pointer to a public key object. pubkey will be set to an
701+
* invalid value if this function returns 0 (cannot be NULL).
702+
* In: tweak: pointer to a 32-byte tweak. If the tweak is invalid according to
703+
* secp256k1_ec_seckey_verify, this function returns 0. For
704+
* uniformly random 32-byte arrays the chance of being invalid
705+
* is negligible (around 1 in 2^128) (cannot be NULL).
701706
*/
702707
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_tweak_mul(
703708
const secp256k1_context* ctx,

0 commit comments

Comments
 (0)