---
name: "libressl-CRYPTO_lock"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-CRYPTO_lock"
---

# libressl-CRYPTO\_lock(3)

thread support

## NAME

**CRYPTO\_lock**, **CRYPTO\_w\_lock**, **CRYPTO\_w\_unlock**, **CRYPTO\_r\_lock**, **CRYPTO\_r\_unlock**, **CRYPTO\_add** – thread support

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/crypto.h\>**

*void*\

**CRYPTO\_lock**(*int mode*, *int type*, *const char \*file*, *int line*);

*int*\

**CRYPTO\_add**(*int \*p*, *int amount*, *int type*);

```
#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

These functions are obsolete.

**CRYPTO\_lock**() locks or unlocks a mutex lock.

*mode* is a bitfield describing what should be done with the lock. For each call, either CRYPTO\_LOCK or CRYPTO\_UNLOCK must be included. In the LibreSSL implementation, CRYPTO\_READ and CRYPTO\_WRITE are ignored.

*type* is a number in the range 0 \<= *type* \< CRYPTO\_NUM\_LOCKS identifying a particular lock. Currently, the value of CRYPTO\_NUM\_LOCKS is 41.

The *file* and *line* arguments are ignored.

In the LibreSSL implementation, **CRYPTO\_lock**() is a wrapper around [pthread\_mutex\_lock(3)](/pthread_mutex_lock/3.md) and [pthread\_mutex\_unlock(3)](/pthread_mutex_unlock/3.md).

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

## SEE ALSO

[crypto(3)](/crypto/3.md)

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