CRYPTO_LOCK(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… CRYPTO_LOCK(3): thread support πŸ’…

okay bestie, this page is from the Library Functions Manual β€” yes, the whole manual, iconic. It's all about the thread-support crew.

🌸 NAME 🌸

  • CRYPTO_lock, CRYPTO_w_lock, CRYPTO_w_unlock, CRYPTO_r_lock, CRYPTO_r_unlock, and CRYPTO_add β€” thread support. The whole squad.

πŸ¦‹ SYNOPSIS πŸ¦‹

library libcrypto

#include <openssl/crypto.h>

the function signatures, exactly as they are:

void
CRYPTO_lock(int mode, int type, const char *file, int line);

int
CRYPTO_add(int *p, int amount, int type);

and the macro glow-ups:

#define CRYPTO_w_lock(type) \
        CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, __FILE__, __LINE__)
#define CRYPTO_w_unlock(type) \
        CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, __FILE__, __LINE__)
#define CRYPTO_r_lock(type) \
        CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ, type, __FILE__, __LINE__)
#define CRYPTO_r_unlock(type) \
        CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ, type, __FILE__, __LINE__)

πŸ’– DESCRIPTION πŸ’–

First things first: these functions are obsolete. Like, obsolete obsolete β€” they're still in the manual, but don't make them your whole personality.

CRYPTO_lock() locks or unlocks a mutex lock. Periodt.

mode is a bitfield describing what should be done with the lock. Every call must include either CRYPTO_LOCK or CRYPTO_UNLOCK β€” no cap, that's required. In the LibreSSL implementation, CRYPTO_READ and CRYPTO_WRITE are ignored.

type is a number in the range 0 <= type < CRYPTO_NUM_LOCKS, and it identifies a particular lock. Currently, the value of CRYPTO_NUM_LOCKS is 41.

The file and line arguments are ignored. Yep, ignored.

In the LibreSSL implementation, CRYPTO_lock() is a wrapper around pthread_mutex_lock(3) and pthread_mutex_unlock(3).

CRYPTO_add() locks the lock number type, adds amount to *p, and unlocks the lock number type again.

πŸ‘‘ RETURN VALUES πŸ‘‘

CRYPTO_add() returns the new value of *p. That's the whole return-value story.

πŸŽ€ SEE ALSO πŸŽ€

🌈 HISTORY 🌈

  • CRYPTO_lock(), CRYPTO_w_lock(), CRYPTO_w_unlock(), CRYPTO_r_lock(), and CRYPTO_r_unlock() first appeared in SSLeay 0.6.0.
  • CRYPTO_add() first appeared in SSLeay 0.6.2.
  • These functions have been available since OpenBSD 2.4.

that's the whole page, bestie β€” from the Debian edition dated June 8, 2025. CRYPTO_LOCK(3), signing off πŸ’–

πŸ“¦ where this page comes from