summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2025-12-05 14:12:32 +0000
committertb <>2025-12-05 14:12:32 +0000
commitf3f05f0cf8c30a990193e332e26fdd8e54b3f59b (patch)
tree47450b6c993423a79d52c43b0bd9849c40035aa1
parentd604767b3782a7a003bea4677652538af9e3bd8e (diff)
downloadopenbsd-f3f05f0cf8c30a990193e332e26fdd8e54b3f59b.tar.gz
openbsd-f3f05f0cf8c30a990193e332e26fdd8e54b3f59b.tar.bz2
openbsd-f3f05f0cf8c30a990193e332e26fdd8e54b3f59b.zip
libcrypto: make most of the BN_* macro pollution internal
This is a first sweep of reducing the number of terribly named macros in bn.h More can go away. Those we need internally go to bn_local.h. Annoyingly bn_internal.h uses some of them, so it includes bn_local.h now. This can be cleaned up later. ok jsing kenjiro
-rw-r--r--src/lib/libcrypto/bn/bn.h27
-rw-r--r--src/lib/libcrypto/bn/bn_convert.c10
-rw-r--r--src/lib/libcrypto/bn/bn_internal.h3
-rw-r--r--src/lib/libcrypto/bn/bn_local.h16
-rw-r--r--src/lib/libcrypto/ec/ec_internal.h4
5 files changed, 29 insertions, 31 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index e64fcf355f..1ee1f1f1f8 100644
--- a/src/lib/libcrypto/bn/bn.h
+++ b/src/lib/libcrypto/bn/bn.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn.h,v 1.83 2025/11/07 13:41:40 jsing Exp $ */ 1/* $OpenBSD: bn.h,v 1.84 2025/12/05 14:12:32 tb Exp $ */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -143,43 +143,18 @@ extern "C" {
143#if defined(_LP64) || defined(_WIN64) 143#if defined(_LP64) || defined(_WIN64)
144#undef BN_LLONG 144#undef BN_LLONG
145#define BN_ULONG uint64_t 145#define BN_ULONG uint64_t
146#define BN_LONG int64_t
147#define BN_BITS 128
148#define BN_BYTES 8 146#define BN_BYTES 8
149#define BN_BITS2 64 147#define BN_BITS2 64
150#define BN_BITS4 32
151#define BN_MASK2 UINT64_C(0xffffffffffffffff)
152#define BN_MASK2l UINT64_C(0xffffffff)
153#define BN_MASK2h UINT64_C(0xffffffff00000000)
154#define BN_MASK2h1 UINT64_C(0xffffffff80000000)
155#define BN_TBIT UINT64_C(0x8000000000000000)
156#define BN_DEC_CONV UINT64_C(10000000000000000000)
157#define BN_DEC_FMT1 "%" PRIu64 148#define BN_DEC_FMT1 "%" PRIu64
158#define BN_DEC_FMT2 "%019" PRIu64
159#define BN_DEC_NUM 19
160#define BN_HEX_FMT1 "%" PRIX64 149#define BN_HEX_FMT1 "%" PRIX64
161#define BN_HEX_FMT2 "%016" PRIX64
162#else 150#else
163#define BN_ULLONG uint64_t 151#define BN_ULLONG uint64_t
164#define BN_LLONG 152#define BN_LLONG
165#define BN_ULONG uint32_t 153#define BN_ULONG uint32_t
166#define BN_LONG int32_t
167#define BN_BITS 64
168#define BN_BYTES 4 154#define BN_BYTES 4
169#define BN_BITS2 32 155#define BN_BITS2 32
170#define BN_BITS4 16
171#define BN_MASK UINT64_C(0xffffffffffffffff)
172#define BN_MASK2 UINT32_C(0xffffffff)
173#define BN_MASK2l UINT32_C(0xffff)
174#define BN_MASK2h1 UINT32_C(0xffff8000)
175#define BN_MASK2h UINT32_C(0xffff0000)
176#define BN_TBIT UINT32_C(0x80000000)
177#define BN_DEC_CONV UINT32_C(1000000000)
178#define BN_DEC_FMT1 "%" PRIu32 156#define BN_DEC_FMT1 "%" PRIu32
179#define BN_DEC_FMT2 "%09" PRIu32
180#define BN_DEC_NUM 9
181#define BN_HEX_FMT1 "%" PRIX32 157#define BN_HEX_FMT1 "%" PRIX32
182#define BN_HEX_FMT2 "%08" PRIX32
183#endif 158#endif
184 159
185#define BN_FLG_MALLOCED 0x01 160#define BN_FLG_MALLOCED 0x01
diff --git a/src/lib/libcrypto/bn/bn_convert.c b/src/lib/libcrypto/bn/bn_convert.c
index ca5c7d7865..ab5bc519c8 100644
--- a/src/lib/libcrypto/bn/bn_convert.c
+++ b/src/lib/libcrypto/bn/bn_convert.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_convert.c,v 1.24 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: bn_convert.c,v 1.25 2025/12/05 14:12:32 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -71,6 +71,14 @@
71#include "crypto_internal.h" 71#include "crypto_internal.h"
72#include "err_local.h" 72#include "err_local.h"
73 73
74#if BN_BYTES == 8
75#define BN_DEC_CONV UINT64_C(10000000000000000000)
76#define BN_DEC_NUM 19
77#else
78#define BN_DEC_CONV UINT32_C(1000000000)
79#define BN_DEC_NUM 9
80#endif
81
74static int bn_dec2bn_cbs(BIGNUM **bnp, CBS *cbs); 82static int bn_dec2bn_cbs(BIGNUM **bnp, CBS *cbs);
75static int bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs); 83static int bn_hex2bn_cbs(BIGNUM **bnp, CBS *cbs);
76 84
diff --git a/src/lib/libcrypto/bn/bn_internal.h b/src/lib/libcrypto/bn/bn_internal.h
index 8b5145e225..efe8202aa0 100644
--- a/src/lib/libcrypto/bn/bn_internal.h
+++ b/src/lib/libcrypto/bn/bn_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_internal.h,v 1.20 2025/08/02 16:20:00 jsing Exp $ */ 1/* $OpenBSD: bn_internal.h,v 1.21 2025/12/05 14:12:32 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -18,6 +18,7 @@
18#include <openssl/bn.h> 18#include <openssl/bn.h>
19 19
20#include "bn_arch.h" 20#include "bn_arch.h"
21#include "bn_local.h"
21 22
22#ifndef HEADER_BN_INTERNAL_H 23#ifndef HEADER_BN_INTERNAL_H
23#define HEADER_BN_INTERNAL_H 24#define HEADER_BN_INTERNAL_H
diff --git a/src/lib/libcrypto/bn/bn_local.h b/src/lib/libcrypto/bn/bn_local.h
index a7d61f1b03..106a2cdf2d 100644
--- a/src/lib/libcrypto/bn/bn_local.h
+++ b/src/lib/libcrypto/bn/bn_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_local.h,v 1.60 2025/09/07 05:21:29 jsing Exp $ */ 1/* $OpenBSD: bn_local.h,v 1.61 2025/12/05 14:12:32 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -116,6 +116,20 @@
116 116
117#include <openssl/bn.h> 117#include <openssl/bn.h>
118 118
119#if BN_BYTES == 8
120#define BN_MASK2 UINT64_C(0xffffffffffffffff)
121#define BN_MASK2l UINT64_C(0xffffffff)
122#define BN_MASK2h UINT64_C(0xffffffff00000000)
123#define BN_BITS 128
124#define BN_BITS4 32
125#else
126#define BN_MASK2 UINT32_C(0xffffffff)
127#define BN_MASK2l UINT32_C(0xffff)
128#define BN_MASK2h UINT32_C(0xffff0000)
129#define BN_BITS 64
130#define BN_BITS4 16
131#endif
132
119__BEGIN_HIDDEN_DECLS 133__BEGIN_HIDDEN_DECLS
120 134
121struct bignum_st { 135struct bignum_st {
diff --git a/src/lib/libcrypto/ec/ec_internal.h b/src/lib/libcrypto/ec/ec_internal.h
index 327d9ea94d..de0affa206 100644
--- a/src/lib/libcrypto/ec/ec_internal.h
+++ b/src/lib/libcrypto/ec/ec_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_internal.h,v 1.2 2025/08/02 15:44:09 jsing Exp $ */ 1/* $OpenBSD: ec_internal.h,v 1.3 2025/12/05 14:12:32 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -24,7 +24,7 @@
24#define EC_FIELD_ELEMENT_MAX_BYTES \ 24#define EC_FIELD_ELEMENT_MAX_BYTES \
25 (EC_FIELD_ELEMENT_MAX_BITS + 7) / 8 25 (EC_FIELD_ELEMENT_MAX_BITS + 7) / 8
26#define EC_FIELD_ELEMENT_MAX_WORDS \ 26#define EC_FIELD_ELEMENT_MAX_WORDS \
27 ((EC_FIELD_ELEMENT_MAX_BYTES + BN_BYTES - 1) / BN_BYTES) 27 ((EC_FIELD_ELEMENT_MAX_BYTES + sizeof(BN_ULONG) - 1) / sizeof(BN_ULONG))
28 28
29typedef struct { 29typedef struct {
30 BN_ULONG w[EC_FIELD_ELEMENT_MAX_WORDS]; 30 BN_ULONG w[EC_FIELD_ELEMENT_MAX_WORDS];