samp.directory
← Скрипты и библиотеки

roseeast/async-crypto

Async Argon2id password hashing and crypto utilities for SA-MP/open.mp Pawn servers.

Плагин★ 2обновлён сент. 2026 г.MITC++
Открыть на GitHub

README.md


Async Crypto provides non-blocking Argon2id password hashing for Pawn gamemodes, plus practical crypto utilities such as secure random hex, SHA-256, HMAC-SHA256, and Base64. Expensive work runs on worker threads, then results are delivered back to Pawn from the main server thread through ProcessTick.

Overview

ItemDetail
Plugin nameasync_crypto
TargetSA-MP and open.mp
Plugin typeLegacy SA-MP plugin API
LanguageC++20
Password algorithmArgon2id
Async modelWorker thread queue + ProcessTick callback
External runtime depsNone beyond OS C runtime for release binaries
Included platformsLinux x86, Linux x86_64, Windows x86, Windows x86_64
Pawn includeinclude/async_crypto.inc

Features

FeatureNativeAsyncOutput
Argon2id password hashingCrypto_Argon2HashYesPHC encoded Argon2id hash
Argon2id password verificationCrypto_Argon2VerifyYes"1" or "0"
Secure random bytes as hexCrypto_RandomHexNoLowercase hex string
SHA-256Crypto_SHA256HexNo64-char lowercase hex
HMAC-SHA256Crypto_HMACSHA256HexNo64-char lowercase hex
Base64 encodeCrypto_Base64EncodeNoBase64 string
Base64 decodeCrypto_Base64DecodeNoDecoded string

Release Files

Prebuilt binaries are available in dist/.

FilePlatformArchitectureInstall as
dist/async_crypto-linux-x86_64.tar.gzLinuxx86_64 / 64-bitExtract, then copy plugins/async_crypto.so
dist/async_crypto-linux-i686.tar.gzLinuxi686 / 32-bitExtract, then copy plugins/async_crypto.so
dist/async_crypto-windows-x86_64.zipWindowsx86_64 / 64-bitExtract, then copy plugins/async_crypto.dll
dist/async_crypto-windows-i686.zipWindowsi686 / 32-bitExtract, then copy plugins/async_crypto.dll
dist/SHA256SUMS.txtAllChecksumsIntegrity verification

Package layout:

plugins/
  async_crypto.so      # Linux packages
  async_crypto.dll     # Windows packages
pawno/include/
  async_crypto.inc
example.pwn
README.md
LICENSE

Compatibility

RuntimeStatusNotes
SA-MP Windows serverSupportedUse the matching .dll architecture.
SA-MP Linux serverSupportedUse the matching .so architecture.
open.mp Windows serverSupported as legacy pluginConfigure through pawn.legacy_plugins or legacy server.cfg.
open.mp Linux serverSupported as legacy pluginConfigure through pawn.legacy_plugins or legacy server.cfg.
Native open.mp componentNot includedThis project currently targets the legacy plugin ABI for broad compatibility.

This plugin does not hook RakNet, patch memory, or depend on SA-MP internal addresses, so it is a good fit for open.mp legacy plugin loading.

Installation

1. Choose The Binary

ServerUse this binaryDestination
Linux 64-bitasync_crypto-linux-x86_64.tar.gzplugins/async_crypto.so
Linux 32-bitasync_crypto-linux-i686.tar.gzplugins/async_crypto.so
Windows 64-bitasync_crypto-windows-x86_64.zipplugins/async_crypto.dll
Windows 32-bitasync_crypto-windows-i686.zipplugins/async_crypto.dll

2. Install The Pawn Include

Copy:

include/async_crypto.inc

to your compiler include directory, for example:

ToolingTypical include directory
Pawnopawno/include/
Qawnoqawno/include/
sampctlProject include path or package include path

3. Load The Plugin

For SA-MP or legacy server.cfg:

plugins async_crypto

On some older Linux setups, include the extension:

plugins async_crypto.so

For open.mp config.json:

{
  "pawn": {
    "legacy_plugins": ["async_crypto"]
  }
}

Native API

Async Natives

NativeSignatureReturnCallback result
Crypto_Argon2Hashconst password[], const callback[], mem_kib, iterations, parallelism, hash_lenrequestid > 0 or negative errorPHC encoded hash
Crypto_Argon2Verifyconst password[], const encoded_hash[], const callback[]requestid > 0 or negative error"1" if valid, "0" if invalid

Callback format:

public MyCallback(requestid, status, const result[])

Return behavior:

Return valueMeaning
> 0Job accepted. Value is the requestid.
< 0Job rejected before reaching the worker queue. Absolute value maps to CRYPTO_STATUS_*.

Sync Utility Natives

NativeSignatureReturnNotes
Crypto_RandomHexbyte_len, dest[], dest_size1 on success, 0 on failurebyte_len must be 1..4096.
Crypto_SHA256Hexconst input[], dest[], dest_size1 or 0Hashes input string.
Crypto_HMACSHA256Hexconst key[], const input[], dest[], dest_size1 or 0Useful for signed tokens/webhooks.
Crypto_Base64Encodeconst input[], dest[], dest_size1 or 0Standard Base64.
Crypto_Base64Decodeconst input[], dest[], dest_size1 or 0Input length must be valid Base64.

Status Codes

