assh/assh.h header reference
Description [link]
This header contains declarations of types used across the library as well as error related enums and macros.
Header inclusion [link]
Members [link]
Types [link]
- typedef assh_status_t (assh_allocator_t)(void *alloc_pv, void **ptr, size_t size, enum assh_alloc_type_e type)
- typedef [...] assh_bool_t
- enum assh_severity_e
- enum assh_status_e
- typedef [...] assh_status_t
Functions [link]
- const char * assh_error_str(assh_status_t err)
- const char ** assh_charptr_cast(char **p)
- uint_fast8_t assh_ct_clz16(uint16_t x)
- uint_fast8_t assh_ct_clz32(uint32_t x)
- uint_fast8_t assh_ct_clz64(uint64_t x)
- uint_fast8_t assh_ct_clz8(uint8_t x)
- uint_fast8_t assh_ct_ctz16(uint16_t x)
- uint_fast8_t assh_ct_ctz32(uint32_t x)
- uint_fast8_t assh_ct_ctz64(uint64_t x)
- uint_fast8_t assh_ct_ctz8(uint8_t x)
- uint_fast8_t assh_ct_popc16(uint16_t x)
- uint_fast8_t assh_ct_popc32(uint32_t x)
- uint_fast8_t assh_ct_popc64(uint64_t x)
- uint_fast8_t assh_ct_popc8(uint8_t x)
- void assh_hexdump(void *stream, const char *name, const void *data, size_t len)
- intptr_t assh_max_int(intptr_t a, intptr_t b)
- uintptr_t assh_max_uint(uintptr_t a, uintptr_t b)
- intptr_t assh_min_int(intptr_t a, intptr_t b)
- uintptr_t assh_min_uint(uintptr_t a, uintptr_t b)
- const uint8_t ** assh_uint8ptr_cast(uint8_t **p)
Macros [link]
- ASSH_SEVERITY
- ASSH_STATUS
- ASSH_SUCCESS
- ASSH_ALLOCATOR
- ASSH_ASSERT
- ASSH_CT_CTLZ_GEN
- ASSH_FIRST_FIELD_ASSERT
- ASSH_IDENT
- ASSH_JMP_IF_TRUE
- ASSH_JMP_ON_ERR
- ASSH_MAX_BLOCK_SIZE
- ASSH_MAX_EKEY_SIZE
- ASSH_MAX_HASH_SIZE
- ASSH_MAX_IKEY_SIZE
- ASSH_MAX_MAC_SIZE
- ASSH_MAX_SYMKEY_SIZE
- ASSH_MIN
- ASSH_MIN_BLOCK_SIZE
- ASSH_PCK_POOL_MAX
- ASSH_PCK_POOL_MIN
- ASSH_PCK_POOL_SIZE
- ASSH_REKEX_THRESHOLD
- ASSH_RETURN
- ASSH_RET_IF_TRUE
- ASSH_RET_ON_ERR
- ASSH_SET_STATE
- ASSH_STATIC_ASSERT
Members detail [link]
#define ASSH_SEVERITY(code) [link]
This macro is declared in assh/assh.h source file, line 253.
This macro extracts the enum assh_severity_e part of an status code returned by a function.
This macro expands to:
((enum assh_severity_e)((code) & 0xf000))
See also assh_status_t, enum assh_severity_e and Error handling.
#define ASSH_STATUS(code) [link]
This macro is declared in assh/assh.h source file, line 244.
This macro extracts the enum assh_status_e part of an status code returned by a function.
This macro expands to:
((enum assh_status_e)((code) & 0xfff))
See also assh_status_t, enum assh_status_e, ASSH_SUCCESS and Error handling.
#define ASSH_SUCCESS(code) [link]
This macro is declared in assh/assh.h source file, line 248.
This macro evaluate to true when the status code is not an error.
This macro expands to:
(ASSH_STATUS(code) < 0x100)
See also ASSH_STATUS and Error handling.
typedef assh_status_t (assh_allocator_t)(void *alloc_pv, void **ptr, size_t size, enum assh_alloc_type_e type) [link]
This typedef is declared in assh/assh.h source file, line 506.
This declaration involves expansion of the ASSH_ALLOCATOR macro.
This is the memory allocator function type. A pointer to function of this type may be passed to the assh_context_create function. The same behavior as the standard realloc function is expected.
See also coremod.
typedef uint8_t assh_bool_t [link]
This typedef is declared in assh/assh.h source file, line 138.
A simple boolean type used in libassh.
const char * assh_error_str(assh_status_t err) [link]
This function is declared in assh/assh.h source file, line 239.
This function returns an error string description of the passed error code.
enum assh_severity_e [link]
This enum is declared in assh/assh.h source file, line 162.
This enum specifies the error severity and must be ored with an enum assh_status_e value.
These values indicate how the state of the session is impacted by the associated error.
Multiple error severity bits may be ored together; in this case the highest bit set prevails. This allows increasing the error severity returned by a callee from the caller function.
See also Error handling.
Identifier | Value | Description |
---|---|---|
ASSH_ERRSV_CONTINUE | 0x0000 | The error is not critical and the connection may continue. This is the default when no severity is specified. |
ASSH_ERRSV_DISCONNECT | 0x2000 | The error prevent further communication with the remote host but a disconnect packet may still be send before closing the connection. |
enum assh_status_e [link]
This enum is declared in assh/assh.h source file, line 176.
This enum specifies the possible errors returned by the libassh functions and passed to the assh_event_done function.
See also Error handling.
Identifier | Value | Description |
---|---|---|
ASSH_OK | 0 | Success. |
ASSH_NO_DATA | 1 | No data were available, This is not an error. |
ASSH_NOT_FOUND | 2 | The requested entry was not found, This is not an error. |
ASSH_ERR_IO | 0x100 | IO error. |
ASSH_ERR_MEM | 0x101 | Memory allocation error. |
ASSH_ERR_INPUT_OVERFLOW | 0x102 | Buffer overflow in input data. Input data contains bad or corrupt data which would result in memory access outside allowed bounds. |
ASSH_ERR_OUTPUT_OVERFLOW | 0x103 | Output buffer is not large enough to write expected data. |
ASSH_ERR_NUM_OVERFLOW | 0x104 | Arithmetic overflow on big number. |
ASSH_ERR_NUM_COMPARE_FAILED | 0x105 | Compare failed on big number. |
ASSH_ERR_BAD_VERSION | 0x106 | Bad version of the ssh protocol. |
ASSH_ERR_BAD_DATA | 0x107 | Packet or buffer contains unexpected or corrupt data. |
ASSH_ERR_BAD_ARG | 0x108 | Invalid function arguments |
ASSH_ERR_MAC | 0x109 | Message authentication code error. |
ASSH_ERR_PROTOCOL | 0x10a | Packet content doesn't match current state of the protocol. |
ASSH_ERR_BUSY | 0x10b | Requested operation can not be performed at this time. |
ASSH_ERR_CRYPTO | 0x10c | Crypto initialization or processing error. |
ASSH_ERR_NOTSUP | 0x10d | Unsupported parameter value. |
ASSH_ERR_KEX_FAILED | 0x10f | The key exchange has failed |
ASSH_ERR_MISSING_KEY | 0x110 | The required key is not available. |
ASSH_ERR_MISSING_ALGO | 0x111 | The required algorithm is not available. |
ASSH_ERR_WRONG_KEY | 0x112 | The key failed to decipher |
ASSH_ERR_HOSTKEY_SIGNATURE | 0x113 | The host key verification has failed |
ASSH_ERR_SERVICE_NA | 0x114 | The requested service is not available |
ASSH_ERR_NO_AUTH | 0x115 | No more authentication method available. |
ASSH_ERR_NO_MORE_SERVICE | 0x116 | The client has reached the end of list of services to request. |
ASSH_ERR_WEAK_ALGORITHM | 0x117 | Algorithm or key security level is below defined threshold. |
ASSH_ERR_TIMEOUT | 0x118 | Protocol timeout. |
ASSH_ERR_count | 1 |
typedef int_fast16_t assh_status_t [link]
This typedef is declared in assh/assh.h source file, line 147.
The error code integer type returned by assh functions. It is composed of two parts specified by the enum assh_status_e and enum assh_severity_e enums.
See also ASSH_STATUS, ASSH_SEVERITY and Error handling.
#define ASSH_ALLOCATOR(n) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 498.
This macro specifies the prototype of a memory allocator function.
This macro expands to:
assh_status_t (n)(void *alloc_pv, void **ptr,
size_t size, enum assh_alloc_type_e type)
See also assh_allocator_t.
#define ASSH_ASSERT(expr) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 294.
This macro takes an assh_status_t value returned by a function and asserts that the error code is ASSH_OK.
This macro expands to:
do {
assh_status_t _e_ = (expr);
(void)_e_;
assert((_e_ & 0xfff) == ASSH_OK);
} while(0)
#define ASSH_CT_CTLZ_GEN(n, l) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 566.
This macro generates contant time ctz and clz functions
This macro expands to:
/** @internal @This computes the number of trailing zero bits of a
n bits value in constant time */
ASSH_PV ASSH_INLINE uint_fast8_t assh_ct_ctz##n(uint##n##_t x)
{
x &= -x;
uint##n##_t c = (x & (uint##n##_t)0x5555555555555555ULL) - 1;
c = (c >> 1) ^ ((x & (uint##n##_t)0x3333333333333333ULL) - 1);
c = (c >> 1) ^ ((x & (uint##n##_t)0x0f0f0f0f0f0f0f0fULL) - 1);
if (n > 8)
c = (c >> 1) ^ ((x & (uint##n##_t)0x00ff00ff00ff00ffULL) - 1);
if (n > 16)
c = (c >> 1) ^ ((x & (uint##n##_t)0x0000ffff0000ffffULL) - 1);
if (n > 32)
c = (c >> 1) ^ ((x & (uint##n##_t)0x00000000ffffffffULL) - 1);
return (c >> (n - l)) ^ (c >> (n - l + 1));
}
/** @internal @This computes the number of leading zero bits of a
n bits value in constant time */
ASSH_PV ASSH_INLINE uint_fast8_t assh_ct_clz##n(uint##n##_t x)
{
uint##n##_t a0, a1, a2, a3, a4, j = 0;
a0 = x | (( x & (uint##n##_t)0xaaaaaaaaaaaaaaaaULL) >> 1);
a1 = a0 | ((a0 & (uint##n##_t)0xccccccccccccccccULL) >> 2);
a2 = a1 | ((a1 & (uint##n##_t)0xf0f0f0f0f0f0f0f0ULL) >> 4);
a3 = a2 | ((a2 & (uint##n##_t)0xff00ff00ff00ff00ULL) >> 8);
a4 = a3 | ((a3 & (uint##n##_t)0xffff0000ffff0000ULL) >> 16);
if (n > 32)
j |= (a4 >> (j + 32-5)) & 32;
if (n > 16)
j |= (a3 >> (j + 16-4)) & 16;
if (n > 8)
j |= (a2 >> (j + 8-3)) & 8;
j |= (a1 >> (j + 4-2)) & 4;
j |= (a0 >> (j + 2-1)) & 2;
j |= (x >> (j + 1-0)) & 1;
return j ^ (n - 1);
}
/** @internal @This computes the number of one bits of a
n bits value in constant time */
ASSH_INLINE uint_fast8_t assh_ct_popc##n(uint##n##_t x)
{
x = (x & (uint##n##_t)0x5555555555555555ULL) +
((x >> 1) & (uint##n##_t)0x5555555555555555ULL);
x = (x & (uint##n##_t)0x3333333333333333ULL) +
((x >> 2) & (uint##n##_t)0x3333333333333333ULL);
x = (x & (uint##n##_t)0x0f0f0f0f0f0f0f0fULL) +
((x >> 4) & (uint##n##_t)0x0f0f0f0f0f0f0f0fULL);
if (n > 8)
x = (x & (uint##n##_t)0x00ff00ff00ff00ffULL) +
((x >> 8) & (uint##n##_t)0x00ff00ff00ff00ffULL);
if (n > 16)
x = (x & (uint##n##_t)0x0000ffff0000ffffULL) +
((x >> 16) & (uint##n##_t)0x0000ffff0000ffffULL);
if (n > 32)
x = (x & 0x00000000ffffffffULL) +
(((uint64_t)x >> 32) & 0x00000000ffffffffULL);
return x;
}
#define ASSH_FIRST_FIELD_ASSERT(struct_name, field) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 513.
This checks at compile time that a field is at offset 0 in a structure.
#define ASSH_IDENT [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 494.
The SSH implementation identification string. Because this is involved in the shared secret generation process, Changing this breaks the testsuite.
This macro expands to:
"SSH-2.0-LIBASSH\r\n"
#define ASSH_JMP_IF_TRUE(cond, err, label) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 483.
This macro reports on error to the ASSH_JMP_ON_ERR macro if the given expression is true.
This macro expands to:
ASSH_JMP_ON_ERR(cond ? err : 0, label)
#define ASSH_JMP_ON_ERR(expr, label) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 320.
Preprocessor condition: not defined( CONFIG_ASSH_DEBUG )
This macro takes an assh_status_t value returned by a function of the library and assigns it to the locally defined err variable.
It jumps to the provided label for any error codes >= 256. If the code is not an error, the execution continues to the next line..
It can be made verbose by defining the CONFIG_ASSH_DEBUG and CONFIG_ASSH_CALLTRACE macros.
This macro expands to:
do {
if ((err = (expr)) & 0x100)
goto label;
} while (0)
See also enum assh_status_e, assh_status_t, ASSH_RET_ON_ERR and ASSH_RETURN.
#define ASSH_MAX_BLOCK_SIZE 16 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 277.
Maximum cipher block size in bytes. must be >= 16.
#define ASSH_MAX_EKEY_SIZE 64 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 268.
Maximum size of cipher algorithms keys in bytes.
#define ASSH_MAX_HASH_SIZE 64 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 265.
Maximum size of hash algorithms output in bytes.
#define ASSH_MAX_IKEY_SIZE 64 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 271.
Maximum size of mac algorithms keys in bytes.
#define ASSH_MAX_MAC_SIZE 64 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 283.
Maximum mac output size in bytes.
#define ASSH_MAX_SYMKEY_SIZE 64 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 280.
Maximum size of cipher/mac keys or iv in bytes.
#define ASSH_MIN(a, b) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 563.
Use only for constant expressions.
This macro expands to:
((a) < (b) ? (a) : (b))
See also assh_min_int and assh_min_uint.
#define ASSH_MIN_BLOCK_SIZE 8 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 274.
Minimal cipher block size in bytes. Spec says 8
#define ASSH_PCK_POOL_MAX 16 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 260.
Log2 of largest packet size bucket in the packet allocator pool.
#define ASSH_PCK_POOL_MIN 6 [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 257.
Log2 of smallest packet size bucket in the packet allocator pool.
#define ASSH_PCK_POOL_SIZE [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 262.
Number of buckets in the packet allocator pool
This macro expands to:
#define ASSH_REKEX_THRESHOLD [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 286.
Default key re-echange threshold in bytes
This macro expands to:
(1 << 31)
#define ASSH_RETURN(expr) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 355.
Preprocessor condition: not defined( CONFIG_ASSH_DEBUG )
This macro takes an assh_status_t value returned by a function and forwards it to the calling function in any case.
The execution never continues to the next line.
It can be made verbose by defining the CONFIG_ASSH_DEBUG and CONFIG_ASSH_CALLTRACE macros. In the other case, it only performs a function return.
This macro expands to:
do {
(void)err;
return (expr);
} while (0)
See also assh_status_t, ASSH_JMP_ON_ERR and ASSH_RET_ON_ERR.
#define ASSH_RET_IF_TRUE(cond, err) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 488.
This macro reports on error to the ASSH_RET_ON_ERR macro if the given expression is true.
This macro expands to:
ASSH_RET_ON_ERR(cond ? err : 0)
#define ASSH_RET_ON_ERR(expr) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 338.
Preprocessor condition: not defined( CONFIG_ASSH_DEBUG )
This macro takes an assh_status_t value returned by a function and assigns it to the locally defined err variable.
It forwards the error to the calling function for any error codes >= 256. If the code is not an error, the execution continues to the next line.
It can be made verbose by defining the CONFIG_ASSH_DEBUG and CONFIG_ASSH_CALLTRACE macros.
This macro expands to:
do {
if ((err = (expr)) & 0x100)
return err;
} while (0)
See also enum assh_status_e, assh_status_t, ASSH_JMP_ON_ERR and ASSH_RETURN.
#define ASSH_SET_STATE(obj, field, value) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 467.
Preprocessor condition: defined( CONFIG_ASSH_FSMTRACE )
This macro is used to change the state variable of finite state machines. It can be made verbose by defining the CONFIG_ASSH_FSMTRACE macro.
This macro expands to:
do {
fprintf(stderr, "%s:%u:%s: " #field " update %u -> %u:" #value" \n",
__FILE__, __LINE__, __func__, (obj)->field, value);
(obj)->field = value;
} while (0)
#define ASSH_STATIC_ASSERT(expr, msgid) [link]
This macro is for internal use only.
This macro is declared in assh/assh.h source file, line 508.
This checks expression at compile time.
const char ** assh_charptr_cast(char **p) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 521.
uint_fast8_t assh_ct_clz16(uint16_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 22 in assh/assh.h source file, line 630.
This function computes the number of leading zero bits of a 16 bits value in constant time
uint_fast8_t assh_ct_clz32(uint32_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 22 in assh/assh.h source file, line 631.
This function computes the number of leading zero bits of a 32 bits value in constant time
uint_fast8_t assh_ct_clz64(uint64_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 22 in assh/assh.h source file, line 632.
This function computes the number of leading zero bits of a 64 bits value in constant time
uint_fast8_t assh_ct_clz8(uint8_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 22 in assh/assh.h source file, line 629.
This function computes the number of leading zero bits of a 8 bits value in constant time
uint_fast8_t assh_ct_ctz16(uint16_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 5 in assh/assh.h source file, line 630.
This function computes the number of trailing zero bits of a 16 bits value in constant time
uint_fast8_t assh_ct_ctz32(uint32_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 5 in assh/assh.h source file, line 631.
This function computes the number of trailing zero bits of a 32 bits value in constant time
uint_fast8_t assh_ct_ctz64(uint64_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 5 in assh/assh.h source file, line 632.
This function computes the number of trailing zero bits of a 64 bits value in constant time
uint_fast8_t assh_ct_ctz8(uint8_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 5 in assh/assh.h source file, line 629.
This function computes the number of trailing zero bits of a 8 bits value in constant time
uint_fast8_t assh_ct_popc16(uint16_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 44 in assh/assh.h source file, line 630.
This function computes the number of one bits of a 16 bits value in constant time
uint_fast8_t assh_ct_popc32(uint32_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 44 in assh/assh.h source file, line 631.
This function computes the number of one bits of a 32 bits value in constant time
uint_fast8_t assh_ct_popc64(uint64_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 44 in assh/assh.h source file, line 632.
This function computes the number of one bits of a 64 bits value in constant time
uint_fast8_t assh_ct_popc8(uint8_t x) [link]
This function is for internal use only.
This function is declared in ASSH_CT_CTLZ_GEN function like macro expansion, line 44 in assh/assh.h source file, line 629.
This function computes the number of one bits of a 8 bits value in constant time
void assh_hexdump(void *stream, const char *name, const void *data, size_t len) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 291.
intptr_t assh_max_int(intptr_t a, intptr_t b) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 539.
uintptr_t assh_max_uint(uintptr_t a, uintptr_t b) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 533.
intptr_t assh_min_int(intptr_t a, intptr_t b) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 551.
uintptr_t assh_min_uint(uintptr_t a, uintptr_t b) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 545.
const uint8_t ** assh_uint8ptr_cast(uint8_t **p) [link]
This function is for internal use only.
This function is declared in assh/assh.h source file, line 527.