BN_CMP(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

Hii bestie!! Welcome to BN_CMP(3ossl) β€” the OpenSSL page for all the BIGNUM comparison and test functions. Buckle up, because these little math gremlins are lowkey iconic and you’re gonna understand every single one. πŸ’…βœ¨

πŸŽ€ NAME πŸŽ€

Here’s the whole squad, no cap:

  • BN_cmp
  • BN_ucmp
  • BN_is_zero
  • BN_is_one
  • BN_is_word
  • BN_abs_is_word
  • BN_is_odd
  • BN_are_coprime

They’re all about BIGNUM comparison and test functions. Periodt. πŸ’–

✨ SYNOPSIS ✨

First things first, bestie β€” pull in the header:

#include <openssl/bn.h>

Then here are the exact signatures, character for character:

int BN_cmp(const BIGNUM *a, const BIGNUM *b);
int BN_ucmp(const BIGNUM *a, const BIGNUM *b);

int BN_is_zero(const BIGNUM *a);
int BN_is_one(const BIGNUM *a);
int BN_is_word(const BIGNUM *a, const BN_ULONG w);
int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w);
int BN_is_odd(const BIGNUM *a);

int BN_are_coprime(BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);

πŸ’– DESCRIPTION πŸ’–

Okay so, let’s break the crew down.

  • BN_cmp() β€” compares the numbers a and b. Like a full vibe check on which one is bigger. 😌
  • BN_ucmp() β€” compares their absolute values instead.
  • BN_is_zero() β€” tests if a equals 0.
  • BN_is_one() β€” tests if a equals 1.
  • BN_is_word() β€” tests if a equals w.
  • BN_abs_is_word() β€” tests if a equals |w|.
  • BN_is_odd() β€” tests if a is odd.

And then there’s BN_are_coprime(), the main character: it determines if a and b are coprime. The ctx is used internally for storing temporary variables. The values of a and b and ctx must not be NULL.

Bestie, seriously: a, b, and ctx must not be NULL. That’s a hard no. 🫢

🌸 RETURN VALUES 🌸

  • BN_cmp() β€” returns -1 if a < b, 0 if a == b, and 1 if a > b. πŸ’…
  • BN_ucmp() β€” same energy, but using the absolute values of a and b.
  • BN_is_zero(), BN_is_one(), BN_is_word(), BN_abs_is_word() and BN_is_odd() β€” return 1 if the condition is true, 0 otherwise.
  • BN_are_coprime() β€” returns 1 if the BIGNUMs are coprime, otherwise it returns 0.

πŸ¦‹ HISTORY πŸ¦‹

Storytime, bestie:

  • Prior to OpenSSL 1.1.0, BN_is_zero(), BN_is_one(), BN_is_word(), BN_abs_is_word() and BN_is_odd() were macros. The way they were macros before? Wild. 😭
  • The function BN_are_coprime() was added in OpenSSL 3.1.

Legal era, unfortunately, but we keep it cute:

Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the β€œLicense”). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


Okay that’s the whole page, bestie. This one comes from OpenSSL 3.5.0, dated 2026-09-25, and its manual name is BN_CMP(3ossl). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from