ConstantValueMeaning
CRYPTO_STATUS_OK0Operation succeeded.
CRYPTO_STATUS_ERROR1Runtime error, such as invalid hash format or random source failure.
CRYPTO_STATUS_BAD_ARGUMENT2Invalid native argument.
CRYPTO_STATUS_QUEUE_FULL3Async worker queue is full.
CRYPTO_STATUS_CALLBACK_MISSING4Reserved for callback-related handling.

Argon2id Defaults

ParameterDefaultAllowed rangeDescription
mem_kib655368192..1048576Memory cost in KiB. Default is 64 MiB.
iterations31..16Time cost.
parallelism11..8Argon2 lane count.
hash_len3216..128Raw hash length before PHC encoding.
Salt length16FixedGenerated with OS secure random source.

For most RP/account systems, the default Argon2id settings are a strong starting point. Increase mem_kib or iterations only after testing login/register latency on your server hardware.

Pawn Example

#include <async_crypto>

public OnGameModeInit()
{
    new request = Crypto_Argon2Hash("secret-password", "OnPasswordHashed");

    if (request < 0)
    {
        printf("Argon2 job rejected: %d", request);
    }

    return 1;
}

public OnPasswordHashed(requestid, status, const hash[])
{
    if (status != CRYPTO_STATUS_OK)
    {
        printf("Hash failed: request=%d status=%d message=%s", requestid, status, hash);
        return 1;
    }

    printf("Hash: %s", hash);
    Crypto_Argon2Verify("secret-password", hash, "OnPasswordVerified");
    return 1;
}

public OnPasswordVerified(requestid, status, const result[])
{
    if (status == CRYPTO_STATUS_OK && strval(result) == 1)
    {
        print("Password valid.");
    }
    else
    {
        printf("Password invalid or verification failed: request=%d status=%d result=%s", requestid, status, result);
    }

    return 1;
}

Build From Source

Linux

sudo apt install cmake g++ git
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

Output:

build/async_crypto.so

Linux 32-bit

sudo apt install cmake g++ git g++-multilib
cmake -S . -B build-linux-i686 \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_C_FLAGS=-m32 \
  -DCMAKE_CXX_FLAGS=-m32 \
  -DCMAKE_SHARED_LINKER_FLAGS=-m32
cmake --build build-linux-i686 -j

Windows Cross-Build With MinGW

Windows x86_64:

cmake -S . -B build-win-x86_64 \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
  -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++
cmake --build build-win-x86_64 -j

Windows i686:

cmake -S . -B build-win-i686 \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc \
  -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++
cmake --build build-win-i686 -j

Offline SDK Build

By default, CMake fetches maddinat0r/samp-plugin-sdk and P-H-C/phc-winner-argon2. If your build machine cannot access GitHub, provide a local SDK checkout:

cmake -S . -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DSAMP_PLUGIN_SDK_DIR=/path/to/samp-plugin-sdk
cmake --build build -j

Build Notes

ComponentHow it is linked
Argon2Built from upstream source through CMake and linked statically.
SHA-256 / HMAC / Base64Built-in implementation in src/crypto_utils.cpp.
Secure randomgetrandom or /dev/urandom on Linux, BCryptGenRandom on Windows.
C++ runtime on LinuxStatic libstdc++/libgcc for release builds.
C++ runtime on WindowsStatic libstdc++/libgcc for MinGW builds.

Security Guidance

DoAvoid
Hash passwords with Crypto_Argon2Hash.Encrypting passwords with AES or reversible encryption.
Store the full PHC encoded hash string.Storing raw hash bytes without parameters and salt.
Verify passwords with Crypto_Argon2Verify.Comparing password strings manually in Pawn.
Use random salts generated by the plugin.Reusing one salt for every player.
Keep login/register flow async.Running expensive password hashing on the main server thread.

Password storage should keep the complete Argon2id PHC string, for example:

$argon2id$v=19$m=65536,t=3,p=1$...$...

The encoded string already contains the algorithm, version, memory cost, time cost, parallelism, salt, and hash.

Project Structure

PathPurpose
src/plugin.cppSA-MP/open.mp plugin entry points, AMX native registration, worker queue, callbacks.
src/crypto_utils.cppSecure random, SHA-256, HMAC-SHA256, Base64 helpers.
include/async_crypto.incPawn include and native declarations.
example.pwnMinimal Pawn usage example.
exports/async_crypto.defWindows export list.
dist/Prebuilt binaries and packaged release files.

Checksums

Use dist/SHA256SUMS.txt to verify release files:

cd dist
sha256sum -c SHA256SUMS.txt

Publishing a GitHub Release

Use GitHub Releases for public downloads. Releases are designed for versioned software packages, release notes, and binary assets.

Recommended Assets

Attach these files to each release:

AssetPurpose
dist/async_crypto-linux-x86_64.tar.gzReady-to-extract Linux 64-bit package.
dist/async_crypto-linux-i686.tar.gzReady-to-extract Linux 32-bit package.
dist/async_crypto-windows-x86_64.zipReady-to-extract Windows 64-bit package.
dist/async_crypto-windows-i686.zipReady-to-extract Windows 32-bit package.
dist/SHA256SUMS.txtIntegrity checksums.

License

Async Crypto is released under the MIT License. See LICENSE for details.

cryptoopenmppassword-hashingpawnsa-mpsa-mp-librarysa-mp-pluginsha256

Страница собрана из того, что GitHub публикует о репозитории. samp.directory не хранит этот код. Сообщить о проблеме с этой записью