summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2025-11-05 13:00:26 +0000
committerjsing <>2025-11-05 13:00:26 +0000
commitcfaf7540f6b19032df0f388ad6a4d0e0714671c6 (patch)
tree30197867ef8aab2348202fd9d377ba981fe153f6
parentb3e89c37e576543ed212191b5769371e3ce58e95 (diff)
downloadopenbsd-cfaf7540f6b19032df0f388ad6a4d0e0714671c6.tar.gz
openbsd-cfaf7540f6b19032df0f388ad6a4d0e0714671c6.tar.bz2
openbsd-cfaf7540f6b19032df0f388ad6a4d0e0714671c6.zip
Use more specific types for BN.
Be specific about width and use uint64_t/uint32_t, rather than using unsigned int/long/long long, based on platform. Additionally use UINT64_C() and UINT32_C() for constants, along with PRI*64/PRI*32 for formatting. This makes the platform responsible for providing the correct types/defines - all we then need to do is determine is if BN should use a 32 bit or 64 bit configuration. With input from and ok tb@
-rw-r--r--src/lib/libcrypto/bn/bn.h56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index f222e9e178..7c98d4e853 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.81 2025/09/07 06:28:03 jsing Exp $ */ 1/* $OpenBSD: bn.h,v 1.82 2025/11/05 13:00:26 jsing 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 *
@@ -125,6 +125,8 @@
125#ifndef HEADER_BN_H 125#ifndef HEADER_BN_H
126#define HEADER_BN_H 126#define HEADER_BN_H
127 127
128#include <inttypes.h>
129#include <stdint.h>
128#include <stdio.h> 130#include <stdio.h>
129#include <stdlib.h> 131#include <stdlib.h>
130 132
@@ -140,44 +142,44 @@ extern "C" {
140 142
141#ifdef _LP64 143#ifdef _LP64
142#undef BN_LLONG 144#undef BN_LLONG
143#define BN_ULONG unsigned long 145#define BN_ULONG uint64_t
144#define BN_LONG long 146#define BN_LONG int64_t
145#define BN_BITS 128 147#define BN_BITS 128
146#define BN_BYTES 8 148#define BN_BYTES 8
147#define BN_BITS2 64 149#define BN_BITS2 64
148#define BN_BITS4 32 150#define BN_BITS4 32
149#define BN_MASK2 (0xffffffffffffffffL) 151#define BN_MASK2 UINT64_C(0xffffffffffffffff)
150#define BN_MASK2l (0xffffffffL) 152#define BN_MASK2l UINT64_C(0xffffffff)
151#define BN_MASK2h (0xffffffff00000000L) 153#define BN_MASK2h UINT64_C(0xffffffff00000000)
152#define BN_MASK2h1 (0xffffffff80000000L) 154#define BN_MASK2h1 UINT64_C(0xffffffff80000000)
153#define BN_TBIT (0x8000000000000000L) 155#define BN_TBIT UINT64_C(0x8000000000000000)
154#define BN_DEC_CONV (10000000000000000000UL) 156#define BN_DEC_CONV UINT64_C(10000000000000000000)
155#define BN_DEC_FMT1 "%lu" 157#define BN_DEC_FMT1 "%" PRIu64
156#define BN_DEC_FMT2 "%019lu" 158#define BN_DEC_FMT2 "%019" PRIu64
157#define BN_DEC_NUM 19 159#define BN_DEC_NUM 19
158#define BN_HEX_FMT1 "%lX" 160#define BN_HEX_FMT1 "%" PRIX64
159#define BN_HEX_FMT2 "%016lX" 161#define BN_HEX_FMT2 "%016" PRIX64
160#else 162#else
161#define BN_ULLONG unsigned long long 163#define BN_ULLONG uint64_t
162#define BN_LLONG 164#define BN_LLONG
163#define BN_ULONG unsigned int 165#define BN_ULONG uint32_t
164#define BN_LONG int 166#define BN_LONG int32_t
165#define BN_BITS 64 167#define BN_BITS 64
166#define BN_BYTES 4 168#define BN_BYTES 4
167#define BN_BITS2 32 169#define BN_BITS2 32
168#define BN_BITS4 16 170#define BN_BITS4 16
169#define BN_MASK (0xffffffffffffffffLL) 171#define BN_MASK UINT64_C(0xffffffffffffffff)
170#define BN_MASK2 (0xffffffffL) 172#define BN_MASK2 UINT32_C(0xffffffff)
171#define BN_MASK2l (0xffff) 173#define BN_MASK2l UINT32_C(0xffff)
172#define BN_MASK2h1 (0xffff8000L) 174#define BN_MASK2h1 UINT32_C(0xffff8000)
173#define BN_MASK2h (0xffff0000L) 175#define BN_MASK2h UINT32_C(0xffff0000)
174#define BN_TBIT (0x80000000L) 176#define BN_TBIT UINT32_C(0x80000000)
175#define BN_DEC_CONV (1000000000L) 177#define BN_DEC_CONV UINT32_C(1000000000)
176#define BN_DEC_FMT1 "%u" 178#define BN_DEC_FMT1 "%" PRIu32
177#define BN_DEC_FMT2 "%09u" 179#define BN_DEC_FMT2 "%09" PRIu32
178#define BN_DEC_NUM 9 180#define BN_DEC_NUM 9
179#define BN_HEX_FMT1 "%X" 181#define BN_HEX_FMT1 "%" PRIX32
180#define BN_HEX_FMT2 "%08X" 182#define BN_HEX_FMT2 "%08" PRIX32
181#endif 183#endif
182 184
183#define BN_FLG_MALLOCED 0x01 185#define BN_FLG_MALLOCED 0x01