75 lines
3.3 KiB
Plaintext
75 lines
3.3 KiB
Plaintext
from openssl.types import *
|
|
|
|
# ============================================================
|
|
# openssl/crypto.vp — OpenSSL global initialization / version / memory utilities
|
|
# Corresponding headers: crypto.h / opensslv.h
|
|
# ============================================================
|
|
|
|
# ---- Version query types (type arg of OpenSSL_version(type)) ----
|
|
define OpenSslVersion = 0 # OPENSSL_VERSION full version text
|
|
define OpenSslBuiltOn = 2 # OPENSSL_BUILT_ON build time
|
|
define OpenSslPlatform = 3 # OPENSSL_PLATFORM platform
|
|
define OpenSslDir = 4 # OPENSSL_DIR
|
|
define OpenSslEnginesDir = 5 # OPENSSL_ENGINES_DIR
|
|
define OpenSslVersionString = 6 # OPENSSL_VERSION_STRING "3.x.y"
|
|
define OpenSslModulesDir = 8 # OPENSSL_MODULES_DIR
|
|
define OpenSslCpuInfo = 9 # OPENSSL_CPU_INFO
|
|
|
|
# ---- OPENSSL_init_crypto / OPENSSL_init_ssl option bits ----
|
|
define OpenSslInitNoLoadCryptoStrings = 0x00000001
|
|
define OpenSslInitNoLoadConfig = 0x00000004
|
|
define OpenSslInitNoAddAllCiphers = 0x00000008
|
|
define OpenSslInitNoAddAllDigests = 0x00000010
|
|
define OpenSslInitLoadConfig = 0x00000040
|
|
define OpenSslInitAsync = 0x00000080
|
|
define OpenSslInitDebugFile = 0x00010000
|
|
define OpenSslInitAtFork = 0x00020000
|
|
define OpenSslInitNoLoadSslStrings = 0x00100000
|
|
define OpenSslInitNoAtomics = 0x00200000
|
|
|
|
# ---- Version numbers (3.6.2, depends on the linked library) ----
|
|
define OpenSslVersionMajor = 3
|
|
define OpenSslVersionMinor = 6
|
|
define OpenSslVersionPatch = 2
|
|
|
|
# ---- Global init / cleanup ----
|
|
# int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
|
extern def OPENSSL_init_crypto(opts: uint64, settings: bytes) -> int
|
|
# int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
|
extern def OPENSSL_init_ssl(opts: uint64, settings: bytes) -> int
|
|
extern def OPENSSL_cleanup()
|
|
|
|
# ---- Version query ----
|
|
# const char *OpenSSL_version(int type)
|
|
extern def OpenSSL_version(type: int) -> str
|
|
# unsigned long OpenSSL_version_num(void)
|
|
extern def OpenSSL_version_num() -> uint32
|
|
extern def OPENSSL_version_pre_release() -> str
|
|
extern def OPENSSL_version_build_metadata() -> str
|
|
|
|
# ---- Memory / secure erase ----
|
|
# void OPENSSL_cleanse(void *ptr, size_t len)
|
|
extern def OPENSSL_cleanse(ptr: bytes, len: sizet)
|
|
# void CRYPTO_free(void *ptr, const char *file, int line)
|
|
extern def CRYPTO_free(ptr: bytes, file: str, line: int)
|
|
# void *CRYPTO_malloc(size_t num, const char *file, int line)
|
|
extern def CRYPTO_malloc(num: sizet, file: str, line: int) -> bytes
|
|
# int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len)
|
|
extern def CRYPTO_memcmp(in_a: bytes, in_b: bytes, len: sizet) -> int
|
|
# char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen) -> free with ossl_free
|
|
extern def OPENSSL_buf2hexstr(buf: bytes, buflen: int32) -> str
|
|
# int OPENSSL_hexchar2int(unsigned char c)
|
|
extern def OPENSSL_hexchar2int(c: uint8) -> int
|
|
# int OPENSSL_strcasecmp(const char *s1, const char *s2)
|
|
extern def OPENSSL_strcasecmp(s1: str, s2: str) -> int
|
|
# int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n)
|
|
extern def OPENSSL_strncasecmp(s1: str, s2: str, n: sizet) -> int
|
|
|
|
# ---- Convenience wrappers (CRYPTO_free/CRYPTO_malloc macros take file/line; wrapped as single-arg) ----
|
|
def ossl_free(ptr: bytes):
|
|
CRYPTO_free(ptr, "", 0)
|
|
|
|
|
|
def ossl_malloc(num: sizet) -> bytes:
|
|
return CRYPTO_malloc(num, "", 0)
|