BN_CMP(3SSL)

πŸ’– BN_CMP πŸ’–

okay bestie, gather round, because today we're talking about BIGNUM comparison and test functions β€” that's the whole vibe of this page from the OpenSSL manual, section 3SSL. it's giving "how do I even know if these giant numbers are equal" and honestly? relatable. ✨


🌸 SYNOPSIS 🌸

#include <openssl/bn.h>

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);

like, look at that. a whole lil friend group of functions. 🫢


✨ DESCRIPTION ✨

so BN_cmp() compares the numbers a and b. and BN_ucmp()? it compares their absolute values instead. the "u" is lowkey doing the "unsigned / no sign energy" thing, no cap.

then we got the little test gremlins πŸ‘‘

  • BN_is_zero(), BN_is_one(), BN_is_word() and BN_abs_is_word() β€” these test if a equals 0, 1, w, or |w| respectively. four little yes/no machines. periodt.
  • BN_is_odd() β€” tests if a is odd. that's it. that's the whole job. πŸ’…

and then the main character: BN_are_coprime() determines if a and b are coprime. ctx is used internally for storing temporary variables, so it's like the little backpack it carries its stuff in. πŸŽ€

⚠️ okay important, not me being dramatic: the values of a and b and ctx must not be NULL. like, at all. don't do that to them. πŸ™ˆ

πŸ’€ RETURN VALUES πŸ’€

here's the tea on what you actually get back:

BN_cmp() returns:

  • -1 if a < b
  • 0 if a == b
  • 1 if a > b

and BN_ucmp() is the exact same deal, except it's doing it with the absolute values of a and b. same energy, different numbers. ✨

BN_is_zero(), BN_is_one(), BN_is_word(), BN_abs_is_word() and BN_is_odd() return 1 if the condition is true, and 0 otherwise. yes/no. that's the whole thing bestie, no in-between. πŸ¦‹

BN_are_coprime() returns 1 if the BIGNUM's are coprime, otherwise it returns 0. iconic behaviour tbh.


🧚 HISTORY 🧚

so back in the day, before OpenSSL 1.1.0, these ones β€” BN_is_zero(), BN_is_one(), BN_is_word(), BN_abs_is_word() and BN_is_odd() β€” were macros. not functions. they've since been glow-upped into real functions. character development fr fr. 🌈

and BN_are_coprime() is the baby of the family β€” it was added in OpenSSL 3.1. new addition, still slaying. πŸ“


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>.


and that's the whole page, bestie!! πŸŽ€ this was 4.0.3 of the OpenSSL docs, dated 2026-09-29 β€” BN_CMP(3SSL), out. go compare some big numbers, you absolute legend. mwah. πŸ’–βœ¨πŸ’…

πŸ“¦ where this page comes from