Skip to content

Commit fd86f99

Browse files
author
MarcoFalke
committed
Squashed 'src/secp256k1/' changes from 84973d393..0b7024185
0b7024185 Merge #474: Fix header guards using reserved identifiers ab1f89f00 Merge #478: Fixed multiple typos 8c7ea22d5 Fixed multiple typos abe2d3e84 Fix header guards using reserved identifiers f532bdc9f Merge #459: Add pubkey prefix constants to include/secp256k1.h cac7c5559 Merge #470: Fix wnaf_const documentation 768514bac Fix wnaf_const documentation with respect to return value and number of words set b8c26a399 Merge #458: Fix typo in API documentation 817fb2013 Merge #440: Fix typos 12230f90e Merge #468: Remove redundant conditional expression 2e1ccdca0 Remove redundant conditional expression bc61b91ac add pubkey prefix constants to include/secp256k1.h b0452e664 Fix typo in API documentation 4c0f32ed5 Fix typo: "Agressive" → "Aggressive" 73aca8364 Fix typo: "exectured" → "executed" git-subtree-dir: src/secp256k1 git-subtree-split: 0b7024185045a49a1a6a4c5615bf31c94f63d9c4
1 parent e7c1b44 commit fd86f99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+187
-178
lines changed

contrib/lax_der_parsing.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@
4848
* 8.3.1.
4949
*/
5050

51-
#ifndef _SECP256K1_CONTRIB_LAX_DER_PARSING_H_
52-
#define _SECP256K1_CONTRIB_LAX_DER_PARSING_H_
51+
#ifndef SECP256K1_CONTRIB_LAX_DER_PARSING_H
52+
#define SECP256K1_CONTRIB_LAX_DER_PARSING_H
5353

5454
#include <secp256k1.h>
5555

