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()andBN_abs_is_word()β these test ifaequals0,1,w, or|w|respectively. four little yes/no machines. periodt.BN_is_odd()β tests ifais 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 ofaandbandctxmust not beNULL. like, at all. don't do that to them. π
π RETURN VALUES π
here's the tea on what you actually get back:
BN_cmp() returns:
-1ifa < b0ifa == b1ifa > 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 π
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
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms