summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_lib.c
diff options
context:
space:
mode:
authorbeck <>2023-07-08 12:21:58 +0000
committerbeck <>2023-07-08 12:21:58 +0000
commit4fff81a3a2e2fb3d68e73e2fcc951cee3548c554 (patch)
tree789e1276988198ecf8411c8f5bb376e2ea404f91 /src/lib/libcrypto/bn/bn_lib.c
parentde1ea0d71a59536dfa9a5b0b755c13d3d6eddbeb (diff)
downloadopenbsd-4fff81a3a2e2fb3d68e73e2fcc951cee3548c554.tar.gz
openbsd-4fff81a3a2e2fb3d68e73e2fcc951cee3548c554.tar.bz2
openbsd-4fff81a3a2e2fb3d68e73e2fcc951cee3548c554.zip
Hide symbols in bn
ok tb@
Diffstat (limited to 'src/lib/libcrypto/bn/bn_lib.c')
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index bac0290efa..74359dab37 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.88 2023/06/21 07:48:41 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.89 2023/07/08 12:21:58 beck 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 *
@@ -81,6 +81,7 @@ BN_new(void)
81 81
82 return bn; 82 return bn;
83} 83}
84LCRYPTO_ALIAS(BN_new);
84 85
85void 86void
86BN_init(BIGNUM *a) 87BN_init(BIGNUM *a)
@@ -96,6 +97,7 @@ BN_clear(BIGNUM *a)
96 a->top = 0; 97 a->top = 0;
97 a->neg = 0; 98 a->neg = 0;
98} 99}
100LCRYPTO_ALIAS(BN_clear);
99 101
100void 102void
101BN_free(BIGNUM *bn) 103BN_free(BIGNUM *bn)
@@ -113,24 +115,28 @@ BN_free(BIGNUM *bn)
113 115
114 freezero(bn, sizeof(*bn)); 116 freezero(bn, sizeof(*bn));
115} 117}
118LCRYPTO_ALIAS(BN_free);
116 119
117void 120void
118BN_clear_free(BIGNUM *bn) 121BN_clear_free(BIGNUM *bn)
119{ 122{
120 BN_free(bn); 123 BN_free(bn);
121} 124}
125LCRYPTO_ALIAS(BN_clear_free);
122 126
123void 127void
124BN_set_flags(BIGNUM *b, int n) 128BN_set_flags(BIGNUM *b, int n)
125{ 129{
126 b->flags |= n; 130 b->flags |= n;
127} 131}
132LCRYPTO_ALIAS(BN_set_flags);
128 133
129int 134int
130BN_get_flags(const BIGNUM *b, int n) 135BN_get_flags(const BIGNUM *b, int n)
131{ 136{
132 return b->flags & n; 137 return b->flags & n;
133} 138}
139LCRYPTO_ALIAS(BN_get_flags);
134 140
135void 141void
136BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags) 142BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)
@@ -143,6 +149,7 @@ BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)
143 *dest = *b; 149 *dest = *b;
144 dest->flags = dest_flags; 150 dest->flags = dest_flags;
145} 151}
152LCRYPTO_ALIAS(BN_with_flags);
146 153
147static const BN_ULONG bn_value_one_data = 1; 154static const BN_ULONG bn_value_one_data = 1;
148static const BIGNUM bn_value_one = { 155static const BIGNUM bn_value_one = {
@@ -158,18 +165,21 @@ BN_value_one(void)
158{ 165{
159 return &bn_value_one; 166 return &bn_value_one;
160} 167}
168LCRYPTO_ALIAS(BN_value_one);
161 169
162int 170int
163BN_num_bits_word(BN_ULONG w) 171BN_num_bits_word(BN_ULONG w)
164{ 172{
165 return BN_BITS2 - bn_clzw(w); 173 return BN_BITS2 - bn_clzw(w);
166} 174}
175LCRYPTO_ALIAS(BN_num_bits_word);
167 176
168int 177int
169BN_num_bits(const BIGNUM *bn) 178BN_num_bits(const BIGNUM *bn)
170{ 179{
171 return bn_bitsize(bn); 180 return bn_bitsize(bn);
172} 181}
182LCRYPTO_ALIAS(BN_num_bits);
173 183
174void 184void
175bn_correct_top(BIGNUM *a) 185bn_correct_top(BIGNUM *a)
@@ -253,6 +263,7 @@ BN_dup(const BIGNUM *a)
253 } 263 }
254 return t; 264 return t;
255} 265}
266LCRYPTO_ALIAS(BN_dup);
256 267
257static inline void 268static inline void
258bn_copy_words(BN_ULONG *ap, const BN_ULONG *bp, int n) 269bn_copy_words(BN_ULONG *ap, const BN_ULONG *bp, int n)
@@ -284,6 +295,7 @@ BN_copy(BIGNUM *a, const BIGNUM *b)
284 295
285 return (a); 296 return (a);
286} 297}
298LCRYPTO_ALIAS(BN_copy);
287 299
288int 300int
289bn_copy(BIGNUM *dst, const BIGNUM *src) 301bn_copy(BIGNUM *dst, const BIGNUM *src)
@@ -322,6 +334,7 @@ BN_swap(BIGNUM *a, BIGNUM *b)
322 b->flags = (flags_old_b & BN_FLG_MALLOCED) | 334 b->flags = (flags_old_b & BN_FLG_MALLOCED) |
323 (flags_old_a & BN_FLG_STATIC_DATA); 335 (flags_old_a & BN_FLG_STATIC_DATA);
324} 336}
337LCRYPTO_ALIAS(BN_swap);
325 338
326BN_ULONG 339BN_ULONG
327BN_get_word(const BIGNUM *a) 340BN_get_word(const BIGNUM *a)
@@ -333,6 +346,7 @@ BN_get_word(const BIGNUM *a)
333 /* a->top == 0 */ 346 /* a->top == 0 */
334 return 0; 347 return 0;
335} 348}
349LCRYPTO_ALIAS(BN_get_word);
336 350
337int 351int
338BN_set_word(BIGNUM *a, BN_ULONG w) 352BN_set_word(BIGNUM *a, BN_ULONG w)
@@ -344,6 +358,7 @@ BN_set_word(BIGNUM *a, BN_ULONG w)
344 a->top = (w ? 1 : 0); 358 a->top = (w ? 1 : 0);
345 return (1); 359 return (1);
346} 360}
361LCRYPTO_ALIAS(BN_set_word);
347 362
348int 363int
349BN_ucmp(const BIGNUM *a, const BIGNUM *b) 364BN_ucmp(const BIGNUM *a, const BIGNUM *b)
@@ -362,6 +377,7 @@ BN_ucmp(const BIGNUM *a, const BIGNUM *b)
362 377
363 return 0; 378 return 0;
364} 379}
380LCRYPTO_ALIAS(BN_ucmp);
365 381
366int 382int
367BN_cmp(const BIGNUM *a, const BIGNUM *b) 383BN_cmp(const BIGNUM *a, const BIGNUM *b)
@@ -382,6 +398,7 @@ BN_cmp(const BIGNUM *a, const BIGNUM *b)
382 398
383 return BN_ucmp(a, b); 399 return BN_ucmp(a, b);
384} 400}
401LCRYPTO_ALIAS(BN_cmp);
385 402
386int 403int
387BN_set_bit(BIGNUM *a, int n) 404BN_set_bit(BIGNUM *a, int n)
@@ -404,6 +421,7 @@ BN_set_bit(BIGNUM *a, int n)
404 a->d[i] |= (((BN_ULONG)1) << j); 421 a->d[i] |= (((BN_ULONG)1) << j);
405 return (1); 422 return (1);
406} 423}
424LCRYPTO_ALIAS(BN_set_bit);
407 425
408int 426int
409BN_clear_bit(BIGNUM *a, int n) 427BN_clear_bit(BIGNUM *a, int n)
@@ -422,6 +440,7 @@ BN_clear_bit(BIGNUM *a, int n)
422 bn_correct_top(a); 440 bn_correct_top(a);
423 return (1); 441 return (1);
424} 442}
443LCRYPTO_ALIAS(BN_clear_bit);
425 444
426int 445int
427BN_is_bit_set(const BIGNUM *a, int n) 446BN_is_bit_set(const BIGNUM *a, int n)
@@ -436,6 +455,7 @@ BN_is_bit_set(const BIGNUM *a, int n)
436 return 0; 455 return 0;
437 return (int)(((a->d[i]) >> j) & ((BN_ULONG)1)); 456 return (int)(((a->d[i]) >> j) & ((BN_ULONG)1));
438} 457}
458LCRYPTO_ALIAS(BN_is_bit_set);
439 459
440int 460int
441BN_mask_bits(BIGNUM *a, int n) 461BN_mask_bits(BIGNUM *a, int n)
@@ -458,12 +478,14 @@ BN_mask_bits(BIGNUM *a, int n)
458 bn_correct_top(a); 478 bn_correct_top(a);
459 return (1); 479 return (1);
460} 480}
481LCRYPTO_ALIAS(BN_mask_bits);
461 482
462void 483void
463BN_set_negative(BIGNUM *bn, int neg) 484BN_set_negative(BIGNUM *bn, int neg)
464{ 485{
465 bn->neg = ~BN_is_zero(bn) & bn_ct_ne_zero(neg); 486 bn->neg = ~BN_is_zero(bn) & bn_ct_ne_zero(neg);
466} 487}
488LCRYPTO_ALIAS(BN_set_negative);
467 489
468/* 490/*
469 * Constant-time conditional swap of a and b. 491 * Constant-time conditional swap of a and b.
@@ -517,6 +539,7 @@ BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
517 } 539 }
518#undef BN_CONSTTIME_SWAP 540#undef BN_CONSTTIME_SWAP
519} 541}
542LCRYPTO_ALIAS(BN_consttime_swap);
520 543
521/* 544/*
522 * Constant-time conditional swap of a and b. 545 * Constant-time conditional swap of a and b.
@@ -575,18 +598,21 @@ BN_zero(BIGNUM *a)
575 a->neg = 0; 598 a->neg = 0;
576 a->top = 0; 599 a->top = 0;
577} 600}
601LCRYPTO_ALIAS(BN_zero);
578 602
579int 603int
580BN_one(BIGNUM *a) 604BN_one(BIGNUM *a)
581{ 605{
582 return BN_set_word(a, 1); 606 return BN_set_word(a, 1);
583} 607}
608LCRYPTO_ALIAS(BN_one);
584 609
585int 610int
586BN_abs_is_word(const BIGNUM *a, const BN_ULONG w) 611BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
587{ 612{
588 return (a->top == 1 && a->d[0] == w) || (w == 0 && a->top == 0); 613 return (a->top == 1 && a->d[0] == w) || (w == 0 && a->top == 0);
589} 614}
615LCRYPTO_ALIAS(BN_abs_is_word);
590 616
591int 617int
592BN_is_zero(const BIGNUM *bn) 618BN_is_zero(const BIGNUM *bn)
@@ -599,30 +625,35 @@ BN_is_zero(const BIGNUM *bn)
599 625
600 return bits == 0; 626 return bits == 0;
601} 627}
628LCRYPTO_ALIAS(BN_is_zero);
602 629
603int 630int
604BN_is_one(const BIGNUM *a) 631BN_is_one(const BIGNUM *a)
605{ 632{
606 return BN_abs_is_word(a, 1) && !a->neg; 633 return BN_abs_is_word(a, 1) && !a->neg;
607} 634}
635LCRYPTO_ALIAS(BN_is_one);
608 636
609int 637int
610BN_is_word(const BIGNUM *a, const BN_ULONG w) 638BN_is_word(const BIGNUM *a, const BN_ULONG w)
611{ 639{
612 return BN_abs_is_word(a, w) && (w == 0 || !a->neg); 640 return BN_abs_is_word(a, w) && (w == 0 || !a->neg);
613} 641}
642LCRYPTO_ALIAS(BN_is_word);
614 643
615int 644int
616BN_is_odd(const BIGNUM *a) 645BN_is_odd(const BIGNUM *a)
617{ 646{
618 return a->top > 0 && (a->d[0] & 1); 647 return a->top > 0 && (a->d[0] & 1);
619} 648}
649LCRYPTO_ALIAS(BN_is_odd);
620 650
621int 651int
622BN_is_negative(const BIGNUM *a) 652BN_is_negative(const BIGNUM *a)
623{ 653{
624 return a->neg != 0; 654 return a->neg != 0;
625} 655}
656LCRYPTO_ALIAS(BN_is_negative);
626 657
627char * 658char *
628BN_options(void) 659BN_options(void)
@@ -642,6 +673,7 @@ BN_options(void)
642 } 673 }
643 return (data); 674 return (data);
644} 675}
676LCRYPTO_ALIAS(BN_options);
645 677
646/* 678/*
647 * Bits of security, see SP800-57, section 5.6.11, table 2. 679 * Bits of security, see SP800-57, section 5.6.11, table 2.
@@ -673,6 +705,7 @@ BN_security_bits(int L, int N)
673 705
674 return bits >= secbits ? secbits : bits; 706 return bits >= secbits ? secbits : bits;
675} 707}
708LCRYPTO_ALIAS(BN_security_bits);
676 709
677BN_GENCB * 710BN_GENCB *
678BN_GENCB_new(void) 711BN_GENCB_new(void)
@@ -684,6 +717,7 @@ BN_GENCB_new(void)
684 717
685 return cb; 718 return cb;
686} 719}
720LCRYPTO_ALIAS(BN_GENCB_new);
687 721
688void 722void
689BN_GENCB_free(BN_GENCB *cb) 723BN_GENCB_free(BN_GENCB *cb)
@@ -692,6 +726,7 @@ BN_GENCB_free(BN_GENCB *cb)
692 return; 726 return;
693 free(cb); 727 free(cb);
694} 728}
729LCRYPTO_ALIAS(BN_GENCB_free);
695 730
696/* Populate a BN_GENCB structure with an "old"-style callback */ 731/* Populate a BN_GENCB structure with an "old"-style callback */
697void 732void
@@ -701,6 +736,7 @@ BN_GENCB_set_old(BN_GENCB *gencb, void (*cb)(int, int, void *), void *cb_arg)
701 gencb->cb.cb_1 = cb; 736 gencb->cb.cb_1 = cb;
702 gencb->arg = cb_arg; 737 gencb->arg = cb_arg;
703} 738}
739LCRYPTO_ALIAS(BN_GENCB_set_old);
704 740
705/* Populate a BN_GENCB structure with a "new"-style callback */ 741/* Populate a BN_GENCB structure with a "new"-style callback */
706void 742void
@@ -710,9 +746,11 @@ BN_GENCB_set(BN_GENCB *gencb, int (*cb)(int, int, BN_GENCB *), void *cb_arg)
710 gencb->cb.cb_2 = cb; 746 gencb->cb.cb_2 = cb;
711 gencb->arg = cb_arg; 747 gencb->arg = cb_arg;
712} 748}
749LCRYPTO_ALIAS(BN_GENCB_set);
713 750
714void * 751void *
715BN_GENCB_get_arg(BN_GENCB *cb) 752BN_GENCB_get_arg(BN_GENCB *cb)
716{ 753{
717 return cb->arg; 754 return cb->arg;
718} 755}
756LCRYPTO_ALIAS(BN_GENCB_get_arg);