56-
# ifdef __cplusplus
56+
#ifdef __cplusplus
5757
extern "C" {
58-
# endif
58+
#endif
5959

6060
/** Parse a signature in "lax DER" format
6161
*
@@ -88,4 +88,4 @@ int ecdsa_signature_parse_der_lax(
8888
}
8989
#endif
9090

91-
#endif
91+
#endif /* SECP256K1_CONTRIB_LAX_DER_PARSING_H */

contrib/lax_der_privatekey_parsing.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
* library are sufficient.
2626
*/
2727

28-
#ifndef _SECP256K1_CONTRIB_BER_PRIVATEKEY_H_
29-
#define _SECP256K1_CONTRIB_BER_PRIVATEKEY_H_
28+
#ifndef SECP256K1_CONTRIB_BER_PRIVATEKEY_H
29+
#define SECP256K1_CONTRIB_BER_PRIVATEKEY_H
3030

3131
#include <secp256k1.h>
3232

33-
# ifdef __cplusplus
33+
#ifdef __cplusplus
3434
extern "C" {
35-
# endif
35+
#endif
3636

3737
/** Export a private key in DER format.
3838
*
@@ -87,4 +87,4 @@ SECP256K1_WARN_UNUSED_RESULT int ec_privkey_import_der(
8787
}
8888
#endif
8989

90-
#endif
90+
#endif /* SECP256K1_CONTRIB_BER_PRIVATEKEY_H */

include/secp256k1.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef _SECP256K1_
2-
# define _SECP256K1_
1+
#ifndef SECP256K1_H
2+
#define SECP256K1_H
33

4-
# ifdef __cplusplus
4+
#ifdef __cplusplus
55
extern "C" {
6-
# endif
6+
#endif
77

88
#include <stddef.h>
99

@@ -61,7 +61,7 @@ typedef struct {
6161
* however guaranteed to be 64 bytes in size, and can be safely copied/moved.
6262
* If you need to convert to a format suitable for storage, transmission, or
6363
* comparison, use the secp256k1_ecdsa_signature_serialize_* and
64-
* secp256k1_ecdsa_signature_serialize_* functions.
64+
* secp256k1_ecdsa_signature_parse_* functions.
6565
*/
6666
typedef struct {
6767
unsigned char data[64];
@@ -159,6 +159,13 @@ typedef int (*secp256k1_nonce_function)(
159159
#define SECP256K1_EC_COMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION | SECP256K1_FLAGS_BIT_COMPRESSION)
160160
#define SECP256K1_EC_UNCOMPRESSED (SECP256K1_FLAGS_TYPE_COMPRESSION)
161161

162+
/** Prefix byte used to tag various encoded curvepoints for specific purposes */
163+
#define SECP256K1_TAG_PUBKEY_EVEN 0x02
164+
#define SECP256K1_TAG_PUBKEY_ODD 0x03
165+
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED 0x04
166+
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN 0x06
167+
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD 0x07
168+
162169
/** Create a secp256k1 context object.
163170
*
164171
* Returns: a newly created context object.
@@ -607,8 +614,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(
607614
size_t n
608615
) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
609616

610-
# ifdef __cplusplus
617+
#ifdef __cplusplus
611618
}
612-
# endif
613-
614619
#endif
620+
621+
#endif /* SECP256K1_H */

include/secp256k1_ecdh.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef _SECP256K1_ECDH_
2-
# define _SECP256K1_ECDH_
1+
#ifndef SECP256K1_ECDH_H
2+
#define SECP256K1_ECDH_H
33

4-
# include "secp256k1.h"
4+
#include "secp256k1.h"
55

6-
# ifdef __cplusplus
6+
#ifdef __cplusplus
77
extern "C" {
8-
# endif
8+
#endif
99

1010
/** Compute an EC Diffie-Hellman secret in constant time
1111
* Returns: 1: exponentiation was successful
@@ -24,8 +24,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
2424
const unsigned char *privkey
2525
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
2626

27-
# ifdef __cplusplus
27+
#ifdef __cplusplus
2828
}
29-
# endif
30-
3129
#endif
30+
31+
#endif /* SECP256K1_ECDH_H */

include/secp256k1_recovery.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef _SECP256K1_RECOVERY_
2-
# define _SECP256K1_RECOVERY_
1+
#ifndef SECP256K1_RECOVERY_H
2+
#define SECP256K1_RECOVERY_H
33

4-
# include "secp256k1.h"
4+
#include "secp256k1.h"
55

6-
# ifdef __cplusplus
6+
#ifdef __cplusplus
77
extern "C" {
8-
# endif
8+
#endif
99

1010
/** Opaque data structured that holds a parsed ECDSA signature,
1111
* supporting pubkey recovery.
@@ -103,8 +103,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
103103
const unsigned char *msg32
104104
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
105105

106-
# ifdef __cplusplus
106+
#ifdef __cplusplus
107107
}
108-
# endif
109-
110108
#endif
109+
110+
#endif /* SECP256K1_RECOVERY_H */

sage/group_prover.sage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# to independently set assumptions on input or intermediary variables.
44
#
55
# The general approach is:
6-
# * A constraint is a tuple of two sets of of symbolic expressions:
6+
# * A constraint is a tuple of two sets of symbolic expressions:
77
# the first of which are required to evaluate to zero, the second of which
88
# are required to evaluate to nonzero.
99
# - A constraint is said to be conflicting if any of its nonzero expressions
@@ -17,7 +17,7 @@
1717
# - A constraint describing the requirements of the law, called "require"
1818
# * Implementations are transliterated into functions that operate as well on
1919
# algebraic input points, and are called once per combination of branches
20-
# exectured. Each execution returns:
20+
# executed. Each execution returns:
2121
# - A constraint describing the assumptions this implementation requires
2222
# (such as Z1=1), called "assumeFormula"
2323
# - A constraint describing the assumptions this specific branch requires,

src/asm/field_10x26_arm.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Note:
1111

1212
- To avoid unnecessary loads and make use of available registers, two
1313
'passes' have every time been interleaved, with the odd passes accumulating c' and d'
14-
which will be added to c and d respectively in the the even passes
14+
which will be added to c and d respectively in the even passes
1515

1616
*/
1717

@@ -23,7 +23,7 @@ Note:
2323
.eabi_attribute 10, 0 @ Tag_FP_arch = none
2424
.eabi_attribute 24, 1 @ Tag_ABI_align_needed = 8-byte
2525
.eabi_attribute 25, 1 @ Tag_ABI_align_preserved = 8-byte, except leaf SP
26-
.eabi_attribute 30, 2 @ Tag_ABI_optimization_goals = Agressive Speed
26+
.eabi_attribute 30, 2 @ Tag_ABI_optimization_goals = Aggressive Speed
2727
.eabi_attribute 34, 1 @ Tag_CPU_unaligned_access = v6
2828
.text
2929

src/basic-config.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_BASIC_CONFIG_
8-
#define _SECP256K1_BASIC_CONFIG_
7+
#ifndef SECP256K1_BASIC_CONFIG_H
8+
#define SECP256K1_BASIC_CONFIG_H
99

1010
#ifdef USE_BASIC_CONFIG
1111

@@ -28,5 +28,6 @@
2828
#define USE_FIELD_10X26 1
2929
#define USE_SCALAR_8X32 1
3030

31-
#endif // USE_BASIC_CONFIG
32-
#endif // _SECP256K1_BASIC_CONFIG_
31+
#endif /* USE_BASIC_CONFIG */
32+
33+
#endif /* SECP256K1_BASIC_CONFIG_H */

src/bench.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_BENCH_H_
8-
#define _SECP256K1_BENCH_H_
7+
#ifndef SECP256K1_BENCH_H
8+
#define SECP256K1_BENCH_H
99

1010
#include <stdio.h>
1111
#include <math.h>
@@ -63,4 +63,4 @@ void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), v
6363
printf("us\n");
6464
}
6565

66-
#endif
66+
#endif /* SECP256K1_BENCH_H */

src/ecdsa.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_ECDSA_
8-
#define _SECP256K1_ECDSA_
7+
#ifndef SECP256K1_ECDSA_H
8+
#define SECP256K1_ECDSA_H
99

1010
#include <stddef.h>
1111

@@ -18,4 +18,4 @@ static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const
1818
static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message);
1919
static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid);
2020

21-
#endif
21+
#endif /* SECP256K1_ECDSA_H */

src/ecdsa_impl.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
**********************************************************************/
66

77

8-
#ifndef _SECP256K1_ECDSA_IMPL_H_
9-
#define _SECP256K1_ECDSA_IMPL_H_
8+
#ifndef SECP256K1_ECDSA_IMPL_H
9+
#define SECP256K1_ECDSA_IMPL_H
1010

1111
#include "scalar.h"
1212
#include "field.h"
@@ -81,8 +81,6 @@ static int secp256k1_der_read_len(const unsigned char **sigp, const unsigned cha
8181
return -1;
8282
}
8383
while (lenleft > 0) {
84-
if ((ret >> ((sizeof(size_t) - 1) * 8)) != 0) {
85-
}
8684
ret = (ret << 8) | **sigp;
8785
if (ret + lenleft > (size_t)(sigend - *sigp)) {
8886
/* Result exceeds the length of the passed array. */
@@ -312,4 +310,4 @@ static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, sec
312310
return 1;
313311
}
314312

315-
#endif
313+
#endif /* SECP256K1_ECDSA_IMPL_H */

src/eckey.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_ECKEY_
8-
#define _SECP256K1_ECKEY_
7+
#ifndef SECP256K1_ECKEY_H
8+
#define SECP256K1_ECKEY_H
99

1010
#include <stddef.h>
1111

@@ -22,4 +22,4 @@ static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx,
2222
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak);
2323
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak);
2424

25-
#endif
25+
#endif /* SECP256K1_ECKEY_H */

src/eckey_impl.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_ECKEY_IMPL_H_
8-
#define _SECP256K1_ECKEY_IMPL_H_
7+
#ifndef SECP256K1_ECKEY_IMPL_H
8+
#define SECP256K1_ECKEY_IMPL_H
99

1010
#include "eckey.h"
1111

@@ -15,16 +15,17 @@
1515
#include "ecmult_gen.h"
1616

1717
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size) {
18-
if (size == 33 && (pub[0] == 0x02 || pub[0] == 0x03)) {
18+
if (size == 33 && (pub[0] == SECP256K1_TAG_PUBKEY_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_ODD)) {
1919
secp256k1_fe x;
20-
return secp256k1_fe_set_b32(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] == 0x03);
20+
return secp256k1_fe_set_b32(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] == SECP256K1_TAG_PUBKEY_ODD);
2121
} else if (size == 65 && (pub[0] == 0x04 || pub[0] == 0x06 || pub[0] == 0x07)) {
2222
secp256k1_fe x, y;
2323
if (!secp256k1_fe_set_b32(&x, pub+1) || !secp256k1_fe_set_b32(&y, pub+33)) {
2424
return 0;
2525
}
2626
secp256k1_ge_set_xy(elem, &x, &y);
27-
if ((pub[0] == 0x06 || pub[0] == 0x07) && secp256k1_fe_is_odd(&y) != (pub[0] == 0x07)) {
27+
if ((pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD) &&
28+
secp256k1_fe_is_odd(&y) != (pub[0] == SECP256K1_TAG_PUBKEY_HYBRID_ODD)) {
2829
return 0;
2930
}
3031
return secp256k1_ge_is_valid_var(elem);
@@ -42,10 +43,10 @@ static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *p
4243
secp256k1_fe_get_b32(&pub[1], &elem->x);
4344
if (compressed) {
4445
*size = 33;
45-
pub[0] = 0x02 | (secp256k1_fe_is_odd(&elem->y) ? 0x01 : 0x00);
46+
pub[0] = secp256k1_fe_is_odd(&elem->y) ? SECP256K1_TAG_PUBKEY_ODD : SECP256K1_TAG_PUBKEY_EVEN;
4647
} else {
4748
*size = 65;
48-
pub[0] = 0x04;
49+
pub[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED;
4950
secp256k1_fe_get_b32(&pub[33], &elem->y);
5051
}
5152
return 1;
@@ -96,4 +97,4 @@ static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx,
9697
return 1;
9798
}
9899

99-
#endif
100+
#endif /* SECP256K1_ECKEY_IMPL_H */

src/ecmult.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_ECMULT_
8-
#define _SECP256K1_ECMULT_
7+
#ifndef SECP256K1_ECMULT_H
8+
#define SECP256K1_ECMULT_H
99

1010
#include "num.h"
1111
#include "group.h"
@@ -28,4 +28,4 @@ static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx
2828
/** Double multiply: R = na*A + ng*G */
2929
static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);
3030

31-
#endif
31+
#endif /* SECP256K1_ECMULT_H */

src/ecmult_const.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
66

7-
#ifndef _SECP256K1_ECMULT_CONST_
8-
#define _SECP256K1_ECMULT_CONST_
7+
#ifndef SECP256K1_ECMULT_CONST_H
8+
#define SECP256K1_ECMULT_CONST_H
99

1010
#include "scalar.h"
1111
#include "group.h"
1212

1313
static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q);
1414

15-
#endif
15+
#endif /* SECP256K1_ECMULT_CONST_H */

0 commit comments

Comments
 (0)