CryptX

 view release on metacpan or  search on metacpan

src/ltc/headers/tomcrypt_private.h  view on Meta::CPAN

/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */

#include "tomcrypt.h"
#include <stdarg.h>

#ifndef TOMCRYPT_PRIVATE_H_
#define TOMCRYPT_PRIVATE_H_

/*
 * Internal Macros
 */
/* Static assertion */
#define LTC_STATIC_ASSERT(msg, cond) typedef char ltc_static_assert_##msg[(cond) ? 1 : -1];

#define LTC_PAD_MASK       (0xF000U)

/* only real 64bit, not ILP32 */
#if defined(ENDIAN_64BITWORD) && !defined(ENDIAN_64BITWORD_ILP32)
   #define CONSTPTR(n) CONST64(n)
#else
   #define CONSTPTR(n) n ## uL
#endif

LTC_STATIC_ASSERT(correct_CONSTPTR_size, sizeof(CONSTPTR(1)) == sizeof(void*))

/* Poor-man's `uintptr_t` since we can't use stdint.h
 * c.f. https://github.com/DCIT/perl-CryptX/issues/95#issuecomment-1745280962 */
typedef size_t ltc_uintptr;

LTC_STATIC_ASSERT(correct_ltc_uintptr_size, sizeof(ltc_uintptr) == sizeof(void*))

/* Aligns a `unsigned char` buffer `buf` to `n` bytes and returns that aligned address.
 * Make sure that the buffer that is passed is huge enough.
 */
#define LTC_ALIGN_BUF(buf, align) ((void*)((ltc_uintptr)&((unsigned char*)(buf))[(align) - 1] & (~(CONSTPTR(align) - CONSTPTR(1)))))

#define LTC_OID_MAX_STRLEN 256

/* `NULL` as defined by the standard is not guaranteed to be of a pointer
 * type. In order to make sure that in vararg API's a pointer type is used,
 * define our own version and use that one internally.
 */
#ifndef LTC_NULL
   #define LTC_NULL ((void *)0)
#endif

#define LTC_ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))

#if defined(LTC_FAST)
#if !defined(LTC_NO_INLINE)
/* The LTC_FAST helpers operate on byte buffers that are not guaranteed to be aligned for LTC_FAST_TYPE.
   Use memcpy for loads/stores to avoid undefined behavior from unaligned or aliasing-unsafe typed-pointer dereferences.
   On GCC/Clang prefer __builtin_memcpy: it is guaranteed to be inlined for constant sizes regardless of any
   user override of XMEMCPY (e.g. embedded builds). Other compilers fall back to XMEMCPY.
*/
static LTC_INLINE LTC_FAST_TYPE LTC_FAST_LOAD(const void *p)
{
   LTC_FAST_TYPE v;
#if defined(__GNUC__)
   __builtin_memcpy(&v, p, sizeof(v));
#else
   XMEMCPY(&v, p, sizeof(v));
#endif
   return v;
}

static LTC_INLINE void LTC_FAST_STORE(void *p, LTC_FAST_TYPE v)
{
#if defined(__GNUC__)
   __builtin_memcpy(p, &v, sizeof(v));



( run in 2.692 seconds using v1.01-cache-2.11-cpan-54e63673c56 )