CRYPTO_LOCK(3)
π 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, andCRYPTO_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 π
crypto(3)β go peek, bestie.
π HISTORY π
CRYPTO_lock(),CRYPTO_w_lock(),CRYPTO_w_unlock(),CRYPTO_r_lock(), andCRYPTO_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
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms