#ifndef _CORECRYPTO_CC_H_
#define _CORECRYPTO_CC_H_
#include <corecrypto/cc_config.h>
#include <string.h>
#include <stdint.h>
#if CC_KERNEL
#include <kern/assert.h>
#else
#include <assert.h>
#include <stdio.h>
#endif
#define cc_aligned_struct(_alignment_) \
typedef struct { \
uint8_t b[_alignment_]; \
} __attribute__((aligned(_alignment_)))
#define cc_ctx_n(_type_, _size_) ((_size_ + sizeof(_type_) - 1) / sizeof(_type_))
#define cc_ctx_sizeof(_type_, _size_) sizeof(_type_[cc_ctx_n(_type_, _size_)])
#define cc_ctx_decl(_type_, _size_, _name_) \
_type_ _name_[cc_ctx_n(_type_, _size_)]
#if CC_HAS_BZERO
#define cc_zero(_size_,_data_) bzero((_data_), (_size_))
#else
#define cc_zero(_size_,_data_) memset((_data_),0 ,(_size_))
#endif
#if CC_KERNEL
#define cc_printf(x...) printf(x)
#else
#define cc_printf(x...) fprintf(stderr, x)
#endif
#define cc_assert(x) assert(x)
#define cc_copy(_size_, _dst_, _src_) memcpy(_dst_, _src_, _size_)
CC_INLINE CC_NONNULL2 CC_NONNULL3 CC_NONNULL4
void cc_xor(size_t size, void *r, const void *s, const void *t) {
uint8_t *_r=(uint8_t *)r;
const uint8_t *_s=(uint8_t *)s;
const uint8_t *_t=(uint8_t *)t;
while (size--) {
_r[size] = _s[size] ^ _t[size];
}
}
#define CC_SWAP(S,T) do { \
__typeof__(S) _cc_swap_tmp = S; S = T; T = _cc_swap_tmp; \
} while(0)
#define CC_MAX(S, T) ({__typeof__(S) _cc_max_s = S; __typeof__(T) _cc_max_t = T; _cc_max_s > _cc_max_t ? _cc_max_s : _cc_max_t;})
#define CC_MIN(S, T) ({__typeof__(S) _cc_min_s = S; __typeof__(T) _cc_min_t = T; _cc_min_s <= _cc_min_t ? _cc_min_s : _cc_min_t;})
#endif